[xsd-users] cpp-parser nested elements/attributes
Kevin Wooten
kevin at wooten.com
Sat Apr 15 20:57:05 EDT 2006
I have either misunderstood how to setup a cpp-parser or it seems to be
quite broken. During parsing, the "event_router" object will search the
tree starting at the root element and traverse downwards through the
current scope, each time a new element starts. This means that elements
and attributes with the same names are always handled incorrectly in
elements above them in the scope.
Here is an example:
---- Schema ----
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="Sub">
<xs:sequence>
<xs:element name="sub" type="Sub" minOccurs="0"/>
<xs:element name="sub2" type="Sub" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
<xs:complexType name="Test">
<xs:sequence>
<xs:element name="sub" type="Sub" />
</xs:sequence>
</xs:complexType>
<xs:element name="test" type="Test" />
</xs:schema>
----- XML -----
<test name="testName">
<sub name="subName">
<sub name="nestedName" />
<sub2 name="sub2Name" />
</sub>
</test>
In this case when starting the first "sub" element the event router will
ask "test" if it can start the element. It can and does. When the second
sub element is started, the event_router again ask the "test" element if
it can start the "sub" element. It can and does, totally screwing the
parsing. What it needs to do is ask only the current scope if it can
start "sub" element, since it is the only valid place to start a new
element in. To demonstrate how it will work 'sometimes', when starting
the "sub2" element, the event_router still does the incorrect thing, but
since "test" cannot start a "sub2" element, it continues trying the
first "sub" element which succeeds. It is at this time you will see the
attribute problem, because attributes are handled in the same way as
elements. All the "name" attributes in this example will be handled by
the "test" element parser.
More information about the xsd-users
mailing list