Friday 15 June 2012

python - Using lxml to generate XPath for a specific line -



python - Using lxml to generate XPath for a specific line -

is possible generate xpath using line number , python lxml library?

background: have references (not xpath, parts of them) in document , find references specific element (in specific line)

enter code here <root> <element> <name>element1</name> <contains> <element> <name>color</name> <value-ref>/colors/red</value-ref> </element> </contains> </element> <element> <name>colors</name> <contains> <element> <name>red</name> <value>0xff0000</value> </element> <element> <name>blue</name> <!-- line i'd xpath --> <value>0x0000ff</value> </element> </contains> </element> </root>

and out of xpath create look in value-ref (this can done regex)

i use

etree.iter()

to iterate on elements , compare the

element.sourceline

and compare line i'm looking for. have element i'm looking , can go on generate path described above.

thanks.

python xpath lxml

No comments:

Post a Comment