Can I reference an external DTD for the structure of an ELEMENT in a DTD?

旧街凉风 提交于 2019-12-05 14:41:09

Yes and you are very close with your example. You just need to reference the parameter entities. Here's an example of 3 DTD's and an XML instance. I only used #PCDATA for MessageHdr and MessageBody, but this can be any structure you define.

message.dtd

<!ENTITY % MessageHdr-DTD SYSTEM "./messagehdr.dtd">
<!ENTITY % MessageBody-DTD SYSTEM "./messagebody.dtd">
%MessageHdr-DTD;
%MessageBody-DTD;
<!ELEMENT Message (MessageHdr, MessageBody)>

messagehdr.dtd

<!ELEMENT MessageHdr (#PCDATA)>

messagebody.dtd

<!ELEMENT MessageBody (#PCDATA)>

message.xml

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