You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by ZhiHai Liu <Zh...@dyncorp-bksd.com> on 2000/09/20 23:50:24 UTC
"type" or "ref"?
I have one schema "employee.xsd" to validate "employee.xml". "employee.xsd"
uses a data type from "test.xsd". It imports "test.xsd" because they have
different target namespace.
1. employee.xml
<?xml version="1.0" encoding="UTF-8"?>
<employee
xmlns="emp"
xmlns:t="test"
xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
xsi:schemaLocation='emp employee.xsd'
>
<record>
<lname>John</lname>
<fname>Smith</fname>
<t:department>Accounting</t:department>
</record>
</employee>
2. employee.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/1999/XMLSchema"
xmlns:e="emp"
xmlns:t="test"
targetNamespace="emp"
elementFormDefault="qualified"
>
<import
namespace="test"
schemaLocation="test.xsd"
/>
<element name="employee">
<complexType>
<element name="record" type="e:RecordType" minOccurs="1"
maxOccurs="unbounded"/>
</complexType>
</element>
<complexType name="RecordType">
<element name="lname" type="string"/>
<element name="fname" type="string"/>
<!--
<element name="department" type="t:department"/>
-->
<element ref="t:department"/>
</complexType>
</schema>
3. test.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/1999/XMLSchema"
targetNamespace="test"
>
<element name="department" type="string"/>
<!--
<simpleType name="department" base="string"/>
-->
</schema>
If I use
<element name="department" type="string"> in test.xsd
and
<element ref="t:department"/> in employee.xsd,
the validation is fine.
However, if I use
<simpleType name="department" base="string"/> in test.xsd
and
<element name="department" type="t:department"/> in employee.xsd,
it will give an error message:
...
startElement: fname
in namespace emp (fname)
characters: Smith
endElement: fname
ignorableWhitespace: [
]
Error in parsing: null
The reason to use test.xsd is that I want to have a schema which has many
datatype definition, so I can reuse them in other schemas later.
Thanks,
Zhihai
Re: "type" or "ref"?
Posted by Eric Ye <er...@locus.apache.org>.
I recall this bug was fixed a few days ago, unfortunately it's after Xerces
1.2.0 was put out. So check out the latest source from CVS and see if you
problem will go away.
_____
Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
----- Original Message -----
From: "ZhiHai Liu" <Zh...@dyncorp-bksd.com>
To: <xe...@xml.apache.org>
Sent: Wednesday, September 20, 2000 2:50 PM
Subject: "type" or "ref"?
> I have one schema "employee.xsd" to validate "employee.xml".
"employee.xsd"
> uses a data type from "test.xsd". It imports "test.xsd" because they have
> different target namespace.
>
> 1. employee.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <employee
> xmlns="emp"
> xmlns:t="test"
> xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance'
> xsi:schemaLocation='emp employee.xsd'
> >
> <record>
> <lname>John</lname>
> <fname>Smith</fname>
> <t:department>Accounting</t:department>
> </record>
> </employee>
>
> 2. employee.xsd
> <?xml version="1.0" encoding="UTF-8"?>
> <schema
> xmlns="http://www.w3.org/1999/XMLSchema"
> xmlns:e="emp"
> xmlns:t="test"
> targetNamespace="emp"
> elementFormDefault="qualified"
> >
>
> <import
> namespace="test"
> schemaLocation="test.xsd"
> />
> <element name="employee">
> <complexType>
> <element name="record" type="e:RecordType" minOccurs="1"
> maxOccurs="unbounded"/>
> </complexType>
> </element>
>
> <complexType name="RecordType">
> <element name="lname" type="string"/>
> <element name="fname" type="string"/>
> <!--
> <element name="department" type="t:department"/>
> -->
> <element ref="t:department"/>
> </complexType>
> </schema>
>
> 3. test.xsd
> <?xml version="1.0" encoding="UTF-8"?>
> <schema
> xmlns="http://www.w3.org/1999/XMLSchema"
> targetNamespace="test"
> >
> <element name="department" type="string"/>
> <!--
> <simpleType name="department" base="string"/>
> -->
> </schema>
>
> If I use
> <element name="department" type="string"> in test.xsd
> and
> <element ref="t:department"/> in employee.xsd,
> the validation is fine.
>
> However, if I use
> <simpleType name="department" base="string"/> in test.xsd
> and
> <element name="department" type="t:department"/> in employee.xsd,
> it will give an error message:
>
> ...
> startElement: fname
> in namespace emp (fname)
> characters: Smith
> endElement: fname
>
> ignorableWhitespace: [
> ]
> Error in parsing: null
>
> The reason to use test.xsd is that I want to have a schema which has many
> datatype definition, so I can reuse them in other schemas later.
>
> Thanks,
> Zhihai
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>