Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Xml schema element with attribute and optional simple content?

Reply
Thread Tools

Xml schema element with attribute and optional simple content?

 
 
Gazza
Guest
Posts: n/a
 
      12-05-2005
I want to define an element type which has child elements which will
have an attribute, but I want the presence of content for these child
elements (which will be simple when present) to be optional. My type is
defined as such

<xsd:complexType name="DistanceStructure">
<xsd:sequence>
<xsd:element name="Value">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:decimal">
<xsd:attribute name="Comment" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="Unit">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="esdalcommistanceUnitType">
<xsd:attribute name="Comment" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
This definition allows validation of the following when it appears in
my instance document


<StructureLength>
<Value Comment="STRUCTURE LENGTH COMMENT">1.1</Value>
<Unit Comment="STRUCTURE LENGTH COMMENT">metre</Unit>
</StructureLength>

But the following does not validate

<StructureLength>
<Value Comment="STRUCTURE LENGTH COMMENT"/>
<Unit Comment="STRUCTURE LENGTH COMMENT"/>
</StructureLength>



I need both to be valid possiblilies in my instance document. What can
I do?

 
Reply With Quote
 
 
 
 
Henry S. Thompson
Guest
Posts: n/a
 
      12-05-2005
Gazza writes:

> <xsd:element name="Value">
> <xsd:complexType>
> <xsd:simpleContent>
> <xsd:extension base="xsd:decimal">
> <xsd:attribute name="Comment" type="xsd:string"/>
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>
> </xsd:element>


> <Value Comment="STRUCTURE LENGTH COMMENT">1.1</Value>


> <Value Comment="STRUCTURE LENGTH COMMENT"/>


The empty string is not a valid xs:decimal, so you should define a union
of the empty string (xs:string restricted to length 0, or xs:string
restricted to an enumeration of only "") and xs:decimal, and use that
instead of xs:decimal itself.

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: http://www.velocityreviews.com/forums/(E-Mail Removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 
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
How to write an XML schema that specifies an optional namespace inthe XML docs? Jethrie-JDuprez in the news XML 4 04-26-2009 08:35 PM
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
In xml schema, what's the difference between attribute "final" and "block" in element "element" tankbattle XML 1 07-21-2006 07:51 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
Simple Schema Element/Attribute/Restriction problem Andy Howden XML 0 10-20-2003 08:01 AM



Advertisments