[xsd-users] Lines numbers after parsing

Boris Kolpackov boris at codesynthesis.com
Fri Jun 29 07:29:22 EDT 2007


Hi Jon,

Jon D <tyrecius13 at yahoo.com> writes:

>   My problem comes when I want to do semantic checks after the parsing
> is done. At that point, all of the diagnostic information (line
> numbers, and the text of the lines themselves) seems to
> disappear. This information is a crucial pre-condition if I want to
> give helpful error messages.
>
>   The question is, how do I get line numbers after parsing is done? If I
> can't, how hard would it be to modify the compiler to save that
> information and make it available?

The most natural way to access this information if by using the
DOM association. This feature allows you to keep the DOM tree of
your XML document around. You can call the _node () function on
a C++/Tree node and get the corresponding DOM node. From there
you can get the actual element/attribute name (those are not kept
in the C++/Tree nodes) as well as possibly reconstruct the XML
fragment to show to the user.

Line and column numbers pose a bit of a problem since Xerces-C++ DOM
tree does not store them (for practical reasons). This, however,
is relatively easy to overcome by customizing the XercesDOMParser
and storing the line/column information as user data. One example
of this approach is available in the Xerces-C++ mailing list
archives:

http://marc.info/?l=xerces-c-users&m=115531248220918&w=2

It is a bit convoluted and can be significantly simplified if
you don't need to keep the file information with each node
(in that case you can just store line and column numbers
directly as void* and get rid of all the allocations, etc.).
If you are interested, I can post a simpler version here.

If you are using the custom DOM parser, you will need to set
up your own XML-DOM stage. This is described in the Wiki FAQ
Section 2, "Parsing":

http://wiki.codesynthesis.com/Tree/FAQ

For more information about the DOM association feature, see
the "mixed" example in examples/cxx/tree/mixed/ as well as
the Section 3.2, "Flags and Properties" in the C++/Tree
Mapping User Manual:

http://codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#3.2


hth,
-boris




More information about the xsd-users mailing list