Re: XPath to Line Number?
- From: MM <1234marlon@xxxxxxxxx>
- Date: Tue, 26 Jun 2007 23:20:42 -0000
On Jun 26, 1:39 pm, Andrew <acheon...@xxxxxxxxx> 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.
Thanks in advance!
It sounds like you want to validate the XML file before even using
XPATH. I am having trouble with finding a good DTD or Schema
validation package (as seen in the thread prior to this one), although
several are available and may meet your requirements. Anyway, you
will need to create a DTD or Schema file to house valid/default
values. Search CPAN for DTD and "XML Schema" to find packages that
will validate XML files.
I prefer using SAX and coding my own data structure, so I am not much
help when it comes to XML::Twig. However, I just quickly read the POD
for XML::Twig and I do not think it actually processes the DTD; I
think it just makes DTD information available in the tree. If
XML::Twig does come with a validation process I will hop on the
bandwagon and try to use it too!!! But right now I am busy playing
with XML::DTD. Anyway, others can comment on this....
I hope I am on the right track here, but I am not 100% sure of what
you are doing.
.
- Follow-Ups:
- Re: XPath to Line Number?
- From: Andrew
- Re: XPath to Line Number?
- References:
- XPath to Line Number?
- From: Andrew
- XPath to Line Number?
- Prev by Date: XPath to Line Number?
- Next by Date: Re: Help with validating XML (DTD or Schema) with PERL
- Previous by thread: XPath to Line Number?
- Next by thread: Re: XPath to Line Number?
- Index(es):
Relevant Pages
|