开发者

xml dtd- how to avoid parsing the content of an element?

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'?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜