By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

validating xml doc with multiple schemas using wildcards

P: n/a
I am trying to validate a xml file with two schema files cust.xsd and
cust1.xsd. The schema file cust.xsd allows addition of elements from
another schema cust1.xsd by using xs:any wildcard.

cust.xsd - schema
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="urn:xmlns:sysapex-com:customer"
elementFormDefault="qualified"
xmlns="urn:xmlns:sysapex-com:customer"
xmlns:mstns="urn:xmlns:sysapex-com:customer"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="FirstName" type="xs:string" />
<xs:element name="LastName" type="xs:string" />

<xs:any namespace="##targetNamespace" processContents="strict"
minOccurs="0" maxOccurs="unbounded" />
<xs:any namespace="##any" processContents="lax" minOccurs="0"
maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute name="customerID" type="xs:integer" />
<xs:anyAttribute namespace="##any" processContents="skip" />
</xs:complexType>
</xs:element>
</xs:schema>

cust1.xsd - schema
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema
targetNamespace="urn:xmlns:sysapex-com:address"
elementFormDefault="qualified"
xmlns="urn:xmlns:sysapex-com:address"
xmlns:mstns="urn:xmlns:sysapex-com:address"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Customer">
<xs:complexType>
<xs:sequence>
<xs:element name="Address" type="xs:string" />
<xs:element name="City" type="xs:string" />
<xs:element name="State" type="xs:string" />
<xs:element name="Zip" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

cust.xml - This has to be validated against both cust.xsd and
cust1.xsd

<cust:Customer customerID="12345" numPurchases="17"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cust="urn:xmlns:sysapex-com:customer"
xsi:noNamespaceSchemaLocation="file://c:/per/Schemas_nn/new1/cust.xsd"

xsi:schemaLocation="urn:xmlns:sysapex-com:address
file://c:/per/Schemas_nn/new1/cust1.xsd"
xmlns:addr="urn:xmlns:sysapex-com:address">
<cust:FirstName >Dare</cust:FirstName>
<cust:LastName >Obasanjo</cust:LastName>
<cust:PhoneNumber >425-555-1234</cust:PhoneNumber>

<addr:Address>2001 Beagle Drive</addr:Address>
<addr:City>Redmond</addr:City>
<addr:State>WA</addr:State>
<addr:Zip>98052</addr:Zip>

</cust:Customer>

Both schemas validate OK. However when I validate cust.xml with the
schemas, I get the following error in MSXML parser using VS Studio
2003. "Although this XML document is well-formed it contains a
structure that data view cannot display. The
urn:xmlns:syspaex-com:address:Adress element is not declared".
I have suspicion that the xsi:schemaLocation syntax in my cust.xml
referring to the path location of my schema file on the c drive as
file://c:/per/Schemas_nn/new1/cust1.xsd is causing the error. I know
the cust1.xsd is in the right location.

I don't know any better.

Please advise.

Jan 20 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
vhrao wrote:
cust.xsd - schema
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="urn:xmlns:sysapex-com:customer"
elementFormDefault="qualified"
xmlns="urn:xmlns:sysapex-com:customer"
xmlns:mstns="urn:xmlns:sysapex-com:customer"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
So this schema defines elements in the namespace
urn:xmlns:sysapex-com:customer.
cust1.xsd - schema
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema
targetNamespace="urn:xmlns:sysapex-com:address"
elementFormDefault="qualified"
xmlns="urn:xmlns:sysapex-com:address"
xmlns:mstns="urn:xmlns:sysapex-com:address"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
The second schema defines elements in the namespace
urn:xmlns:sysapex-com:address.

<cust:Customer customerID="12345" numPurchases="17"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cust="urn:xmlns:sysapex-com:customer"
xsi:noNamespaceSchemaLocation="file://c:/per/Schemas_nn/new1/cust.xsd"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^

Why are you using noNamespaceSchemaLocation although cust.xsd defines
elements in a namespace? You need to provide the locations of the
schemas with schemaLocation, not with noNamespaceSchemaLocation e.g.

xsi:schemaLocation="urn:xmlns:sysapex-com:address
file:///c:/per/Schemas_nn/new1/cust1.xsd urn:xmlns:sysapex-com:customer
file:///c:/per/Schemas_nn/new1/cust.xsd"
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 21 '07 #2

P: n/a
Thank you. It took care of the original error I had. But a new error
comes up.
Here is the revised cust.xml and error message.

cust.xml
<?xml version="1.0" encoding="utf-8" ?>
<cust:Customer customerID="12345" numPurchases="17"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cust="urn:xmlns:sysapex-com:customer"
xmlns:addr="urn:xmlns:sysapex-com:address"
xsi:schemaLocation="urn:xmlns:sysapex-com:customer
file:///f:/per/pats/new1/cust.xsd
urn:xmlns:sysapex-com:address
file:///f:/per/pats/new1/cust1.xsd" >

<cust:FirstName >Dare</cust:FirstName>
<cust:LastName >Obasanjo</cust:LastName>
<addr:Address>2001 Beagle Drive</addr:Address>
<addr:City>Redmond</addr:City>
<addr:State>WA</addr:State>
<addr:Zip>98052</addr:Zip>
</cust:Customer>

Error Message:
The given name Customer matches at least two names in the collection
object with different namespaces.

How can I fix this problem.

Thanks for your help!

Martin Honnen wrote:
vhrao wrote:
cust.xsd - schema
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="urn:xmlns:sysapex-com:customer"
elementFormDefault="qualified"
xmlns="urn:xmlns:sysapex-com:customer"
xmlns:mstns="urn:xmlns:sysapex-com:customer"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

So this schema defines elements in the namespace
urn:xmlns:sysapex-com:customer.
cust1.xsd - schema
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema
targetNamespace="urn:xmlns:sysapex-com:address"
elementFormDefault="qualified"
xmlns="urn:xmlns:sysapex-com:address"
xmlns:mstns="urn:xmlns:sysapex-com:address"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

The second schema defines elements in the namespace
urn:xmlns:sysapex-com:address.

<cust:Customer customerID="12345" numPurchases="17"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cust="urn:xmlns:sysapex-com:customer"
xsi:noNamespaceSchemaLocation="file://c:/per/Schemas_nn/new1/cust.xsd"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^

Why are you using noNamespaceSchemaLocation although cust.xsd defines
elements in a namespace? You need to provide the locations of the
schemas with schemaLocation, not with noNamespaceSchemaLocation e.g.

xsi:schemaLocation="urn:xmlns:sysapex-com:address
file:///c:/per/Schemas_nn/new1/cust1.xsd urn:xmlns:sysapex-com:customer
file:///c:/per/Schemas_nn/new1/cust.xsd"
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 21 '07 #3

P: n/a
vhrao wrote:
But a new error
comes up.
Here is the revised cust.xml and error message.

cust.xml
<?xml version="1.0" encoding="utf-8" ?>
<cust:Customer customerID="12345" numPurchases="17"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cust="urn:xmlns:sysapex-com:customer"
xmlns:addr="urn:xmlns:sysapex-com:address"
xsi:schemaLocation="urn:xmlns:sysapex-com:customer
file:///f:/per/pats/new1/cust.xsd
urn:xmlns:sysapex-com:address
file:///f:/per/pats/new1/cust1.xsd" >

<cust:FirstName >Dare</cust:FirstName>
<cust:LastName >Obasanjo</cust:LastName>
<addr:Address>2001 Beagle Drive</addr:Address>
<addr:City>Redmond</addr:City>
<addr:State>WA</addr:State>
<addr:Zip>98052</addr:Zip>
</cust:Customer>

Error Message:
The given name Customer matches at least two names in the collection
object with different namespaces.
What exactly do you want to achieve? Do you know about xs:import and
then xs:element ref to import and reference elements from a different
namespace? I don't think you need xs:any to use elements from different
namespaces.

As for the error message, which tool exactly do you use for validation
that gives that error message?


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jan 22 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.