Oct. 4, 2010, 6 a.m.
posted by reo
Writing a Simple XML FileLet's start out by writing up a simple version of the kind of XML data you could use for a slide presentation. In this exercise, you'll use your text editor to create the data in order to become comfortable with the basic format of an XML file. You'll be using this file and extending it in later exercises. Note The examples in this chapter can be found in docs/tutorial/examples/jaxp/sax/samples. 1 Creating the FileUsing a standard text editor, create a file called slideSample.xml. Note Here is a version of it that already exists: slideSample01.xml. (The browsable version is slideSample01-xml.html.) You can use this version to compare your work, or just review it as you read this guide. 2 Writing the DeclarationNext, write the declaration, which identifies the file as an XML document. The declaration starts with the characters "<?", which is the standard XML identifier for a processor instruction. (You'll see other processor instructions later on in this tutorial.) <?xml version='1.0' encoding='utf-8'?> This line identifies the document as an XML document that conforms to version 1.0 of the XML specification, and says that it uses the 8-bit Unicode character-encoding scheme. (For information on encoding schemes, see Java Encoding Schemes (page 493).) Since the document has not been specified as standalone, the parser assumes that it may contain references to other documents. To see how to specify a document as standalone, see The XML Prolog (page 32). 3 Adding a CommentComments are ignored by XML parsers. You never see them in fact, unless you activate special settings in the parser. You'll see how to do that later on in the tutorial, when we discuss Handling Lexical Events (page 140). For now, add the text highlighted below to put a comment into the file. <?xml version='1.0' encoding='utf-8'?> <!-- A SAMPLE set of slides --> |
- Comment