Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Required and optional elements

Reply
Thread Tools

Required and optional elements

 
 
Spaulding
Guest
Posts: n/a
 
      08-14-2009
I have an xsd specified as such:

<?xml version="1.0" encoding="UTF-8" ?>
- <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
- <xs:element name="REQUEST">
- <xs:complexType>
- <xs:all>
<xs:element name="FIELD1" type="xs:string" />
<xs:element name="FIELD2" type="xs:string" />
<xs:element name="FIELD3" type="xs:string" minOccurs="0" />
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

I was thinking that this would allow FIELD3 to be optional and that
FIELD1 and FIELD2 are required. I use JAXB to unmarshal from an XML
doc that does not have FIELD1, and it works. i would have expected an
exception. Am i doing this correctly?
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      08-15-2009
Spaulding wrote:
> I have an xsd specified as such:
>
> <?xml version="1.0" encoding="UTF-8" ?>
> - <xs:schema xmlnss="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> - <xs:element name="REQUEST">
> - <xs:complexType>
> - <xs:all>
> <xs:element name="FIELD1" type="xs:string" />
> <xs:element name="FIELD2" type="xs:string" />
> <xs:element name="FIELD3" type="xs:string" minOccurs="0" />
> </xs:all>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> I was thinking that this would allow FIELD3 to be optional and that
> FIELD1 and FIELD2 are required. I use JAXB to unmarshal from an XML
> doc that does not have FIELD1, and it works. i would have expected an
> exception. Am i doing this correctly?


In terms of the schema language one FIELD1 child element of the REQUEST
element is required and a validating parser should flag that as an error
if there is no such element.
Whether JAXB validates I don't know. You might want to ask in a Java group.

--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
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
W3C Schema for required and optional elements Philipp XML 2 04-11-2008 09:17 AM
XSD: complexType with mandatory and optional elements in arbitraryorder? Thomas Wittek XML 4 09-13-2007 12:04 PM
Use of required and optional LJ XML 3 02-09-2006 10:54 AM
XSD question: Allowing one required element and many optional elements. MENTAT XML 8 04-04-2005 04:16 AM
Required & Optional software and utilities for creating html, Javascript etc Sean HTML 8 02-15-2004 11:24 PM



Advertisments