Domanda

I have a couple problems with generating XML Schema for an XML document. The XML document should look like this:

<HEADER>
    <ID>64639</ID>
    ....
    <INCIDENT>
        <HEADER>64639</HEADER>
    </INCIDENT>
    <INCIDENT>
        <HEADER>64639</HEADER>
    </INCIDENT>
    ....
</HEADER>

So far I achieved the following structure:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        elementFormDefault="qualified">

<xsd:element name="HEADER">
    <xsd:complexType>
        <xsd:all>
            <xsd:element minOccurs="1" name="ID" nillable="false" type="xsd:integer"/>
        </xsd:all>
    </xsd:complexType>
    <xsd:key name="SYS_C0032500">
        <xsd:selector xpath="."/>
        <xsd:field xpath="ID"/>
    </xsd:key>
    <xsd:keyref name="SYS_C0032500_HEADER.ID_INCIDENT.HEADER_" refer="SYS_C0032500">
        <xsd:selector xpath="INCIDENT"/>
        <xsd:field xpath="HEADER"/>
    </xsd:keyref>
</xsd:element>

<xsd:element name="INCIDENT">
    <xsd:complexType>
        <xsd:all>
            <xsd:element minOccurs="1" name="HEADER" nillable="false" type="xsd:integer"/>
        </xsd:all>
    </xsd:complexType>
    <xsd:key name="IDK">
        <xsd:selector xpath="."/>
        <xsd:field xpath="HEADER"/>
    </xsd:key>
</xsd:element>

</xsd:schema>

The criteria of this task to use the and elements to simulate database constraints. Currently I get an error message that says:

Engine name: Xerces Severity: error Description: cvc-complex-type.2.4.d: Invalid content was found starting with element 'INCIDENT'. No child element is expected at this point. Start location: 3:6 End location: 3:14 URL: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type

My other problem comes with the more INCIDENT parts. How can I add more INCIDENT elements, when the has no maxOccurs attribute?

Thanks for every help!

Regards, Joe

È stato utile?

Soluzione

In your example instance document, the content model for HEADER appears to be "an ID followed by one or more INCIDENTs". In XSD that is:

<xsd:element name="HEADER">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="ID" nillable="false" type="xsd:integer"/>
            <xsd:element name="INCIDENT" minOccurs="1" maxOccurs="unbounded" type="..."/>
        </xsd:all>
    </xsd:complexType>
    ...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top