外部DTD文档

不需要在外面再套一层

<!DOCTYPE NEWSPAPER[

]>

这个了。直接这样写

<?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;” 

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

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