TopicsNext topics |
Step Five: Writing Valid XMLThe goal of this step is writing a valid XML document, making sure to conform with your DTD. After having struggled with the DTD, writing the document is easy. Valid XML is actually easier to write than well formed XML because you simply follow the structure of the DTD, which requires much fewer choices. Valid XML document writing is much different than well-formed XML. You must follow the DTD that you have written, making sure to not break any of the rules that you have written. If your document does become non-conformant, you had better fix it, as it will likely not display or process properly when you use it. Your document should include XML and document type declarations. Insert a start- and end-tag for your root element. Follow the DTD explicitly, paying special attention to the content rule of each element, making sure to comply where you are required to and choose where you are allowed. Errors are a major problem for document developers. If you take care in your writing, making sure to follow the DTD, you can avoid errors. Ensure that your elements nest properly, as overlapping elements cause errors. If you find that your DTD is too strict for the document that you wish to write, then modify your DTD. The DTD is yours, and can be modified as you need to. Keep the overall structure of your document in mind, being sure that your rendering of it in XML is correct and makes sense. Your valid XML Instance
<?xml version="1.0" standalone="no"?>
<!DOCTYPE MEMO [
<!ELEMENT MEMO (TO,FROM,SUBJECT,BODY,SIGN)>
<!ATTLIST MEMO importance (HIGH|MEDIUM|LOW) "LOW">
<!ELEMENT TO (#PCDATA)>
<!ELEMENT FROM (#PCDATA)>
<!ELEMENT SUBJECT (#PCDATA)>
<!ELEMENT BODY (P+)>
<!ELEMENT P (#PCDATA)>
<!ELEMENT SIGN (#PCDATA)>
<!ATTLIST SIGN signatureFile CDATA #IMPLIED
email CDATA #REQUIRED>
]>
<MEMO importance="HIGH">
<TO>Tutorial Takers</TO>
<FROM>Tutorial Writer</FROM>
<SUBJECT>Your impressions</SUBJECT>
<BODY>
<P>Now that you are almost done the tutorial, you must be getting
an idea of what XML is about. These emerging technologies sometimes
take time though before they catch on.</P>
<P>Did you find the tutorial helpful? Which areas did you find
confusing? How would you improve them?</P>
</BODY>
<SIGN email="rlander@pdbeam.uwaterloo.ca">Richard</SIGN>
</MEMO>
<Beginning of Document> <Table of Contents> <Previous> <Next> |