I have a XML file as follows:
<?xml version='1.0' encoding='UTF-8'?><graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.1/graphml.xsd">
<key id="labelV" for="node" attr.name="labelV" attr.type="string"/>
<key id="Count" for="node" attr.name="Count" attr.type="double"/>
<key id="URI" for="node" attr.name="URI" attr.type="string"/>
<key id="labelE" for="edge" attr.name="labelE" attr.type="string"/>
<graph id="G" edgedefault="directed">
<node id="4096">
<data key="labelV">v</data>
<data key="Count">1.0</data>
<data key="URI">http://www.guavus.com/rflx/ont/c?ln=en&v=1.0&cust=comcast&prj=x1&id=63a9f0ea7bb98050796b649e85481845&norm=n</data>
</node>
<node id="4104">
<data key="labelV">v</data>
<data key="Count">0.1111111111111111</data>
<data key="URI">http://www.guavus.com/rflx/ont/l?ln=en&v=1.0&cust=comcast&prj=x1&id=c01ed2b3bffa35c9c2d2c3c723f18bdb&norm=n</data>
</node>...
I want to add more data elements to the node element. I am not able to reach to the node element.
tree = ET.parse("ner.xml")
root = tree.getroot()
print(root)
I get
<Element '{http://graphml.graphdrawing.org/xmlns}graphml' at 0x10e015188>
and root.findall('graph') return empty. why is that? Can anyone help me with this?
root.findall(‘./graph’)should find all the graph nodes and then for each of these,findall(‘./node’)should get you each node. Read the tutorial and try it out with the provided example, try different things.