Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Schema element contain text or elements, but not both.

Reply
Thread Tools

Schema element contain text or elements, but not both.

 
 
Alan Johnson
Guest
Posts: n/a
 
      07-24-2007
I am trying to specify that an element may contain simple content (an
integer), or complex content (a sequence of two other elements), but not
both. The listMember element in the following XML fragment demonstrates
what I'm trying to accomplish:

<list>
<listMember>
<ident>1</ident>
<name>Name1</name>
</listMember>
<listMember>
<ident>2</ident>
<name>Name2</name>
</listMember>
</list>

<list>
<listMember>1</listMember>
<listMember>2</listMember>
</list>

I cannot, however, figure out any way to create such a restriction. The
following (invalid) schema sort of shows what it is I would like, but of
course it is invalid because listMember is redeclared.

<?xml version="1.0"?>

<xs:schema
xmlnss="http://www.w3.org/2001/XMLSchema"
xmlns="exampleSchema"
targetNamespace="exampleSchema"
elementFormDefault="qualified">

<xs:element name="list" type="List"/>

<xs:complexType name="List">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name="listMember" type="ListMember"/>
<xs:element name="listMember" type="xs:integer"/>
</xs:choice>
</xs:sequence>
</xs:complexType>

<xs:complexType name="ListMember">
<xs:sequence>
<xs:element name="indent" type="xs:integer"/>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>

</xs:schema>

Do any of you know how I could accomplish this?

--
Alan Johnson
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RCR: String#contain? and Array#contain? Roger Pack Ruby 3 09-28-2010 04:13 PM
Does string contain A, and if so, does a section of string contain B Jason Carlton Javascript 11 12-08-2009 06:07 PM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
Including element from one schema namespace in another schema namespace mflll@wiu.edu XML 1 07-20-2006 06:48 AM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM



Advertisments