You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Jeehong Min <je...@parasoft.com> on 2004/11/05 02:29:35 UTC
derived types in instance documents
All,
I have the following types defined in a schema:
<xsd:complexType name="AttributedString">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute ref="wsu:Id"/>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="EncodedString">
<xsd:simpleContent>
<xsd:extension base="wsse:AttributedString">
<xsd:attribute name="EncodingType" type="xsd:anyURI"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="UsernameTokenType">
<xsd:sequence>
<xsd:element name="Username" type="wsse:AttributedString"/>
<xsd:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute ref="wsu:Id"/>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:complexType>
Note that EncodedString is derived from AttributedString.
The following passes XML Validation:
<ns1:UsernameToken>
<ns1:Username xsi:type="ns1:AttributedString" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
my username</ns1:Username>
</ns1:UsernameToken>
And so does this:
<ns1:UsernameToken>
<ns1:Username>my username</ns1:Username>
</ns1:UsernameToken>
But Xerces throws an error on the following:
<ns1:UsernameToken>
<ns1:Username EncodingType="someType" xsi:type="ns1:EncodedString" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">my username</ns1:Username>
</ns1:UsernameToken>
Xerces says:
cvc-elt.4.3: Type 'ns1:EncodedString' is not validly derived from the type definition, 'AttributedString', of element 'ns1:Username'.
It's not clear to me what is wrong with the XML. Can someone shed some light?
Thanks.
--
Jeehong Min
Software Engineer
SOAPtest Development
Parasoft Corporation
"We Make Software Work"
Re: derived types in instance documents
Posted by George Cristian Bina <ge...@sync.ro>.
Hi,
Make sure you are using Xerces 2.6.2. I cannot reproduce your error with
the following documents. The instance is reported valid by Xerces 2.6.2
against the schema.
test.xml
<?xml version="1.0" encoding="UTF-8"?>
<ns1:UserNameToken xmlns:ns1="wsse"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="wsse test.xsd">
<ns1:Username xsi:type="ns1:EncodedString"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
EncodingType="someType">test</ns1:Username>
</ns1:UserNameToken>
test.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="wsse"
xmlns:wsse="wsse" xmlns:wsu="wsu" elementFormDefault="qualified">
<xsd:import namespace="wsu" schemaLocation="wsu.xsd"/>
<xsd:complexType name="AttributedString">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute ref="wsu:Id"/>
<xsd:anyAttribute namespace="##other"
processContents="lax"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="EncodedString">
<xsd:simpleContent>
<xsd:extension base="wsse:AttributedString">
<xsd:attribute name="EncodingType" type="xsd:anyURI"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="UsernameTokenType">
<xsd:sequence>
<xsd:element name="Username" type="wsse:AttributedString"/>
<xsd:any processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute ref="wsu:Id"/>
<xsd:anyAttribute namespace="##other" processContents="lax"/>
</xsd:complexType>
<xsd:element name="UserNameToken" type="wsse:UsernameTokenType"/>
</xsd:schema>
wsu.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="wsu" attributeFormDefault="qualified">
<xs:element name="test"/>
<xs:attribute name="Id" type="xs:string"/>
</xs:schema>
Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jeehong Min wrote:
> All,
>
> I have the following types defined in a schema:
>
> <xsd:complexType name="AttributedString">
> <xsd:simpleContent>
> <xsd:extension base="xsd:string">
> <xsd:attribute ref="wsu:Id"/>
> <xsd:anyAttribute namespace="##other" processContents="lax"/>
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>
>
> <xsd:complexType name="EncodedString">
> <xsd:simpleContent>
> <xsd:extension base="wsse:AttributedString">
> <xsd:attribute name="EncodingType" type="xsd:anyURI"/>
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>
>
> <xsd:complexType name="UsernameTokenType">
> <xsd:sequence>
> <xsd:element name="Username" type="wsse:AttributedString"/>
> <xsd:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
> </xsd:sequence>
> <xsd:attribute ref="wsu:Id"/>
> <xsd:anyAttribute namespace="##other" processContents="lax"/>
> </xsd:complexType>
> Note that EncodedString is derived from AttributedString.
>
> The following passes XML Validation:
>
> <ns1:UsernameToken>
> <ns1:Username xsi:type="ns1:AttributedString"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <http://www.w3.org/2001/XMLSchema-instance">>
> my username</ns1:Username>
> </ns1:UsernameToken>
> And so does this:
>
> <ns1:UsernameToken>
> <ns1:Username>my username</ns1:Username>
> </ns1:UsernameToken>
>
> But Xerces throws an error on the following:
>
> <ns1:UsernameToken>
> <ns1:Username EncodingType="someType" xsi:type="ns1:EncodedString"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">my
> <http://www.w3.org/2001/XMLSchema-instance">my> username</ns1:Username>
> </ns1:UsernameToken>
> Xerces says:
>
> cvc-elt.4.3: Type 'ns1:EncodedString' is not validly derived from the
> type definition, 'AttributedString', of element 'ns1:Username'.
>
> It's not clear to me what is wrong with the XML. Can someone shed some
> light?
>
> Thanks.
>
> --
> Jeehong Min
> Software Engineer
> SOAPtest Development
> Parasoft Corporation
>
> "We Make Software Work"
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org