Validating only parts of an XML document using schema?

Is it possible to write a schema to mix validated XML with only well-formed XML? An example is a data transfer application in which requests consist of a bunch of metadata (which we would like to check) and a specific record (which is checked separately from XML in business logic, since XML requests are only one of several ways through which requests can come )

Example:

<request>
    <campaign>CAMP00001</campaign>
    <username>user_bob</username>
    <token>one-time-token-goes-here</token>
    ... more meta-data ...
    <records>
        <record id="90209">
            <name>John Doe</name>
            <address>Park Lane 191</address>
            <postal>99999</postal>
        </record>

        <record id="90210">
            <name>Jane Doe</name>
            <address>Park Lane 192</address>
            <postal>88888</postal>
        </record>
    </records>
</request>

, , . , XML, , , - , , . ?

( , , <data> , <data> .. )

+3
2

.

<xs:element name="foo">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="first" type="xs:string"/>
            <xs:element name="second" type="xs:string"/>
            <xs:any minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

, foo node, . :

<foo>
    <first>Hello</first>
    <second>World</second>
    <other>can be anything</other>
    <nodes/>
</foo>
+7

.

0

Source: https://habr.com/ru/post/1727643/


All Articles