Question

Goal:

Element octave can have either subnode query or any subnode in namespace http://www.website.com/main.

I don't know where/how this is violating unique particle attribution...there's no other element called octave or subnode called query. Query is not a global element, it is used only for octave.

Error:

"cos-nonambig: "http://www.website.com/main":query and WC["http://www.website.com/main"] (or elements from their substitution group) violate "Unique Particle Attribution". During validation against this schema, ambiguity would be created for those two particles."

Schema:

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema
    xmlns="http://www.website.com/main"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://www.website.com/main" 
    attributeFormDefault="unqualified" elementFormDefault="qualified"
    >

<xs:complexType name="octave" >
    <xs:choice>
        <xs:element name="query" type="xs:string" />
        <xs:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.website.com/main" processContents="strict" />
    </xs:choice>
    <xs:attribute name="id" type="xs:string" use="optional" />
</xs:complexType>

<xs:element name="octave" type="octave" />

Was it helpful?

Solution

The behavior you describe can be obtained by declaring 'octave' this way:

<xs:complexType name="octave" >
  <xs:choice>
    <xs:any minOccurs="0" 
            maxOccurs="unbounded" 
            namespace="http://www.website.com/main" 
            processContents="strict" />
  </xs:choice>
  <xs:attribute name="id" 
                type="xs:string" 
                use="optional" />
</xs:complexType>

and declaring query as a global element:

<xs:element name="query" type="xs:string" />

Since the query element you are defining is in namespace http://www.website.com/main, it is accepted by the wildcard and there is no pressing need, from the point of view of the 'octave' type, to include an element reference to it in the choice.

This design does have the disadvantage of making 'query' accessible to all existing wildcards which match arbitrary elements in namespace http://www.website.com/main. If it matters a great deal that 'query' should appear only as a child of element 'octave' and other elements of the same type, then you might consider making the local 'query' element unqualified:

<xs:complexType name="octave" >
  <xs:choice>
    <xs:element name="query" 
                type="xs:string" 
                form="unqualified"/>
    <xs:any minOccurs="0" 
            maxOccurs="unbounded" 
            namespace="http://www.website.com/main" 
            processContents="strict" />
  </xs:choice>
  <xs:attribute name="id" 
                type="xs:string" 
                use="optional" />
</xs:complexType>

Since the declaration of 'query' no longer generates an element declaration whose expanded name is in the 'main' namespace, it no longer competes with the wildcard.

You might also move to XSD 1.1, which relaxes the 'unique particle attribution' rule by saying that element declarations and references are matched in preference to wildcards and which thus makes your existing declaration legal.

OTHER TIPS

The problem is in my opinion following: you define targetNamespace="http://www.website.com/main". Then use <xs:any... to declare that there can be anything from this namespace. But in this namespace is also query element so it could be present there because of the direct declaration using <xs:element and also because of the "indirect" declaration using <xs:any.

Probably for parser it is the same as if you declared something like this:

<xs:complexType name="a">
    <xs:choice>
        <xs:element name="b" type="xs:string" />
        <xs:element name="b" type="xs:string" />
    </xs:choice>
</xs:complexType>

And this is an error obviously.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top