开发者

dtd and mixed content

开发者 https://www.devze.com 2023-01-30 14:40 出处:网络
Does someone know way a mixet content element (in dtd) there is a need to add the \"*\" at the end? For example:<!ELEMENT note (#PCDATA|to|from|header|message)*>

Does someone know way a mixet content element (in dtd) there is a need to add the "*" at the end?

For example:<!ELEMENT note (#PCDATA|to|from|header|message)*>

I'm reffering to the 开发者_Go百科case where I don't want to repeat anything again... I just want to be able to choose between #PCDATA and other elements.

I know that if I drop the "*" in the end of the decleration I will get a bad DTD decleration... But - I have no idea what is the reason of that...

Anyone know why?


You're hitting this restriction because the mixed content model is only allowed to constrain which elements occur not their order or the number of them. This is, I'm afraid, required by the XML Specification itself.

Mixed content is hard I'm afraid. The model was designed with documents in mind - it makes sense when you think of inline text but not in many other cases. If you have a choice, best practice would suggest that you create an element to contain your PCDATA. If you can't then I'm afraid you are stuck with the limits of mixed content models (using another schema language doesn't help much either I'm afraid).


You want to use ANY

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE things [
    <!ELEMENT things ANY>
]>
<things>
    <person name="a" />
    <cats />
    <dogs />
    <animals><a rel="gogo" /></animals>
</things>

Also, the * is the operator for zero to more occurrences. So the (element|element2)* is saying either or/and

0

精彩评论

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