Re: Unique Particle Attribution with xsd:any and xsd:element with different namespaces

Mukul Gandhi <[email protected]>
Newsgroups gmane.text.xml.schema.devel
Message-ID <[email protected]>
Michael rightly wrote that in your schema, the wild-card and the
element particles are in same namespace, so you're getting a UPA
violation.

Here's probably a solution (one of the solutions I guess :)) with few
sample XML and schema documents, which could solve the problem for
you.

test.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                     targetNamespace="some-A"
                     xmlns:tns="some-A"
                     xmlns:fault="some-B"
                     elementFormDefault="qualified">

   <xsd:import namespace="some-B" schemaLocation="fault.xsd" />

   <xsd:element name="MyResponse">
       <xsd:complexType>
           <xsd:choice>
              <xsd:any namespace="##targetNamespace" processContents="lax" />
              <xsd:element ref="fault:Fault" />
           </xsd:choice>
       </xsd:complexType>	
   </xsd:element>

</xsd:schema>

fault.xsd
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                     targetNamespace="some-B"
		     xmlns:fault="some-B"
                     elementFormDefault="qualified">

   <xsd:element name="Fault" type="xsd:integer" />

</xsd:schema>

test1.xml
<MyResponse xmlns="some-A">
     <Fault>
        <Message>test message</Message>
     </Fault>
</MyResponse>

test2.xml
<MyResponse xmlns="some-A">
     <Fault xmlns="some-B">test message</Fault>
</MyResponse>

Here are the validation outcomes for above examples, with Xerces XML
Schema 1.0 engine:
1. Validating test1.xml with test.xsd successfully passes the
validation (here the child of 'MyResponse' is validated by the
wild-card)
2. Validating test2.xml with test.xsd gives following error,
[Error] test2.xml:2:45: cvc-datatype-valid.1.2.1: 'test message' is
not a valid value for 'integer'.
[Error] test2.xml:2:45: cvc-type.3.1.3: The value 'test message' of
element 'Fault' is not valid.
(here the child of 'MyResponse' is validated by the element
declaration in fault.xsd)

I hope this helps.

On Tue, Aug 31, 2010 at 8:03 PM, janne postilista
<[email protected]> wrote:
> Hi,
>
>  I am trying to create a choice with either a xsd:any from namespace A
> or xsd:element from namespace B. I think that because they are from
> different namespaces there should be no ambiguity, am I wrong?
>
> My schema:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>    targetNamespace="some-A"
>    xmlns:tns="some-A"
>    xmlns:fault="some-B"
>    elementFormDefault="qualified" >
>
>    <xsd:import namespace="some-B"
>    schemaLocation="fault.xsd" />
>
>    <xsd:element name="MyResponse">
>        <xsd:complexType>
>                <xsd:choice>
>                    <xsd:any namespace="##targetNamespace"/>
>                    <xsd:element name="Fault" type="fault:FaultType" />
>                </xsd:choice>
>        </xsd:complexType>
>    </xsd:element>
>
> When validating I get
>
>
> XML validation started.
> D:/zzz.xsd:33,8
> ERROR: cos-nonambig: WC["some-A"] and "hsome-A":Fault (or elements
> from their substitution group) violate "Unique Particle Attribution".
> During validation against this schema, ambiguity would be created for
> those two particles.
>
> 1 Error(s),  0 Warning(s).
> XML validation finished.
>
> What is the problem?



-- 
Regards,
Mukul Gandhi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.