tags:

views:

32

answers:

1

Among the elements that consist my xml, I have got element let's call it 'X' that can contain many different kind of inner elements. Therefore I'd like to define the DTD parser to avoid parsing its content during its XMl validation.
I tried to define this elemtn by:
<!ELEMENT X ANY>
and got error message that the inner element inside 'X' is undefined and when trying to define it as:
<!ELEMENT X (#PCDATA)>
I got the error message 'Only text allowed inside 'X''

How should I define X so the DTD validator will ignore the content of element 'X'?

+1  A: 

Some guides on the Internet claim that ANY means shutting down the validation process for this element, but this is not correct information. Content model ANY in DTD doesn't actually mean "allow whatever well formed XML content in this element". Instead it means "allow any content defined in this DTD". This means that you will get an error for every element which content model you have not defined (or you can not define). Conceptually speaking this means the same as being unable to allow contents from another namespace.

Unfortunately at the moment I can't recall any way to do this with DTD. However, this is possible with XML Schemas:

<xs:complexType>
  <xs:sequence>
    <xs:any namespace="##any" processContents="skip"/>
  </xs:sequence>
</xs:complexType>

This would allow any elements from any namespace and skip the validation for this element. If you are able to switch from DTDs to XML Schemas, this would solve your problem.

Note about a simple error when using ANY
(Original poster didn't have this error but I'm just mentioning it here since I'm already writing about this subject.)
This is a simple typo to make, but these two do not mean the same:

<!ELEMENT X  ANY  >
<!ELEMENT X (ANY) >

The first one refers to content model keyword ANY but the second one means an element with name "ANY", and it's the parenthesis that cause this difference.

jasso
So your answer is that there is no solution in DTD. Can't There be any workaround intead?
Spiderman
@Spiderman My answer is that "at the moment I can't recall any way to do this with DTD". There is a slight chance that it is possible, but I don't think so and I couldn't come up with any solution. :( Workaround is to use something else than DTD for validating, if using DTD is not mandatory.
jasso
eventually I did move to XSD world and used <xs:any namespace="##any" processContents="skip"/> solution. So thanks
Spiderman