问题
Is it legal for an XML document to specify that it follows both a DTD and a Schema? Won't the two conflict with one another?
回答1:
Technically I think you would have problems with the DTD not recognizing the attributes for referencing the schema (the namespace declaration and the schema location).
However I think it depends on how you're validating your XML and whether or not you can ignore the DTD for validation if a schema is specified.
Also, for your assignment are you sure you have to reference both from the same XML instance? Maybe you could have 2 versions of the XML; one that references the DTD and one that references the schema?
Here's two other possible options...
Declaring the schema attributes:
<!DOCTYPE doc [
<!ELEMENT doc (test)>
<!ATTLIST doc
xmlns:xsi CDATA #IMPLIED
xsi:noNamespaceSchemaLocation CDATA #IMPLIED>
<!ELEMENT test (#PCDATA)>
]>
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<test>Test Doc</test>
</doc>
Using a processing instruction to reference the schema:
<!DOCTYPE doc [
<!ELEMENT doc (test)>
<!ELEMENT test (#PCDATA)>
]>
<?xml-model href="test.xsl"?>
<doc>
<test>Test Doc</test>
</doc>
回答2:
Is it legal for an XML document to specify that it follows both a DTD and a Schema?
Yes
Won't the two conflict with one another?
Only if one of them mandates something the other forbids (in which case claiming to follow both would be a strange thing to do).
来源:https://stackoverflow.com/questions/16021048/can-an-xml-document-follow-both-a-dtd-and-an-xml-schema