Reputation: 77
Does anyone have an idea on how to deal with PLMXML and python? I have been searching but didnt find too much. If anyone could give me a direction I would appreciate.
I have a huge PLMXML, but I edited to show the information that I want to get from it. I want to get the values: "RED: [1, 0, 0]", "GREEN: [0, 1, 0]" and "BLUE:[0, 0 , 1]". Its something like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema" schemaVersion="6.1" author="XXXXXXXXXXX" time="00:00:00.000+00:00" date="0000-00-00+00:00" name="000000000000">
<ProductDef id="000">
<InstanceGraph Ref="000 0000 000000 000000 00000 000000" name="instancegraphname" id="instancegraphid">
</ProductInstance>
<ProductRevisionView type="productrevisionviewtype" name="productrevisionname" id="productrevisionid" />
<ProductInstance Ref="priductinstanceref" id="productinstanceid" name="productinstancename">
<UserData type="userdatatype" id="userdataid">
<UserValue title="userdataValueTitle" value="userdatavalue" id="userdataid" />
<UserValue title="1" value="RED: [1, 0, 0]" id="id_red" />
<UserValue title="2" value="GREEN: [0, 1, 0]" id="id_green" />
<UserValue title="3" value="BLUE:[0, 0 , 1]" id="id_blue" />
</UserData>
</ProductInstance>
</ProductRevisionView>
</InstanceGraph>
</ProductDef>
</PLMXML>
Thanks in advance.
Upvotes: 1
Views: 727
Reputation: 55629
You can use the ElementTree package to parse the file (Assuming it's valid XML, which is not true of the example in the question).
>>> import xml.etree.ElementTree as ET
>>> ET.parse('pl.xml')
<xml.etree.ElementTree.ElementTree object at 0x7f9bfab8b700>
>>> tree = ET.parse('pl.xml')
>>> root = tree.getroot()
>>> for elem in root.iter('{http://www.plmxml.org/Schemas/PLMXMLSchema}UserValue'):print(elem.attrib['value'])
...
userdatavalue
RED: [1, 0, 0]
GREEN: [0, 1, 0]
BLUE:[0, 0 , 1]
For serious XML work, consider installing and using the lxml package.
Upvotes: 1