Consider a collection of recipes stored in raw text files such as this example. We design an XML version of a recipe collection:
<?xml version="1.0" encoding="UTF-8"?>
<collection>
<description>
Some recipes used for the XML tutorial.
</description>
<recipe>
<title>Beef Parmesan with Garlic Angel Hair Pasta</title>
<ingredient name="beef cube steak" amount="1.5" unit="pound"/>
...
<preparation>
<step>
Preheat oven to 350 degrees F (175 degrees C).
</step>
...
</preparation>
<comment>
Make the meat ahead of time, and refrigerate over night, the acid in the
tomato sauce will tenderize the meat even more. If you do this, save the
mozzarella till the last minute.
</comment>
<nutrition calories="1167" fat="23" carbohydrates="45" protein="32"/>
</recipe>
...
</collection>
|
Note that XML documents (usually) begin with an XML declaration (<?xml ...?>)
To check that an XML document file.xml is wellformed XML, you can either
java -classpath xercesImpl.jar:xercesSamples.jar:xmlParserAPIs.jar dom.Writer file.xml >out.xmlOn Windows you type:
java -classpath xercesImpl.jar;xercesSamples.jar;xmlParserAPIs.jar dom.Writer file.xml >out.xmlThe program parses the file named file.xml, checks if it is well-formed and outputs the file. (The output is redirected to the file out.xml).
To run the W3C validator on a page without a DOCTYPE and encoding, try using "HTML 4.01 Transitional" and "iso-8859-1".