【xml】DTD文档和内部DTD 实验三

2019-11-08 00:44:18 浏览数 (1)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/shiliang97/article/details/101296688

外部DTD文档

不需要在外面再套一层

<!DOCTYPE NEWSPAPER[

]>

这个了。直接这样写

代码语言:javascript复制
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT NEWSPAPER (ARTICLE )>
<!ELEMENT ARTICLE (HEADLINE, BYLINE, LEAD, BODY, NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPATER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">

然后相应的xml文件

不能用&了,会报错error on line 7 at column 20: Entity 'PUBLISHER' not defined等等错误

要用&amp;替换这个

把实体引用编码后使用,即 把“&”编码为 “&amp;” 把“<”编码为“&lt;” 把“>”编码为 “&gt;” 把“'”编码为 “&apos;” 把“"”编码为 “&quot;

代码语言:javascript复制
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE NEWSPAPER SYSTEM "3-2dtd.dtd">
<NEWSPAPER>
	<ARTICLE AUTHOR="&amp;NEWSPATER;" EDITOR="&amp;PUBLISHER;" DATE="2009-6-1" EDITION="&amp;COPYRIGHT;">
		<HEADLINE>Environment Protection</HEADLINE>
		<BYLINE>Material waste</BYLINE>
		<LEAD>&amp;PUBLISHER;</LEAD>
		<BODY>
dfjaljdklafhjkdfhsjkdafgjhkfgdshdafsdfjhsgdafjkdasgfsgjdafdfasdfdsfa

</BODY>
		<NOTES>
jdslfjklasdhfjkdshfjksldahfjkdshfkhasdfdsaf
</NOTES>
	</ARTICLE>
</NEWSPAPER>

内部DTD直接写不需要注意前面的问题

咱也不知道为啥不用替换&amp;

代码语言:javascript复制
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE NEWSPAPER[
<!ELEMENT NEWSPAPER (ARTICLE )>
<!ELEMENT ARTICLE (HEADLINE, BYLINE, LEAD, BODY, NOTES)>
<!ELEMENT HEADLINE (#PCDATA)>
<!ELEMENT BYLINE (#PCDATA)>
<!ELEMENT LEAD (#PCDATA)>
<!ELEMENT BODY (#PCDATA)>
<!ELEMENT NOTES (#PCDATA)>
<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED>
<!ATTLIST ARTICLE EDITOR CDATA #IMPLIED>
<!ATTLIST ARTICLE DATE CDATA #IMPLIED>
<!ATTLIST ARTICLE EDITION CDATA #IMPLIED>
<!ENTITY NEWSPATER "Vervet Logic Times">
<!ENTITY PUBLISHER "Vervet Logic Press">
<!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">
]>
<NEWSPAPER>
<ARTICLE AUTHOR="&NEWSPATER;" EDITOR="&PUBLISHER;" DATE="2009-6-1" EDITION="&COPYRIGHT;">
<HEADLINE>Environment Protection</HEADLINE>
<BYLINE>Material waste</BYLINE>
<LEAD>&PUBLISHER;</LEAD>

<BODY>
dfjaljdklafhjkdfhsjkdafgjhkfgdshdafsdfjhsgdafjkdasgfsgjdafdfasdfdsfa

</BODY>
<NOTES>
jdslfjklasdhfjkdshfjksldahfjkdshfkhasdfdsaf
</NOTES>
</ARTICLE>
</NEWSPAPER>

0 人点赞