sawpythonnewbie
sawpythonnewbie

Reputation: 29

Incorrect Value When Parsing XML File

I am trying to get the ImageVersion number from an xml file.

This is the code I have:

from xml.etree import ElementTree as ET
tree = ET.parse(file.xml)
root = tree.getroot()
siteImageVersion= (root.getchildren()[0].attrib['ImageVersion'])

The xml file looks like this

<!--InputFile D:/OutputFiles/Config.xml was parsed-->
<Configuration xmlns="http://....xsd"  version="3">
  <TesterRecord TimeStamp="2020-09-04T02:07:51-07:00"  Name="SomeName"  IPAddress="IPAddress"  SystemId="Id"  Version="0.1.0.1.00003"  ImageVersion="Test_XXX_3.10.5.1"  CellIndex="33"  GeneratedBy="Name"  Other="N/A">
  </TesterRecord>
</Configuration>

I would expect that the output would be Test_XXX_3.10.5.1 (as it should be). But for some reason, I am getting this output instead: Test_XXX_3.10.4.2. I have no idea how the number changed, there is no 3.10.4.2 in the XML file.

Upvotes: 1

Views: 44

Answers (1)

d410
d410

Reputation: 78

Are you sure that you are reading the correct file? (Sometimes it is merely the correct processing on the wrong data.) Is there a file anywhere in that directory that does have "Test_XXX_3.10.4.2"? Delete/Move/Rename it and see what happens.

Caching could also be a cause, if you are accessing the data from a remote source. You might not be getting the updated file, but getting the old cached version. Try a brand new file and see what happens.

Upvotes: 1

Related Questions