0

I'm looking to take specific data from a XML file with this schema, there is many children elements excluded but the data I want is from the child elements, ROW. I've tried using the lettered tags only however there are thousands in the document.

What I want to do is assign the child to its own element then extract the data but I haven't had any luck.

Any suggestions are greatly appreciated!

Thanks

<REPORT>
       <RESULT DrillLevel="1">
              <ROWSET title="Days">
                 </ROWSET>
              <MAP>
                 </MAP>
          </RESULT>
       <RESULT DrillLevel="2">
              <ROWSET title="Operators">
                     <HEADERS>
                        </HEADERS>
                     <ROW num="1" expandid="0" level="0">
                            <C>Name</C>
                            <N>91.0</N>
                            <I>3346.0</I>
                            <U>00:17:34</U>
                            <V>17.0</V>
                            <S>00:00:35</S>
                            <X>00:00:11</X>
                            <D>95.0</D>
                            <O>52.0</O>
                            <Z>00:17:05</Z>
                            <J>98456.0</J>
                            <H>100216.0</H>
                            <E>1053.0</E>
                            <T>00:01:42</T>
                            <Y>00:18:10</Y>
                            <K>103562.0</K>
                            <W>102.0</W>
                            <G>457.0</G>
                            <L>95.0</L>
                            <F>0.0</F>
                            <M>96.0</M>
                        </ROW>
vkrams
  • 7,267
  • 17
  • 79
  • 129
Michael
  • 1
  • 1
  • possible duplicate of [How to use xpath in Python?](http://stackoverflow.com/questions/8692/how-to-use-xpath-in-python) – ivan_pozdeev Nov 20 '14 at 03:11
  • I finally got the XPath syntax correct. The answer is def parseXML(): tree = ET.parse('test.xml') root = tree.getroot() for c in root.findall(".//RESULT[@DrillLevel='2']/ROWSET[@title='Operators']/ROW/C"): print c.text – Michael Nov 20 '14 at 03:38
  • Possible duplicate of [How do I parse XML in Python?](http://stackoverflow.com/questions/1912434/how-do-i-parse-xml-in-python) – Harv Oct 10 '16 at 06:27

0 Answers0