xml.etree

How to extract specfic values from xml file using python xml.etree.ElementTree iterating until an id is found inside a hidden child node?

How to extract specfic values from xml file using python xml.etree.ElementTree iterating until an id is found inside a hidden child node? Question: I need to iterate over the tag ObjectHeader and when the tag ObjectType/Id is equal to 1424 I need to extract all the values inside the following tags ObjectVariant/ObjectValue/Characteristic/Name and ObjectVariant/ObjectValue/PropertyValue/Value and …

Total answers: 2

XML ElementTree Python: Find all the relations of a node

XML ElementTree Python: Find all the relations of a node Question: If we supose the following XML file: <XML Data> <Record> <Service> <Product id="A"></Product> <Product id="B"></Product> <Product id="C"></Product> </Service> </Record> <Record> <Service> <Product id="A"></Product> <Product id="B"></Product> <Product id="Y"></Product> </Service> </Record> <Record> <Service> <Product id="U"></Product> </Service> </Record> </XML Data> As you can see, each record shows …

Total answers: 1

Python iterparse large XML while filtering with elements and children

Python iterparse large XML while filtering with elements and children Question: I am attempting to parse product data from icecat. The data comes in large xml files. (3-7gb). In order to reduce the amount of product data I am bringing in, I need to filter this list before moving to my next step. Particularly I …

Total answers: 2

Python XML Element AttributeError: 'NoneType' object has no attribute 'text'

Python XML Element AttributeError: 'NoneType' object has no attribute 'text' Question: I am trying to parse the following xml file. <xml version="1"> <nodes> 1 -2.50000000E+01 0.00000000E+00 5.00000000E+00 </nodes> </xml> I want to retrieve the values within the element nodes in that file. I have tried the following code: import pandas as pd import xml.etree.ElementTree as …

Total answers: 1

I can't read an XML file

I can't read an XML file Question: It’s my first time working with XML files, yet I have a problem with a code as simple as: from xml.etree import ElementTree as ET tree = ET.parse(‘some_xml_file.xml’) s = ET.tostring(tree, method = ‘xml’) root = tree.getroot() all I am trying to do here is reading the XML …

Total answers: 1

How to read specific data and write to csv file

How to read specific data and write to csv file Question: I have data in xml file and I am reading 3 columns : price , name , calories xml data <?xml version=’1.0′ encoding=’utf-8′?> <data> <row> <index>0</index> <price>$5.95</price> <name>Belgian Waffles</name> <desc>Two of our famous Belgian Waffles with plenty of real maple syrup</desc> <calories>650</calories> </row> <row> …

Total answers: 3

How can I transfer the attributes of parent elements to child elements in XML using python?

How can I transfer the attributes of parent elements to child elements in XML using python? Question: Given the following structure of XML file: <root> <parent attr1="foo" attr2="bar"> <child> something </child> </parent> . . . how can transfer the attributes from parent to child and delete the parent element to get the following structure: <root> …

Total answers: 1

etree Clone Node

etree Clone Node Question: How to clone Element objects in Python xml.etree? I’m trying to procedurally move and copy (then modify their attributes) nodes. Asked By: Ming-Tang || Source Answers: If you have a handle on the Element elem‘s parent you can call new_element = SubElement(parent, elem.tag, elem.attrib) Otherwise you might want to try new_element …

Total answers: 7