1

I am trying to adjust my xsd that it allows as child one element with the name processName and otherwise any element.
For that I prepared a small complexType:

<complexType name="configType">
<!--    <xsd:choice> -->
    <sequence>
        <element name="processName" type="string" maxOccurs="1"/>
        <xsd:any minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
<!--    </xsd:choice> -->
</complexType>

My problem is that it doesn't prevent any other occurrence of the processName:

<config>
    <process:processName></process:processName>
    <test></test>
    <test2></test2>
    <process:processName></process:processName>
</config>

I have tried to use choice but it ends with the validation error

processName and WC[##any] (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles.

The rule isn't active any more in XSD v 1.1, but all my XML files are version 1.0. But I think it isn't possible to check with newer schema version an older file.

This particular example no longer violates the Unique Particle Attribute constraint in XML Schema version 1.1, which disambiguates it by saying that when an element matches both an element particle and a wildcard, the element particle wins. However, the UPA constraint itself remains in version 1.1.

Is it possible to enforce only one time occurence of processName?
Thanks for any hints.

EDIT:
With some hints from ColdFusion I was able to create a piece of XSD1.1 schema which allows the ambigous declaration:

<sequence>
    <element name="processName" type="string" minOccurs="0" maxOccurs="1"/>
    <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</sequence>

Now it is possible to have multiple times processName.

CSchulz
  • 10,882
  • 11
  • 60
  • 114

2 Answers2

1

You wrote:

The rule isn't active any more in XSD v 1.1, but all my XML files are version 1.0. But I think it isn't possible to check with newer schema version an older file.

XML version has nothing to do with XML Schema version! (see also: What XML version to use?)

XML 1.0 is the mainstream now and XML schemas v1.1 are equally for it.

If your v1.1 schema works well for you, then just use it!

As to how to express that your schema constrain in XSD 1.0 is unclear to me too. Probably, there is no way. (Otherwise, they wouldn't ease in XSD v1.1 that UPA restriction).

The <xs:any> can be constrained only for specific namespaces (if those 'other' elements were from a different namespace than <processName>, then that would be possible). Otherwise, I think, the only way is to specify which exactly those other elements may be.

Community
  • 1
  • 1
ColdFusion
  • 2,381
  • 13
  • 14
  • Thanks for the information. In this case the things about xml and xsd version are wrong. Where can I set the xsd version? – CSchulz Aug 27 '13 at 08:17
  • You don't need to specify which XSD version your XML schema follows (there is no way, really). Since XSD 1.0 is a subset of XSD 1.1, all you need is the XSD 1.1 aware schema processor, e.g. XML validator that "knows" XSD 1.1. If it does not, it will just report errors. – ColdFusion Aug 27 '13 at 09:08
  • Okay and how to I *correct* my xsd that it matches my rules? A choice containing the **processName** element and a sequence with **any**? – CSchulz Aug 27 '13 at 16:22
  • XSD 1.1 is quite new (released in 2012, after all), so it is not widely supported yet. I've just googled for "xsd 1.1 validation". It finds a few solutions, including free ones. I think, you need to try it by yourself and could even tell us later what you achieved. I myself don't have time for this now. But your problem looks like solvable in that way. – ColdFusion Aug 27 '13 at 18:20
  • Okay found so far a solution, but it is possible to have duplicates now. :/ – CSchulz Aug 28 '13 at 18:48
0

Wildcards are also particles and can cause UPA violations when mixed with optional elements (or other wildcards.

  <xs:complexType name="bad2">
    <xs:sequence>
      <xs:element name="A" type="xs:string" minOccurs="0"/>
      <xs:element name="B" type="xs:string" minOccurs="0"/>
      <xs:any/>
    </xs:sequence>
  </xs:complexType>

Sometimes a wildcard conflict can be avoided by use a namespace="##other" attribute on the wildcard particle, but problems can arise later if the content model is extended to handle elements in more than one namespace. XML Schema 1.0 does not support exclusion of multiple namespaces in a wildcard.

Luís Cruz
  • 14,780
  • 16
  • 68
  • 100
Shital
  • 1