TopicsNext topics |
Step Three: Writing in XMLThe goal of this step is to describe and populate your well-formed XML instance. You will have to write your document and describe it with XML markup as you proceed. It will be the longest step since you are creating the bulk of your document. Now that you have a focus for your document, develop it. Start writing, explicitly describing content with elements of your own naming. Invent a new element each time you introduce content into your document that significantly differs from any previous. The deeper the description in your document, the greater the control you will have later, when you use it, possibly when writing a stylesheet. You can also use attributes to describe your document. They are contained within the start-tags of elements and are used to describe their content or behaviour. For example, an attribute might be used to describe the difference between ordered and unordered lists, if all lists were described with the <LIST> element. If the attribute was named type, an unordered list start-tag would take the form: <LIST type="unordered">. You can consider both elements and attributes as part of your description toolkit. Use the example XML instances, such as the trivia instance in step two, which described questions and answers, and the conversation in this step. Notice that both examples represent document components with descriptive elements. Effective XML instances use descriptive element names in a similar manner to ensure that documents are easy to create and maintain. Document authors typically name their documents. The TITLE and TTL elements are often used for naming documents and document components, such as tables and figures. You do not have to include a document title but it does provide a good description of your document to document readers. Your document name should be situated near the start of your document, but after the root element. Your Well-Formed XML InstanceYou should complete your well-formed XML instance in this step. Look to this instance that has grown with each step of the tutorial. You should not copy this example but you should mimic its general development. <?xml version="1.0" standalone="yes"?> <HELP> <TITLE>XML Help</TITLE> <QUERY area="XML"> <QUESTION>I don't know where to start. What do I do?</QUESTION> <ANSWER>Start with your root element. Break your document down into parts, filling them in and flushing them out further.</ANSWER> </QUERY> <QUERY area="XML"> <QUESTION>How do I know if my element names are well chosen? </QUESTION> <ANSWER>If their purpose is implied through their names, then they are well chosen. Make sure, at the very least, that they make sense to you. If not, rename them or change your structure.</ANSWER> </QUERY> <QUERY area="formatting"> <QUESTION>Where can I learn about formatting XML documents? </QUESTION> <ANSWER>You should learn much more about XML before you concern yourself with formatting. Formatting is an external process and is best done with XSL, CSS or DSSSL.</ANSWER> </QUERY> </HELP> An XML Document Describing a ConversationThis well-formed XML document describes a conversation between two people. You can use it as another example of good content description. Notice the use of attributes in the elements to further describe content. The use of upper-case for element names and lower-case for attribute names is merely a convention and does not need to be followed. <?xml version="1.0" standalone="yes"?> <CONVERSATION> <TITLE>A Conversation between Richard and Annie</TITLE> <SPEECH> <PERSON name="Annie">Why XML?</PERSON> <PERSON name="Richard">XML conforms to information, allowing document authors to create markup languages that work for them.</PERSON> </SPEECH> <SPEECH> <PERSON name="Richard">With HTML, document authors become frustrated, trying to fit their information sets into a fixed markup language. </PERSON> <PERSON name="Annie">For authors that have become used to HTML, but only want a few more elements, can they use XML?</PERSON> <PERSON name="Richard">With XML, anything is possible. You could extend or even contract HTML, depending on your needs. You can also define your own markup language, to describe any organization of information. Think of XML as being information-dependent.</PERSON> </SPEECH> </CONVERSATION> <Beginning of Document> <Table of Contents> <Previous> <Next> |