J
justyb11
Hi everyone,
I'm learning XML and have read a couple of site on the topic, but I'm
wondering how to implement something like this in a DTD.
<root>
<header>
<name> Some data </name>
<date month="12", day="01", year="2005" />
<author name="Bob" />
<note> Bob wrote this. </note>
</header>
</root>
However, the <name> tag is required, but all the others are optional.
Also, the name tag must appear first but it does not matter what order
the other fields appear in or if they even appear at all. So another
example of the document could be...
<root>
<header>
<name> Another Example </name>
<author name="Sue" />
</header>
</root>
or...
<root>
<header>
<name> A different example. </name>
<author name="Joe" />
<note> Quick example for you to look at. </note>
<date month="1", day="1", year="2004" />
</header>
</root>
I've come up with this much so far.
<!ELEMENT root (header)>
<!ELEMENT header (name, (author | note | date)?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT author EMPTY>
<!ELEMENT note (#PCDATA)>
<!ELEMENT date EMPTY>
<!ATTLIST author name CDATA #REQUIRED>
<!ATTLIST date month CDATA #REQUIRED>
<!ATTLIST date day CDATA #REQUIRED>
<!ATTLIST date year CDATA #REQUIRED>
I would also like to include that the author, note, and date element
can be used once or not at all. And if you use one of those elements
then you must use the the attributes listed.
I thank you all in advance for any help. Also if you could suggest
some tool that I can use in Linux to help me with XML and validation.
Thanks!
I'm learning XML and have read a couple of site on the topic, but I'm
wondering how to implement something like this in a DTD.
<root>
<header>
<name> Some data </name>
<date month="12", day="01", year="2005" />
<author name="Bob" />
<note> Bob wrote this. </note>
</header>
</root>
However, the <name> tag is required, but all the others are optional.
Also, the name tag must appear first but it does not matter what order
the other fields appear in or if they even appear at all. So another
example of the document could be...
<root>
<header>
<name> Another Example </name>
<author name="Sue" />
</header>
</root>
or...
<root>
<header>
<name> A different example. </name>
<author name="Joe" />
<note> Quick example for you to look at. </note>
<date month="1", day="1", year="2004" />
</header>
</root>
I've come up with this much so far.
<!ELEMENT root (header)>
<!ELEMENT header (name, (author | note | date)?)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT author EMPTY>
<!ELEMENT note (#PCDATA)>
<!ELEMENT date EMPTY>
<!ATTLIST author name CDATA #REQUIRED>
<!ATTLIST date month CDATA #REQUIRED>
<!ATTLIST date day CDATA #REQUIRED>
<!ATTLIST date year CDATA #REQUIRED>
I would also like to include that the author, note, and date element
can be used once or not at all. And if you use one of those elements
then you must use the the attributes listed.
I thank you all in advance for any help. Also if you could suggest
some tool that I can use in Linux to help me with XML and validation.
Thanks!