Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an XML document follow both a DTD and an XML Schema?

Tags:

xml

schema

dtd

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?

like image 573
CodyBugstein Avatar asked Dec 06 '25 00:12

CodyBugstein


1 Answers

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.xsd"?>
<doc>
    <test>Test Doc</test>
</doc>
like image 86
Daniel Haley Avatar answered Dec 09 '25 04:12

Daniel Haley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!