Well, I can't really use a SAX parser in this situation, because I need
the whole DOM tree to search.
However, I was thinking that it might be possible to calculate the text
position of a node by evaluating all the DOMText nodes in between, since
they should carry all the spaces and line breaks. This would at least
allow to find the offending line in the source document.
I was wondering if that would be a feasible method and maybe if it was
even included in Xerces - or if someone has already implemented it
outside of Xerces (so I could borrow some code ;)
I certainly agree that keeping the line number info within the DOMNode
is impractical for a general purpose XML parser.
Any clues?
Cheers,
Uwe
Jesse Pelton jsp-at-PKC.com |xerces-c-users mailing list| schrieb:
I don't think so. Any given node might or might not derive from a parse
operation, so keeping row and column for nodes is challenging. What
would you do if a node had been inserted or deleted ahead of the node
you're currently analyzing - should the file position data for
subsequent parsed nodes be retained or discarded? What values do you
use for nodes that you've added? Furthermore, not every application
wants this information, and there's overhead for carrying it around for
every node.
You might find that a SAX parser would serve your needs better. You can
then use a DocumentLocator. From the
ContentHandler::setDocumentLocator() documentation: "The locator allows
the application to determine the end position of any document-related
event, even if the parser is not reporting an error. Typically, the
application will use this information for reporting its own errors (such
as character content that does not match an application's business
rules)."
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Monday, June 12, 2006 12:28 PM
To: [email protected]
Subject: how to locate a DOMNode in it's source file
I parsed an XML document with the xerces DOM parser and receive a DOM
tree as a result. Subsequently, I analyse the DOM tree.
However, my code might detect errors during the analysis, and report
them. The problem here is though that I only have the DOM tree and it's
nodes, so for a given DOMNode* containing the offending node, I'd need
to find out the position in the source file from which it was generated.
Is there an easy way of doing that with Xerces?
Cheers,
Uwe
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]