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] help - Writing schema

[ Lists Home | Date Index | Thread Index ]

Hi Pradeep,

> I need to write XML schema for the following XML

It's best to direct questions about XML Schema to xmlschema-dev@w3.org
rather than XML-Dev.

>    <Attribute>
>          <AttributeName>
>                   <id />
>          </AttributeName>
>          <TagName>
>            <emp/>
>          </TagName>
>    </Attribute>
>
> The element under AttributeName and TagName is unknown but it should
> contain only one element.
> The tags AttributeName and TagName  should not be empty.

To indicate an 'unknown' element, you need to use the wildcard xs:any.
xs:any takes minOccurs and maxOccurs attributes to indicate how many
unknown elements should occur; in your case, you just want one and
only one unknown element, so you can leave those to default (they both
default to 1).

xs:any also takes a namespace attribute to indicate which namespaces
the element(s) can belong to. If you want to allow elements in any
namespace, you can use the keyword '##any'; again, that's the default,
so you don't have to add a namespace attribute to allow any element in
any namespace.

Finally, xs:any takes a processContents attribute to indicate what
should be done about validating the 'unknown' element. Probably in
this case you should just skip them or use lax validation (whereby
they're validated if they're declared, and not if they aren't). The
default is 'strict' (it's an error if the elements aren't declared),
so probably you should change that.

So a complex type that allows a single unknown element would be:

<xs:complexType name="unknownElement">
  <xs:sequence>
    <xs:any processContents="lax" />
  </xs:sequence>
</xs:complexType>

The Attribute element contains an AttributeName element followed by a
TagName element, both of which are of the type 'unknownElement':

<xs:element name="Attribute">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="AttributeName" type="unknownElement" />
      <xs:element name="TagName" type="unknownElement" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/





 

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

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