[xsd-users] Parsing for the substitutionGroup
Boris Kolpackov
boris at codesynthesis.com
Thu Mar 6 04:26:06 EST 2008
Hi Ninh,
Ninh Tran Dang <tdninh at tma.com.vn> writes:
> I got problem when using Tree mapping to the configNameType below. When
> parsing with the elements in the "config-name" substitutionGroup like:
> startup, candidate, running, I received the same object of configNameType
> for startup, candidate and running. So how to differentiate and get the
> correct element in this case?
>
> The most important thing is how to know the incoming element name (startup,
> candidate, or running) when they are defined to the same type of
> configNameType.
Ok, so you are using C++/Tree, not C++/Parser. Since all your elements
are of the same type, the only thing that differentiates them is the
element name. This makes the whole idea somewhat pointless: it would
be much more straightforward to add an attribute to configNameType
that holds this information instead of encoding it into element's
names.
Element names are not preserved in the object model. So the only way
to access them is via DOM. There are several way to do this:
1. If the startup, candidate, etc., elements are document roots
then you can split the XML-to-object model parsing into two
stages: XML-to-DOM and DOM-to-object model. This will allow
you to determine which element is used. For more information
on this approach, see the 'multiroot' example.
2. Using the DOM association feature you can obtain a corresponding
DOM element from an object model node and then query the element's
name. For more information, see the "DOM Association" section in
the C++/Tree Mapping User Manual:
http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#5.1
This method will work for both root and non-root elements.
3. For non-root elements, you can also customize the parsing constructor
of the type which includes the config-name element and query the
element name there. For more information on this approach see the
'wildcard' example in the examples/cxx/tree/custom/ directory as
we all the C++/Tree Mapping Customization Guide:
http://wiki.codesynthesis.com/Tree/Customization_guide
Boris
More information about the xsd-users
mailing list