Моя XML структура файла:
<tp:Package xml:lang='en-US' xmlns:tp='http://myorg.org/2016/mypackage'>
<tp:identifier>http://www.myweb.com/</tp:identifier>
<tp:name>MyName</tp:name>
<tp:description xml:lang='en-US'>My Description</tp:description>
<tp:version>2020-01-01</tp:version>
<tp:license href='http://www.myweb.com/terms/TermsConditions.html' name='Terms and Conditions' />
<tp:publisher>MyPublisher</tp:publisher>
<tp:publisherURL>http://www.mypublisherurl.com/</tp:publisherURL>
<tp:publisherCountry>US</tp:publisherCountry>
<tp:publicationDate>2020-01-01</tp:publicationDate>
<tp:entryPoints>
<tp:entryPoint>
<tp:name>Form A</tp:name>
<tp:description>This is Form A.</tp:description>
<tp:version>v313</tp:version>
<tp:entryPointDocument href='http://www.myweb.com/myfile.xsd' />
<tp:formType>1</tp:formType>
</tp:entryPoint>
<tp:entryPoint>
<tp:name>Form B</tp:name>
<tp:description>This is Form B.</tp:description>
<tp:version>v313</tp:version>
<tp:entryPointDocument href='http://www.myweb.com/myfile.xsd' />
<tp:formType>2</tp:formType>
</tp:entryPoint>
</tp:entryPoints>
</tp:Package>
Как мне прочитать этот файл, используя etree и l oop над каждым тегом и распечатать значения элемента tp: имя, tp: описание, tp: версия, tp: entryPointDocument, tp: formType
Ниже приведен мой частичный python код:
from lxml import etree
tree = etree.parse(xmlfilepath)
root = tree.getroot()
for elt in root.xpath("//tp:entryPoints", namespaces={'tp': 'http://myorg.org/2016/mypackage'}):
print(elt)