Pergunta

I have tried the following to test that an element has a unique identifier. So far, .net has said that the xml is valid with the xsd but it shouldn't be.

The XML:

<Document>
   <Record>
     <Id>1</Id>
   </Record>
   <Record>
     <Id>1</Id>
   </Record>
</Document>

The XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Filing_new"
           targetNamespace="http://tempuri.org/Filing_new.xsd"
           elementFormDefault="qualified"
           xmlns="http://tempuri.org/Filing_new.xsd"
           xmlns:mstns="http://tempuri.org/Filing_new.xsd"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <!-- Document Schema -->
    <xs:element name="Document">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Record" minOccurs="1" maxOccurs="unbounded">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element name="Id" type="xs:integer" />
                    </xs:sequence>
                  </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:unique name="sequence">
            <xs:selector xpath="Record" />
            <xs:field xpath="Id" />
        </xs:unique>
    </xs:element>
</xs:schema>

What am I doing wrong?

Foi útil?

Solução

It would work in a no-namespace schema.

In your schema, the elements in the XPath expression must be qualified with your target namespace http://tempuri.org/Filing_new.xsd (which has a mstns prefix declared in your schema, so you can use it). It should work if you add the mstns: prefix to the elements in your XPath expressions:

<xs:selector xpath="mstns:Record" />
<xs:field xpath="mstns:Id" />
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top