xmldtdxmlspy

DTD - Switch off validation for specific XML element


I'm writing a DTD for an XML document I create. The XML document is a wrapper around a Payload provided by another system. I have no control over the contents of the Payload, and don't care providing it is self-contained valid XML. (It is ultimately validated by a separate schema I have no control over).

However, I do care about the structure of the wrapper and want to be able to dictate the structure of each Example below and control the SomeData I add.

The DTD will look something like this:

<!DOCTYPE Examples[
<!ELEMENT Examples(Example+)>
<!ELEMENT Example(SomeData,Payload)>
<!ELEMENT SomeData (#PCDATA)>
<!ELEMENT Payload ANY>
]>

The Payload will be somthing like:

<Payload><foo>bar</foo></Payload>

The problem is that whatever I drop into the Payload, XMLSpy will continue validating that and complain that the child elements of Payload are not expected:

Content model of element <Payload> disallows element <foo> at this position.

Element <foo> has not been declared.

What I want is a way to say, "everything underneath Payload is not defined as having a specific structure, so please ignore it".

I figured defining it as ANY or CDATA might work, but so such luck.

Any pointers much appreicated.


Solution

  • In short - I don't believe this is possible in dtd.

    As Michael points out in the comments it is possible in XSD.

    You can use <xs:any processContents="skip"/> which is the answer to the original questions, but what is more useful (to me) is to use <xs:any processContents="strict"/> and specify a different XSD for the inner XML.

    You can see my follow-up question and answer about the specifics of doing this: Dynamic XML Schema Validates Subsection of Document