how to add DTD element if I dont know the child elements

可紊 提交于 2019-12-11 07:28:47

问题


I need to validate xml files against a DTD.

Sometimes the child elements can be more and I dont know what child elements will come up next time, I tried the following:

<!ELEMENT Story (StoryPara+ , ANY+)+>

but this didn't work, how to validate for any child elements using DTD?


回答1:


You can't mix "ANY" with anything else in your content model. (You would use it just like you would use "EMPTY".)

What your current element declaration is saying is: at least one occurrence of: one or more "StoryPara" element(s) followed by one or more "ANY" element(s)

Change your element declaration to this:

<!ELEMENT Story ANY>

Do note that any child of "Story" must also be defined.

For example, this is valid:

<?xml version="1.0"?>
<!DOCTYPE test [
<!ELEMENT test ANY>
<!ELEMENT foo (#PCDATA)>
]>
<test>
  <foo>This element is defined.</foo>
</test>

but this is not because "bar" is not defined:

<?xml version="1.0"?>
<!DOCTYPE test [
<!ELEMENT test ANY>
<!ELEMENT foo (#PCDATA)>
]>
<test>
  <foo>This element is defined.</foo>
  <bar>This element is not defined.</bar>
</test>


来源:https://stackoverflow.com/questions/6489366/how-to-add-dtd-element-if-i-dont-know-the-child-elements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!