Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > How to define an empty or type-safe element in XSD

Reply
Thread Tools

How to define an empty or type-safe element in XSD

 
 
SW
Guest
Posts: n/a
 
      10-07-2003
Hello,

Can anyone show me how to define in an XSD schema that an element in
an XML document can either contain no text, or if it does contain text
that the text has to be of a specific type.

For example, I would like both the following to be valid, where any
text present should equate to an integer, but an empty element is also
valid:

<mytest></mytest>

or

<mytest>123</mytest>

Many thanks in advance
 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      10-11-2003
In article <(E-Mail Removed) >,
SW <(E-Mail Removed)> wrote:

% For example, I would like both the following to be valid, where any
% text present should equate to an integer, but an empty element is also
% valid:
%
% <mytest></mytest>
%
% or
%
% <mytest>123</mytest>

I was waiting to see if someone who's more of a schema person than me
answered, but I'll stoke the fire by suggesting you use a union.

<xs:element name='mytest'>
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:integer"/>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
--

Patrick TJ McPhee
East York Canada
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
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
XSD restriction of nesting an element within another element with aspecific attribute value? PeteOlcott XML 1 02-05-2009 06:39 AM
Altova Mapforce - xml 2 xml map: empty elements output although input element is not empty Lukas XML 3 11-10-2005 02:25 PM
XSD - element, element value and attribute ? Matthet XML 2 09-24-2003 04:10 PM
empty/non-empty element John XML 1 07-16-2003 10:23 AM
Re: Newb Q: How define element in XML Schema which forces it to be empty? gabriel XML 1 06-25-2003 01:53 PM



Advertisments