python - Lxml: Return a part of the xml file as string -


i parsing xml file using lxml parser looks this:

    # elements above     <contact>        <phonenumber>             #something        </phonenumber>     </contact> 

i want able return part of xml file.

like suppose if on phonenumber, want lxml return between string .

i dont want return textb/w phonenumber entire string :

    <phonenumebr>something</phonenumber> 

is possible ?

to print part of xml tree, can use lxml.etree.tostring. on python 2:

in [1]: lxml.etree import tostring, parse  in [2]: tree = parse('test.xml')  in [3]: elem = tree.xpath('//phonenumber')[0]  in [4]: print tostring(elem) <phonenumber>                    </phonenumber> 

for more information can refer "serialisation" section of lxml tutorial.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -