OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Namespaces and XML Schema validation

[ Lists Home | Date Index | Thread Index ]

Hi Peter,

Yes, you can only have one schema document per namespace, so you will be
required to have a.xsd, b.xsd, etc.

> PROBLEM 1
> 
> 
> Example document:
> <?xml version="1.0">
> <a1 xsi:noNamespaceSchemaLocation="a.xsd"
>     xmlns:b="http:\\example.org\b\"
>     xmlns:c="http:\\example.org\c\">
>   <b:b1>This is element B1 from namespace B</b:b1>
>   <a2>This is the second element from schema a</a2>
>   <c:c1>This element is from namespace c</c:c1>
> </a1>

a.xsd would look something like this:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
            xmlns:b="http:\\example.org\b\"
            xmlns:c="http:\\example.org\c\">
<xsd:import namespace="http:\\example.org\b\" schemaLocation="b.xsd"/>
<xsd:import namespace="http:\\example.org\c\" schemaLocation="c.xsd"/>

<xsd:element name="a1" type="a1Type"/>
<xsd:complexType name="a1Type">
  <xsd:sequence>
    <xsd:element ref="b:b1"/>
    <xsd:element name="a2" type="xsd:string"/>
    <xsd:element ref="c:c1"/>
  </xsd:sequence>
</xsd:complexType>

and b.xsd and c.xsd would declare the b1 and c1 elements, globally.

> PROBLEM 2
> 
> Can I nest the namespaces in such an XML document, so that 
> elements from one
> namespace contains elements from other namespaces, and still 
> validate my XML
> document against one or several XML Schemas?

Yes, in this case you could have a.xsd import the b namespace, and b.xsd
import the c namespace.

> PROBLEM 3
> 
> Can elements from one namespace occur several times in a 
> hierarchy where
> elements from other namespaces occur as fathers, i.e. true 
> nesting, and
> still validate my XML document against one or several XML 
> Schemas? And how
> would the XML Schemas that defines those namespaces look like?

Yes, in that case a.xsd could import the b namespace, and b.xsd could
import the a namespace.  Same thing with b and c. (there is no rule that
says "circular imports" are not allowed; in fact, they are necessary.)


> PROBLEM 4
> 
> Can I, using the example from my problem 3, enforce (through 
> validation)
> that instances are created with exactly those elements, 
> occuring just one
> time each, with one single XML Schema?

I assume you mean one single schema _document_ (since an XML Schema can
be made up of more than one document, as we have seen above).  No, you
can't - the best you could do is put wildcards where you want the
elements from other namespaces to go.  Wildcards will allow you to
constrain the namespace and number of elements that appear, but will not
validate those elements without a schema document for that namespace.


The examples from my XML Schema book are online at:

http://www.datypic.com/books/DefXMLSchema/Examples.html

I can't guarantee they're the exact same structure as your examples, but
they might help.

Hope that helps!
Priscilla

-----------------------------------------------------
Priscilla Walmsley             priscilla@walmsley.com
Author, Definitive XML Schema     (Prentice Hall PTR)
----------------------------------------------------- 





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS