mutliple schemas/namespaces - xml validation

Discussion in 'XML' started by Dominique, Jun 29, 2004.

  1. Dominique

    Dominique Guest

    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>
    Dominique, Jun 29, 2004
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Jun 29, 2004
    #2
    1. Advertising

  3. 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!
    Priscilla Walmsley, Jun 29, 2004
    #3
  4. Dominique

    Dominique Guest

    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!
    Dominique, Jun 29, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Divya Alice George

    A query regarding validation of xml-schemas

    Divya Alice George, Oct 10, 2003, in forum: XML
    Replies:
    1
    Views:
    360
    Martin Boehm
    Oct 10, 2003
  2. Tony Prichard
    Replies:
    0
    Views:
    718
    Tony Prichard
    Dec 12, 2003
  3. Replies:
    6
    Views:
    428
  4. chuck

    Schemas & Namespaces

    chuck, Dec 30, 2007, in forum: XML
    Replies:
    1
    Views:
    397
    Martin Honnen
    Dec 30, 2007
  5. Replies:
    3
    Views:
    494
Loading...

Share This Page