[xsd-users] C++/Parser: string extension

Boucher, Robert J Robert.Boucher at ca.com
Fri Oct 20 14:49:12 EDT 2006


Hello!
I have encountered difficulty in correctly using XSD for parsing a
schema that extends the built-in string data type.  For example, I
replaced the type of the element "name" in the hello.xsd sample with
"stringWithType" which simply adds an attribute "type".

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:complexType name="hello_type">
        <xsd:sequence>
            <xsd:element name="greeting" type="xsd:string"/>
            <xsd:element name="name" type="stringWithType"
maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="stringWithType">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string">
                <xsd:attribute name="type" type="xsd:string" />
            </xsd:extension>
        </xsd:simpleContent>
   </xsd:complexType>

    <xsd:element name="hello" type="hello_type"/>
</xsd:schema>

When I try to create a parser using this schema, and implement the
parser for stringWithType, I can capture the type value, when present,
but I cannot capture the value of the actual element.  On the otherhand,
if I configure the hello_type to use the standard string parser for
stringWithType, I get the value but obviously not the attribute.

<hello xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
<http://www.w3.org/2001/XMLSchema-instance>
xsi:noNamespaceSchemaLocation="hello.xsd">
    <greeting>Hello</greeting>
        <name type="type1">sun</name>
        <name type="type2">moon</name>
        <name type="type3">world</name>
</hello>

Is there a way to implement stringWithType to capture both the value and
the type?  I tried subclassing the template, but without success.
Hopefully the solution may be obvious for someone out there.

Thank you very much for your assistance,

Robert Boucher




More information about the xsd-users mailing list