python 2.7 - XML parsing to access tags -


i have xml file, fetch tags, edit necessary element , write new file (updated xml).

<vdu xmlns="test:file"> <lsm>     <m-id>v1</m-id>     <name>v1</name>     <communication>bi</communication>     <states>         <s-name>stage1</s-name>         <state>             <s-type>defaultstate</s-type>             <s-func>                 <p-name>pkgname</p-name>                 <f-list>                     <f-name>funcname</f-name>                     <f-arg>{&amp;}</f-arg>                 </f-list>             </s-func>         </state>         <lib-path>libpath</lib-path>         <e-list>             <e-name>noevent</e-name>             <event>                 <nss>inc</nss>                 <nfs>inc</nfs>                 <actions>                     <p-name>pkgname</p-name>                     <f-list>                         <f-name>tof</f-name>                         <f-arg></f-arg>                     </f-list>                 </actions>             </event>         </e-list> 

however not able text xml. tried couple of things below.

import xml.etree.elementtree et root = et.parse(r'c:\users\sample\file.xml').getroot()  child in root:     print child.tag     child in child.iter('s-type'):         print child 

output:

 <element '{est:file}lsm  [] 

also, tried lxml(still exploring), didnt expected answer. appreciated.

root.xpath("//lsm/states/e-list/e-name/text()")  

output:

[] 

however able access values root[0][0].text


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -