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] Flexible schema definition help

[ Lists Home | Date Index | Thread Index ]

Eric,

The XForms specification is one example of a mixed-namespace document as it
uses the XML Events Schema.

The mechanics are as follows:
-  Put each namespace in a separate Schema and use xs:import to associate
the namespace with the schema file in the schema files that use those
namespaces.  
- It's also a good idea to use elementFormDefault="qualified" in your
xs:schema element and then always use the namespace prefix in the ref
attributes in xs:element and xs:attribute; that way you always are clear
which namespace the elements and attributes come from when reading your
Schema.  
- Of course, you never use the namespace prefix inside the name attribute...

There's also a nice Schema and instance validator tool available in Java
Xerces.  Just do
  java -classpath xercesImpl.jar;xercesSamples.jar xni.XMLGrammarBuilder -a
schema.xsd -i myinstance.xml
You can leave off the instance if you want and it will just error check your
Schema.

If your goal is defining a set of datatypes that can be compiled into
Java/C* then XML Schema is a good plan.  If your goal is having a
non-interactive program or a debugging tool that gives you a valid/invalid
indicator, or additionally shows locations of errors, you might consider
using Relax NG.

There's an article by Micah Dubinko on IBM's website about using Relax NG
and an XSLT transformation (with XPath expressions) to validate a
mixed-namespace document:
http://www-106.ibm.com/developerworks/library/x-xfvalid.html 
Micah usesRelax NG and an XSLT transformation that outputs additional
validation based on XPath expressions.  Of course, this XSLT/XPath approach
can be used with XML Schema as well, as it's a totally independent step.
There is also a Schema validation system called Schematron that is similar
to this XPath based approach.

Leigh.

-----Original Message-----
From: Eric Dalquist [mailto:edalquist@unicon.net] 
Sent: Tuesday, September 14, 2004 10:33 AM
To: Klotz, Leigh
Subject: Re: [xml-dev] Flexible schema definition help

I guessed that I would have to use a separate name space to allow the 
XML document to be extensible. I guess I was hoping to validate the 
document contained a specific structure without limiting the rest of the 
structure of the document.

I'm not very familiar with how name spaces in XML documents and XML 
Schema are related. Could you point me to a basic example of an XML 
document that has multiple name spaces where the XML schema is used to 
validate them?

Thank you,
    -Eric Dalquist

Klotz, Leigh wrote:

>Eric,
>In your anyType definition, you allow for any attribute and any element.
>Then, in your other definitions, you extend anyType to allow other
>attributes and other elements.
>
>That's not going to work, because the base anyType already allows whatever
>attributes and elements you were going to add anyway.
>So, you won't be getting any validation.
>
>For a working example of allowing any foreign attributes, see the XForms
1.0
>Schema in http://www.w3.org/TR/xforms -- I think Micah Dubinko was
>responsible for the construction of the attributeGroup that does this.  A
>key point is to do  <xsd:anyAttribute namespace="##other"/>  -- that will
>restrict the attributes in your namespace to the listed set, but allow any
>other attributes from other namespaces.  Of course, in your extensions you
>won't be able to then specify which foreign attributes to allow as you've
>allowed them all, but at least you get validation of your namespace's
>attributes.  You might find using attributeGroups easier than using type
>extension; if your types really aren't related, but just all happen to
allow
>foreign attributes, it's much clearer what's going on.
>
>There's a similar thing to do with xsd:any for elements, where you will
need
>to specify namespace="##other".  But watch out -- ordering matters here.
>Attributes, fortunately, are unordered, but with sequences of child
>elements, you will run into the XML Schema deficiencies in the area of
>unordered choices / ordered sequences -- some things you might want to
>express aren'f possible in XML Schema without resorting to a combinatorial
>listing, and that's really painful.  Read up on sequence, choice, and
>minOccurs and maxOccurs.  See the XForms Schema for some examples, or look
>at Zvon.org for a discussion of some of those issues.
>
>-----Original Message-----
>From: Eric Dalquist [mailto:edalquist@unicon.net] 
>Sent: Monday, September 13, 2004 11:06 AM
>To: xml-dev@lists.xml.org
>Subject: [xml-dev] Flexible schema definition help
>
>I'd like to create an XML schema that will ensure a certain simple 
>structure exists in the document but allows for any other elements or 
>attributes.
>
>I've attached an invalid XSD which is close to what I want. If I remove 
>the anyType complex type and it's references the XSD is then valid and 
>will validate my XML document correctly but there is no allowance for 
>any elements or attributes beyond what is defined in the XSD. I'd rather 
>have the XSD define a set of required elements and their structure but 
>allow for any other elements and attributes in the document. I hope that 
>description make sence and any help is very much appreciated.
>
>Thank you,
>    Eric Dalquist
>
>PS: The error Oxygen is giving me with the attached XSD is:
>E cos-nonambig: WC[##any] and "":folder (or elements from their 
>substitution group) violate "Unique Particle Attribution". During 
>validation against this schema, ambiguity would be created for those two 
>particles.    layout.xsd    24:39
>
>  
>




 

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

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