Oct-05-2018, 03:55 PM
Hi all,
I have a problem to parse a specific text from a xml file.
What I need is the Value (BB001234) of the IDTAG but I didn't know how to grab them.
Here is my full .xml file and my python code.
The problem is that the quantity of the "<DataPoint> ### </DataPoint>" can change.
Hopefully someone can help me.
Thank you
TeraX
I have a problem to parse a specific text from a xml file.
What I need is the Value (BB001234) of the IDTAG but I didn't know how to grab them.
Here is my full .xml file and my python code.
The problem is that the quantity of the "<DataPoint> ### </DataPoint>" can change.
Hopefully someone can help me.
Thank you
TeraX
import os
from xml.etree import ElementTree
file_name = 'cumulus.xml'
full_file = os.path.abspath(os.path.join('data', file_name))
dom = ElementTree.parse(full_file)
assy = dom.findall('WorkOrders/CumulusWorkOrder/Assembly')
for c in assy:
item = c.find('PartNumber').text
serial = c.find('SerialLotNumber').text
desc = c.find('Description').text.encode('utf-8')
# idtag = c.find('IDTAG').text
#print(' * {} - {} - {} - {}'.format(
# item, serial, desc, idtag
#))
print(' * {} - {} - {} - '.format(
item, serial, desc
))results:Output:$ python 1.py
* 1234567 - 1234567.abcdef - Item Description -cumulus.xml