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 mmfive <mm...@netspace.net.au> on 2003/04/25 08:30:29 UTC
Using Xerces-J 2.4.0 with Namespaces in Schema
Hi All,
I'm dom.Writer from the DOM samples and I'm trouble with Namespaces
in a Schema. For example if this is my XML file:
<?xml version = "1.0" ?>
<cust:Customer xmlns:cust = "http://www.example.org/Customers"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "Customers.xsd">
<FirstName>Ray</FirstName>
<MiddleInitial>G</MiddleInitial>
<cust:LastName>Bayliss</cust:LastName>
</cust:Customer>
This is my Schema called Customers.xsd
<?xml version = "1.0" ?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
targetNamespace = "http://www.example.org/Customers"
xmlns = "http://www.example.org/Customers">
<xs:element name = "Customer" >
<xs:complexType>
<xs:sequence>
<xs:element name = "FirstName" type = "xs:string" />
<xs:element name = "MiddleInitial" type = "xs:string" />
<xs:element ref = "LastName" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name = "LastName" type = "xs:string" />
</xs:schema>
Using the dom.Writer with this command -v for validation -s for Schema
validation
java dom.Writer -v -s CustomerA.xml > CustomerA-result.xml
I get the following errors:
[Warning] CustomerA.xml:4:53: SchemaLocation: schemaLocation value =
'Customers.xsd' must have even number of URIs.
[Error] CustomerA.xml:4:53: cvc-elt.1: Cannot find the declaration of
element 'cust:Customer'.
The Questions I have are:
1) It cannot find the Customers.xsd the corresponding Schema for the file -
why?
2) It cannot find the Customers.xsd file - why?
3) How do I get multiple namespaces working for the Schema and the XML file?
Thnaks Marco.
Re: Using Xerces-J 2.4.0 with Namespaces in Schema
Posted by "K. Venugopal" <k....@sun.com>.
Hi Marco ,
schemaLocation needs namespace name and location of the schema , so you
need to modify your xml file as
xsi:schemaLocation = "http://www.example.org/Customers Customers.xsd">
An example from net is below:
xsi:schemaLocation=
"http://contoso.com/People
http://contoso.com/schemas/people.xsd
http://contoso.com/schemas/Vehicles
http://contoso.com/schemas/vehicles.xsd
http://contoso.com/schemas/People
http://contoso.com/schemas/people.xsd">
Regards
venu
mmfive wrote:
> Hi All,
>
> I'm dom.Writer from the DOM samples and I'm trouble with
> Namespaces in a Schema. For example if this is my XML file:
>
>
>
> <?xml version = "1.0" ?>
>
> <cust:Customer xmlns:cust = "http://www.example.org/Customers"
>
> xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation = "Customers.xsd">
>
> <FirstName>Ray</FirstName>
>
> <MiddleInitial>G</MiddleInitial>
>
> <cust:LastName>Bayliss</cust:LastName>
>
> </cust:Customer>
>
>
>
> This is my Schema called Customers.xsd
>
>
>
> <?xml version = "1.0" ?>
>
> <xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
>
> targetNamespace = "http://www.example.org/Customers"
>
> xmlns = "http://www.example.org/Customers">
>
>
>
> <xs:element name = "Customer" >
>
> <xs:complexType>
>
> <xs:sequence>
>
> <xs:element name = "FirstName" type = "xs:string" />
>
> <xs:element name = "MiddleInitial" type = "xs:string" />
>
> <xs:element ref = "LastName" />
>
> </xs:sequence>
>
> </xs:complexType>
>
> </xs:element>
>
>
>
> <xs:element name = "LastName" type = "xs:string" />
>
>
>
> </xs:schema>
>
>
>
> Using the dom.Writer with this command -v for validation -s for Schema
> validation
>
> java dom.Writer -v -s CustomerA.xml > CustomerA-result.xml
>
>
>
> I get the following errors:
>
>
>
> [Warning] CustomerA.xml:4:53: SchemaLocation: schemaLocation value =
> 'Customers.xsd' must have even number of URIs.
>
> [Error] CustomerA.xml:4:53: cvc-elt.1: Cannot find the declaration of
> element 'cust:Customer'.
>
>
>
> The Questions I have are:
>
> 1) It cannot find the Customers.xsd the corresponding Schema for the
> file - why?
>
>
>
> 2) It cannot find the Customers.xsd file - why?
>
>
>
> 3) How do I get multiple namespaces working for the Schema and the XML
> file?
>
>
>
>
>
> Thnaks Marco.
>