-1

I need the output of the z:row along from the xmlfile which is received as response from Sharepoint

I need the output as

Title dept
test  hr
gang  ht

The input i got as xmlfile is

<xml xmlns:s="uuid:ABCDDC" xmlns:dt="uuid:REDSD" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
    <s:Schema id="RowsetSchema">
        <s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30">
            <s:AttributeType name="Title" rs:name="Title" rs:number="1">
                <s:datatype dt:type="string" dt:maxLength="512"/>
            </s:AttributeType>
        <s:AttributeType name="dept" rs:name="dept" rs:number="1">
            <s:datatype dt:type="string" dt:maxLength="512"/>
        </s:AttributeType>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row Title="test" dept="hr" />
<z:row Title="gang" dept="ht" />
</rs:data>
</xml>
Rafa
  • 487
  • 7
  • 22
  • With the namespace the parsing doesnt work and i am new to python any help is highly appreciated – Rafa Apr 26 '17 at 18:51

1 Answers1

0

You can use lxml package to find all the data nodes like so:

from lxml import etree

xml_tree = etree.parse("file.xml")

data_nodes = xml_tree.findall("//{#RowsetSchema}row")

for node in data_nodes:
    print node.get('Title'), node.get("dept")

Finding the particular node you want can get tricky sometimes because of the namespaces associated with them. You'd think you want the "row" node but it is actually "{#RowsetSchema}row". If you want to check what are the namespaces associated with each nodes, you can use the iter() method on the xml_tree and print tag names.

Example:

for node in xml_tree.iter():
    print node.tag
Manthan Thakar
  • 209
  • 1
  • 9