• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How can I fix element so it can obtain default values if omitted

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im trying to create an element "refresh" which contains both a "time" & "timeType" element. If these elements are not included in .xml they will be replaced by the default values. However Im not sure what to place in ********* because I cant place <xs:sequence> because it will throw an error if I skip either of the "time" or "timeType" elements. Sorry i'm new to schemas how would I go about getting it to work?

Thank you all for your time

.........
<xs:element name="time" type="xs ositiveInteger" default="1"/>
<xs:element name="timeType" default="weeks">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="days"/>
<xs:enumeration value="weeks"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="refresh">
<xs:complexType>
************
<xs:element ref="time"/>
<xs:element ref="timeType"/>
*************
</xs:complexType>
</xs:element>
 
author
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can still use sequence if you make the elements in the sequence optional. Or you could use a sequence of choice. Depending on exactly what input variations you need to accept, this may be all you need.
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried both

<xs:complexType>
<xs:sequence>
<xs:element ref="time"/>
<xs:element ref="timeType"/>
</xs:sequence>
</xs:complexType>

which results in an error if I omit one or both of the elements from my .xml.

And

<xs:complexType>
<xs:choice>
<xs:element ref="time"/>
<xs:element ref="timeType"/>
</xs:choice>
</xs:complexType>

which throws no error if either the "time" or "timeType" is included but fails to add the default value if one is omitted.
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by john mattucci:
<xs:complexType>
<xs:sequence>
<xs:element ref="time"/>
<xs:element ref="timeType"/>
</xs:sequence>
</xs:complexType>

which results in an error if I omit one or both of the elements from my .xml.

You can get rid of this validation error by using the minOccurs and maxOccurs attributes like this:
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This does not solve my issue. If I include minOccurs="0" maxOccurs="1" and the element is not included in the .xml the default value is never selected.
I have the following

<xs:element name="time" type="xs ositiveInteger" default="1"/>
<xs:element name="timeType" default="weeks">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="days"/>
<xs:enumeration value="weeks"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

and if the elements are not included I wish to have the default inserted
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic