[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Namespaces and XML Schema validation


validate my xml
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@w...
Author, Definitive XML Schema     (Prentice Hall PTR)
----------------------------------------------------- 


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.