Ask Sawal

Discussion Forum
Notification Icon1
Write Answer Icon
Add Question Icon

What is xsd choice?

5 Answer(s) Available
Answer # 1 #

source: Kevin Burges

Other use cases: Co-constraint Use Cases

This is is an UNCONDITIONED RELAXATION on an structure in an ELEMENT

While it's clear that the original poster's idea could be expressed in an SGML all group, it's not clear to me that the sample solutions below for SchemaPath and conditional types are correct in saying that this could be handled by the recently agreed extensions to all: we agreed to allow maxOccurs to exceed 1, and to specify interleave semantics. Did we agree to allow choices inside all-groups?

Of course, an unextended all-group could handle the substantive requirement today, either using a wrapper element:

or using a substitution group:

A check-clause solution might be:

This illustrates one danger of a powerful predicate language in check clauses: that constraints which can be expressed in a relatively simple way in the content model will instead be expressed in a less direct way in a predicate. (Of course, directness may be in the eye of the beholder. It's quite possible that the schema author might feel that the predicate approach allowed a simpler, clearer, and more direct expression of what was really desired.)

This appears to be solvable with current extension of . But, if you want to have it using co-constraints, one of the possible solutions is:

This appears to be solvable with current extension of . But, if you want to have it using co-constraints, one of the possible solutions is:

[3]
Edit
Query
Report
Bragi Thayer
Theater Manager
Answer # 2 #

Allows one and only one of the elements contained in the selected group to be present within the containing element.

The following complex type defines an element with one attribute and one and only one element from a choice of four specified elements.

For more information see the W3C XML Schema Part 1: Structures Recommendation at www.w3.org/TR/2001/REC-xmlschema-1-20010502/\#element-all.

[3]
Edit
Query
Report
Halsted Sigler
Minstrel
Answer # 3 #

Allows one and only one of the elements contained in the selected group to be present within the containing element.

[2]
Edit
Query
Report
Somnath Saxena.
WATCH CRYSTAL MOLDER
Answer # 4 #

An XML Schema Definition (XSD) contains a choice element, which allows only one of the elements within the declaration to be present within the element.

An XSD can be imported into GenRocket to automatically create Domains, Attributes, and other necessary components that represent an XML document.  The element selections for the choice element within a created Domain are not tagged automatically.

The XSD Choice Option has been created to make it easy to select (or tag) each element that should be within the declaration for Domains created during the import process.

The XSD file will need to be imported into a selected Project Version of a given Project. After the import has finished, the XSD Choice Option will be available for every Domain created from the imported XSD file.

Select a Domain within the Domains Pane in the Project Dashboard. The Domain will be displayed within the Domain Dashboard.

Next, click on the Choice Selection button within the Domain Dashboard.

Within the dialog window, users can select one or more Attributes or Children of the Domain. This will determine what elements are available for generating data within the declaration.

Click on the Search field located above the Attributes and Children columns to enter a search keyword. The result will be displayed automatically as the keyword is entered.

Click on an item within the Attributes column or the Children column to select it. Selected items will be highlighted in blue.

Note: Use a Shift/Click or CTRL/Click combination to select multiple Attributes or Children within the dialog window.

Once finished, click on the Add Choice Group button within the Choice Group Selection dialog window.

A grChoiceSelection Attribute will be created automatically and used when generating data for the Domain.

[1]
Edit
Query
Report
xgfb Tiwari
BENCH CARPENTER
Answer # 5 #

Consider the following schema, Root must contain one of the child nodes A,B,C or D.

The following code is generated for the choice.

The class RootChc represents the xs:choice, so only one of the properties in RootChc can be set.

Also note that all properties within the RootChc class are represented in their optional form (as its a choice all but one of the options should be empty).

Also see Cardinality

We can use the following code to build instances of the Root Element

The following code will read back in the files created above.

When the valid XML files ChoiceA_Output.xml and ChoiceD_Output.xml are read they produce an object model identical to the one serialized out in the code above.

However when the invalid XML file ChoiceAB_Output.xml is read an 'UnknownElement' error is raised, and additional element B is discarded.

[0]
Edit
Query
Report
Aatif gvcfd
SUPERVISOR DIE CASTING