 |
 |
 |
Hello,
I'm investigating the structure of an XML file. The best tool is an usual
text editor (vim), but I need to look at some specific tags in some
specific contexts.
The idea is to execute an XPath and somehow to get to the location in the
editor. Remembering that I saw something interesting while playing with
libxml internals, I re-checked... And bingo! I've written a script which
executes an XPath and prints the result together with the line number in
the source XML file.
Usage:
python xpath.py document xpath
Code:
<xpath.py>
import sys,libxml2
doc_name = sys.argv[1]
xpath = sys.argv[2]
doc = libxml2.parseFile(doc_name)
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval(xpath)
for node in res:
print node.lineNo()
print node
doc.freeDoc()
ctxt.xpathFreeContext()
del ctxt
del doc
</xpath.py>
I think many will find this code useful. If you want bookmark it, here is
the permanent address:
http://uucode.com/blog/2007/03/05/execute-an-xpath-and-get-the-line-numbers/
--
Oleg Parashchenko olpa@ http://xmlhack.ru/ XML news in Russian
http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme
http://olpa.livejournal.com/
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |