Answer the question
In order to leave comments, you need to log in
How to get XML from xpath Element?
I need to get XML from xpath Element.
afile.xml:
<?xml version = "1.0" encoding = "UTF-8"?>
<applications >
<application >
<journalNumber > 1 < /journalNumber >
</application >
<application >
<journalNumber > 2</journalNumber>
</application >
</applications >
etxml = etree.parse(afile)
root = etxml.getroot()
value = root.xpath("//*[local-name() = '{0}']".format("application"))
<Element {http://zakupki.gov.ru/oos/types/1}application at 0x16568142d48>
Answer the question
In order to leave comments, you need to log in
Docs
Element to String Element
Text
test.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<applications>
<application>
<journalNumber>1</journalNumber>
</application>
<application>
<journalNumber>2</journalNumber>
</application>
</applications>
from lxml import etree
etxml = etree.parse('test.xml')
root = etxml.getroot()
values = root.xpath("//*[local-name() = 'journalNumber']")
for value in values:
print('XML: ', etree.tostring(value, encoding='unicode'))
print('Text: ', value.text)
XML: <journalNumber>1</journalNumber>
Text: 1
XML: <journalNumber>2</journalNumber>
Text: 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question