0

I am using Python to pick a specific set of values from my XML:

children = root[2].getchildren()
for child in children:
    ET.dump(child)

Once I use this I get a print of exactly what I need from my XML. I can also change the root number to access different data. I want to export this value as a new separate xml, however when I use :

tree.write('new.xml')

It exports the entire XML, as before. It is not just the value I specified above, value I selected.

James Z
  • 12,209
  • 10
  • 24
  • 44
Alex L
  • 1
  • 1
    Can you share full code? – Alderven Mar 12 '19 at 13:09
  • Why do you `tree.write(...` if you only want `child`? – stovfl Mar 12 '19 at 14:10
  • I have an xml with say 10 different currency names. Each name has sub elements with different values etc. What I wanted was to be able to pick specific currency and get ALL of the data for that currency, meaning the main root and all of it's subroots. Once I got the output I wanted I wanted to save it as an xml file. When I saved it as a new xml file, by default it was saving the entire file with all of the currency data in it not the ones, which I have selected to be viewed. – Alex L Mar 12 '19 at 14:54
  • @AlexL: Did you consider to answer my Question? Also we need [mcve] and example XML with at least 3 Elements. – stovfl Mar 12 '19 at 21:20
  • This is for work...hence I cannot provide the actual XML...my question was how do I pick only the root and entire element structure for specific items and only then save new xml with those items so say I have a tree made up of 5 separate names and under each name I have all the variables and values ...if I want to pick 2 names with all their details this is what I meant – Alex L Mar 19 '19 at 16:34

0 Answers0