python - Retrieving the value of specific attribute using E Tree -


i have xml document through want ti retrieve value of specific attribute using e tree. below document-snippet have:

-<orcid-message>     <message-version>1.2</message-version>   -<orcid-profile type="user">     -<orcid-identifier>         <uri>http://orcid.org/0000-0001-5105-9000</uri>         <path>0000-0001-5105-9000</path> 

i want retrieve value of 'path' have tried far:

tree = et.parse(file) root = tree.getroot() element in root:     all_tags in element.findall('.//'):          if all_tags.text:              print all_tags.text, '|', all_tags.tail 

what should value of 'path'

you can use element class' find method path element wish pick out, example:

import xml.etree.elementtree et  tree = et.parse("filename") root = tree.getroot() path = root.find("orcid-profile/orcid-identifier/path") print(path.text) 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -