Re: XPath to Line Number?
- From: Andrew <acheong87@xxxxxxxxx>
- Date: Wed, 27 Jun 2007 16:20:34 -0700
On Jun 27, 3:48 am, mirod <m...@xxxxxxxxxxx> wrote:
Andrew wrote:
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.
Keeping the line number around is actually a FAQ:http://xmltwig.com/xmltwig/XML-Twig-FAQ.html#Q18
And no, XML::Twig does not validate the XML (it's ultimately based on
expat which is a non-validating parser).
XML::LibXML has also that info available (even more conveniently: the
line_number method in XML::LibXML::Node).
I don't know those modules very well, but the XML::Schematron::* modules
might also be usefull, they are designed for that kind of task I think:http://search.cpan.org/dist/XML-Schematron/
--
mirod
Thanks, everyone! Currently, I'm busy with another part of the code,
but I will post back here after trying these suggestions.
.
- References:
- XPath to Line Number?
- From: Andrew
- Re: XPath to Line Number?
- From: mirod
- XPath to Line Number?
- Prev by Date: GD::Graph with Image Map implementation question
- Next by Date: Re: HTML::Template, is it possible to nest <TMPL_VAR> inside a <TMPL_IF>?
- Previous by thread: Re: XPath to Line Number?
- Next by thread: bignum incompatible with loos_like_number ???
- Index(es):