473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

mutliple schemas/namespaces - xml validation

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>
Jul 20 '05 #1
3 1569


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 <xs:schema>

<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.
--

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

Jul 20 '05 #2
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!
Jul 20 '05 #3


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!
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AnonymousOne | last post by:
Greetings all, I'm getting a little frustrated trying to figure this out. When creating an XML schema file, the default extention is XSD. How is it that schemas can be accessed using only their...
6
by: inerte | last post by:
Hello all! I need to build an XML file structure so a client can import data to one of our systems. Totally new to XML, I learned about Namespaces and DTD, and built a nice spec using them. Now...
0
by: Murali Inguva | last post by:
I have an xml. It was generated from different schemas. I want to know the namespaces and the schemas that are reffered in that XML. So that i can add the Namespaces and Schemas to the Namespace...
4
by: anonymous | last post by:
When I use the schema collection to apply many schemas to one XML instance document, I get an error if I do not qualify every element with the appropriate namespace. Both the W3C site and this...
1
by: SideByEach | last post by:
I have a schema that references a child schema via a "xs:import" node. In that child schema it references several other grand children schemas. Is there an object in the VS 2K5 suite which will...
0
by: wolf_y | last post by:
I'm a newbie to XML and primarily program in SAS, so even though I've consulted documentation, I can't translate into language I understand. I hope I can explain the problem clearly. The project...
3
by: vhrao | last post by:
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. ...
5
by: Arndt Jonasson | last post by:
I have a schema defining the input of a particular application. Let's refer to the namespace for my schema by the prefix "my:". Now the need has arisen to annotate such input documents with foreign...
5
by: carlpayne1984 | last post by:
Hi all, I'm fairly new to XML, however already I have studied myself stupid without being able to solve this problem. Basically, I have an XML file/Schema about a CD catalog that I've created that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.