XPath to Line Number?



In one sentence: Given an XML file and an XPath pointing to a certain
node, how can I find the line-number of that node in the original XML
file?

I am building a script that reads an XML file, checks it against a
bunch of validation rules, and outputs any errors and/or warnings.
Currently, I read the XML file via XML::XPath->new(filename =>
$filename), but I am open to alternative suggestions. When I do find
an error (for example, a certain attribute may have an invalid keyword
for its value), I want to print the line number of the original XML
file in which this error occurred.

Searching on the web, I found several references to XML::Twig. I was
wondering if anyone could offer suggestions or advice about XML::Twig
or any other modules that could help.

Thanks in advance!

.



Relevant Pages

  • Re: XPath to Line Number?
    ... how can I find the line-number of that node in the original XML ... bunch of validation rules, and outputs any errors and/or warnings. ... It sounds like you want to validate the XML file before even using ... I am having trouble with finding a good DTD or Schema ...
    (comp.lang.perl.modules)
  • Save changes in the original XML file
    ... I'm trying to update XML file using DOM. ... But as the dom-tree is stored ... in memory, i found the original XML file is not updated after i ... Is there any command that saves changes of nodes into the original XML ...
    (comp.lang.tcl)