Click here to get back home

XPath to Line Number?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
XPath to Line Number? Andrew 06-26-2007
Posted by Andrew on June 27, 2007, 7:20 pm
Please log in for more thread options


> 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.


Similar ThreadsPosted
Help with XML::Twig xpath syntax, please October 16, 2005, 6:56 pm
XML::XPath delete function November 26, 2007, 3:35 pm
Parsing Doctype Entitites using XML::XPath November 5, 2004, 10:13 am
XML::Twig::XPath - strange problem November 10, 2005, 9:44 am
Ask for recommended module for precise number January 22, 2006, 3:25 am
Proposed module: Number::NaryPP March 10, 2006, 6:46 am
Maximum number of sockets - FD_SETSIZE September 8, 2006, 10:14 am
finding version number of a library August 10, 2007, 6:54 am
XML::Generator::DBI - use of uninitialized value on line 180 and 187 September 12, 2004, 8:00 pm
Shebang line for modules? January 8, 2008, 4:31 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap