I have the following XML file which includes internal DTD validation:
<?xml version="1.0"?>
<!DOCTYPE animals [
<!ELEMENT animals (animal)*>
<!ELEMENT animal (skin, noise, eyes, diet, class, weight, special_skill)>
<!ELEMENT skin (#PCDATA)>
<!ELEMENT noise (#PCDATA)>
<!ELEMENT eyes (#PCDATA)>
<!ELEMENT diet (#PCDATA)>
<!ELEMENT class (#PCDATA)>
<!ELEMENT weight (#PCDATA)>
<!ELEMENT special_skill (#PCDATA)>
<!ATTLIST animal name CDATA #REQUIRED >
<!ATTLIST weight unit CDATA "kg">
]>
<animals>
<animal name="cow">
<skin>
Straight fur
</skin>
<noise>
Moo!
</noise>
<eyes>
2
</eyes>
<diet>
Herbivore
</diet>
<class>
Mammalia
</class>
<weight unit="kg">
635-1134
</weight>
<special_skill>
Chewing
</special_skill>
</animal>
<animal name="sheep">
...
</animal>
</animals>
I was looking for how to replace the DTD validation with an XSD but couldn't find any examples. It seems like XSDs always need to be defined in a separate file and the be referenced by the XML. Is this true that XSD cannot be used internally?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…