mutliple schemas/namespaces - xml validation

D

Dominique

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 xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="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 xmlns:xs="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 xmlns:xs="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="xs:positiveInteger" />
<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 xmlns:xs="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="xs:positiveInteger" />
<xs:element name="ELEMJ" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>
 
M

Martin Honnen

Dominique wrote:

here are my example files:

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

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

<conf:CONF xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="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 xmlns:xs="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 xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test.com/A"
xmlns="http://test.com/A">

add
elementFormDefault="qualified"
as an attribute to said:
<xs:element name="ROOT">
<xs:complexType>
<xs:sequence>
<xs:element name="ELEM1" type="xs:positiveInteger" />
<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 xmlns:xs="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="xs:positiveInteger" />
<xs:element name="ELEMJ" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Then try validating again.
 
P

Priscilla Walmsley

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
 
D

Dominique

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top