Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Schema: Validate child to one of a choice of element types?

Status
Not open for further replies.

jeff00seattle

Programmer
Jan 6, 2009
1
US
Hi am a relative newbie in XML, so forgive me.

I am tring to put together a validation script using XML Schema, but I cannot determine how to define that the child of an element can have a choice of elements but can only have one.

For example, my XML contents are as follows (if it is total wrong, let me know):

<configuration>
<applicationSettings>
<setting name="Market">
<value>
<string>English (United States)</string>
</value>
</setting>
<setting name="BingSearchEnabled">
<value>
<boolean>True</boolean>
</value>
</setting>
<setting name="MaximumResultsCount">
<value>
<integer>10</integer>
</value>
</setting>
<setting name="FileTypeFilter">
<value>
<stringarray>
<string>js</string>
<string>gif</string>
<string>jpg</string>
</stringarray>
</value>
</setting>
</applicationSettings>
</configuration>

I am trying to create a validation XML Schema that states that is OK for <value> to be only ONE of <string> or <boolean> or <integer> or <stringarray>.

How would I do this?

Thanks

Jeff in Seattle

 
[0] It is the use of xs:choice element. Like this.

[1] Define three global xs:element with name="string", name="boolean", name="boolean" and name="stringarray".

[2] The xs:element name="value" would appear like this.
[tt]
<xs:element name="value">
<xs:complexType>
<xs:choice>
<xs:element ref="string" />
<xs:element ref="boolean" />
<xs:element ref="integer" />
<xs:element ref="stringarray" />
</xs:choice>
</xs:complexType>
</xs:element>
[/tt]
[3] If you want some opinion on the design: the major observation is that you try to take away the functionality of schema data type and/or certain functionality which is proper to the application level such as determing an array of string. It makes the xml document appear clumsy --- put in something proper to application level, --- and overweight --- duplicating something which should appear in the w3c schema language itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top