How would I know if The XML that I created follows the rule that is in my DTD?
here’s my XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE HW SYSTEM "HW.dtd">
<A>
AA = "BAR"
AB = "FOO"
AC = "1"
<C>
<B/>
CA = "Name"
</C>
<D>Element</D>
</A>
and here is my DTD
<?xml version="1.0" encoding="ISO-8859-1"?>
<!ELEMENT A (B* |C+,D)>
<ATTLIST A
AA CDATA #REQUIRED
AB CDATA #REQUIRED
AC(0|1|2) #REQUIRED
>
<!ELEMENT B EMPTY>
<!ATTLIST C(B)>
<!ATTLIST C
CA CDATA #REQUIRED
>
<!ELEMENT D (#PCDATA)>
is my XML correct with the DTD?
You need to Use an XML Validator,
An Online version is http://www.xmlvalidation.com/, there are lots of tools that do this also
According to the validator, your DTD is not valid
I’ve tried to fix up your DTD, here’s the fixed up version
The problems with the DTD you posted were:
As far as I could see you need the brackets around C+,D also the
<ATTLISTabove is incorrect as you specify a list of attributes with<!ATTLISTnote the ! was missing.Also your DTD had
Which failed validation as you were defining an attribute list from element C
<!ATTLIST Cbut hadn’t defined the Element C in the DTD, therefore I changed it toThis makes your DTD valid
Also your XML is wrong in quite a few ways
for example your DTD specifices
Which means that Element A must have the attributes AA BB AC as they are required also AC attribute must be 0 or 1 or 2
You have put
Which is not specifiying XML attributes in the Element A, to specify attributes it should be
This should help you do your homework
heres a link http://www.quackit.com/xml/tutorial/dtd_introduction.cfm to a DTD tutorial this should help you create an XML doc that validates against it