Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > mutliple schemas/namespaces - xml validation

Reply
Thread Tools

mutliple schemas/namespaces - xml validation

 
 
Dominique
Guest
Posts: n/a
 
      06-29-2004
Hi all,

I am trying to create a schema (conf.xsd) that includes 2 other
schemas (a.xsd, b.xsd). in my xml file, I have namespaces for each of
these schemas, but my XML file doesn't validate... It's definitely a
grammar problem.
I have spent quite a bit of time playing with it, and can't find
related examples on the net, anyone has experience with this?

here are my example files:

------------------------ main.xml -------------------------

<?xml version="1.0" encoding="ISO-8859-1" ?>

<conf:CONF xmlnss="http://www.w3.org/2001/XMLSchema"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://test.com/CONF conf.xsd
http://test.com/A a.xsd
http://test.com/B b.xsd"

xmlns:conf="http://test.com/CONF"
xmlns:namea="http://test.com/A"
xmlns:nameb="http://test.com/B"
>


<namea:ROOT>
<namea:ELEM1>12345</namea:ELEM1>
<namea:ELEM2>TEST</namea:ELEM2>
</namea:ROOT>

<nameb:ROOT>
<namea:ELEMI>2020</namea:ELEMI>
<namea:ELEMJ>DATA</namea:ELEMJ>
</nameb:ROOT>

</conf:CONF>

------------------------ conf.xsd -------------------------

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test.com/CONF"
xmlns="http://test.com/CONF"
xmlns:a="http://test.com/A"
xmlns:b="http://test.com/B"
>


<xs:import namespace="http://test.com/A" schemaLocation="a.xsd" />
<xs:import namespace="http://test.com/B" schemaLocation="b.xsd" />

<xs:element name="CONF">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="a:ROOT" minOccurs="0"/>
<xs:element ref="b:ROOT" minOccurs="0"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

------------------------ a.xsd -------------------------

<?xml version="1.0" encoding="utf-8"?>

<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test.com/A"
xmlns="http://test.com/A">

<xs:element name="ROOT">
<xs:complexType>
<xs:sequence>
<xs:element name="ELEM1" type="xsositiveInteger" />
<xs:element name="ELEM2" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

------------------------ b.xsd -------------------------

<?xml version="1.0" encoding="utf-8"?>

<xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test.com/B"
xmlns="http://test.com/B">

<xs:element name="ROOT">
<xs:complexType>
<xs:sequence>
<xs:element name="ELEMI" type="xsositiveInteger" />
<xs:element name="ELEMJ" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      06-29-2004


Dominique wrote:


> here are my example files:
>
> ------------------------ main.xml -------------------------
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
>
> <conf:CONF xmlnss="http://www.w3.org/2001/XMLSchema"
> xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation="http://test.com/CONF conf.xsd
> http://test.com/A a.xsd
> http://test.com/B b.xsd"
>
> xmlns:conf="http://test.com/CONF"
> xmlns:namea="http://test.com/A"
> xmlns:nameb="http://test.com/B"
>
>
> <namea:ROOT>
> <namea:ELEM1>12345</namea:ELEM1>
> <namea:ELEM2>TEST</namea:ELEM2>
> </namea:ROOT>
>
> <nameb:ROOT>
> <namea:ELEMI>2020</namea:ELEMI>
> <namea:ELEMJ>DATA</namea:ELEMJ>
> </nameb:ROOT>
>
> </conf:CONF>
>
> ------------------------ conf.xsd -------------------------
>
> <?xml version="1.0" encoding="utf-8" ?>
> <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://test.com/CONF"
> xmlns="http://test.com/CONF"
> xmlns:a="http://test.com/A"
> xmlns:b="http://test.com/B"
>
>
> <xs:import namespace="http://test.com/A" schemaLocation="a.xsd" />
> <xs:import namespace="http://test.com/B" schemaLocation="b.xsd" />
>
> <xs:element name="CONF">
> <xs:complexType>
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element ref="a:ROOT" minOccurs="0"/>
> <xs:element ref="b:ROOT" minOccurs="0"/>
> </xs:choice>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> ------------------------ a.xsd -------------------------
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://test.com/A"
> xmlns="http://test.com/A">


add
elementFormDefault="qualified"
as an attribute to <xs:schema>

>
> <xs:element name="ROOT">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="ELEM1" type="xsositiveInteger" />
> <xs:element name="ELEM2" type="xs:string" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> </xs:schema>
>
> ------------------------ b.xsd -------------------------
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
> targetNamespace="http://test.com/B"
> xmlns="http://test.com/B">


same here
> <xs:element name="ROOT">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="ELEMI" type="xsositiveInteger" />
> <xs:element name="ELEMJ" type="xs:string" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> </xs:schema>


Then try validating again.
--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Priscilla Walmsley
Guest
Posts: n/a
 
      06-29-2004
Hi,

Your ELEM1, ELEM2, ELEMI and ELEMJ elements are locally declared.
Locally declared elements, by default, are in no namespace.

If you want them to be in the A and B namespaces, you need to add
elementFormDefault="qualified" to the xs:schema element in your A.xsd
and B.xsd schema documents.

Hope that helps,
Priscilla

-----------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema (Prentice Hall PTR)
http://www.datypic.com
-----------------------------------------------------

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Dominique
Guest
Posts: n/a
 
      06-29-2004


Thanks all for this comment it does help. But even so, when I add to the
schema elementFormDefault="qualified" (to a.xsd and b.xsd), when I try
to validate my xml file, it complains with:

Athough this XML document is well formed, it contains structure that
Data View cannot display.
A Data Table named 'ROOT: already belongs to this DataSet.

Dominique


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mutliple Drop down list boxes Ami ASP .Net 1 08-25-2006 06:07 AM
[nio] Mutliple Messages in ByteBuffer Michael B Allen Java 1 12-13-2004 06:30 AM
mutliple CPUs, threading and JVM 1.4.2 David Java 0 11-03-2004 07:29 PM
Mutliple Virtual Profiles with local AAA Andy Gray Cisco 7 10-29-2003 02:22 PM
Managing mutliple email accounts Zork Computer Support 0 09-18-2003 11:29 PM



Advertisments