Domanda

I would like to define a schema for the following XML construct:

<object>System<S/>Design<S/>Part</object>

Where element "object" should be filled with a list of content as enumeration values (System, Design, Part), which potentially may contain spaces - that's why I cannot go with space-separated list. As a separator I use element.

But all the xsd elements that can parent simple content won't parent elements and vice verso. Is there any way to work around it?

È stato utile?

Soluzione

The answer is no -- unless you move to XSD 1.1 and use assertions.

In XSD 1.0 there is no way of constraining the text that appears in the text nodes of a mixed-content element. This is because you aren't using XML the way it was designed to be used (you will also have problems with XPath/XSLT on this kind of structure).

In XSD 1.1 you could have an assertion on the declaration of "object" such as

test="every $s in text() satisfies $s = ('System', 'Design', 'Part')

Altri suggerimenti

The easiest way to work around it is to use a slightly different XML structure, for example:

<object>
  <item>System</item>
  <item>Design</item>
  <item>Part</item>
</object>

This allows the individual item values to contain spaces, as desired, and makes it easy to constrain the legal values with an enumerated list in XSD. It also exhibits the structure of the data a bit more directly: you are describing the object using a list of something-or-others (which I have called item because I have no idea what they actually are -- give them a more informative name in your XML!). Each of the something-or-others in the list is a distinct object in your conceptual model of the problem, and life is better both for you and for your XML tools if each is represented by a distinct XML object (here, a distinct instance of element type item).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top