I have a project where I connect to an API that puts out the data in XML. I can grab the values of the tags and print those out but want to grab the whole line of specific lines in the XML and write it out to an XML file. How is the best way to do this in Python? I don't really have any code to share as I'm unsure how to write this.
Here is an example of the XML file or output given by the api:
<?xml version="1.0" ?>
<Product ParentID="XXX" ID="XXX" title="XXX">
<Values>
<Value AttributeID="ABC" title="ABC1">ABC</Value>
<Value AttributeID="DEF" title="DEF1">DEF</Value>
<Value AttributeID="GHI" title="GHI1">GHI</Value>
</Values>
</Product>
I would want to write the xml file to read like this:
<?xml version="1.0" ?>
<Product ParentID="XXX" ID="XXX" title="XXX">
<Values>
<Value AttributeID="ABC" title="ABC1">ABC</Value>
<Value AttributeID="GHI" title="GHI1">GHI</Value>
</Values>
</Product>
<Value AttributeID="DEF" title="DEF1">DEF</Value>: is it because it's the second? Because its text value isDEF? etc.ABCandGHI? What exactly is in them that makes them different from the one in the middle? Python can't guess why you are doing what you are doing....