This is chapter one from the book, XML and FrameMaker, by Kay Ethier (Apress, ISBN: 159059276X. 2004). Ethier reviews some of the basic XML terms and rules, and provides a basic overview of the purpose of DTDs and XSLT.
Introduction to XML - Understanding XML Rules (1-3) (Page 4 of 7 )
What do you need to do to create an XML document? At the simplest level, you need a text editor in which you can type. On the other end of the spectrum, you may need an XML editing program; a validation tool; a DTD and DTD editor; XSL or CSS for formatting; and a repository for storage, tracking, and retrieval.
In this section, I cover simple rules that XML documents need to If you follow XML follow. Examples in this section serve to clarify the rules of XML, with each addressing a specific aspect of XML. The numbering on the rules (Rule 1, Rule 2, ...) is just to help you in your reading.
Rule 1: If you have an XML declaration, it must be the first line of the document.
While an XML declaration is not required, it can be helpful when bringing XML into different tools. The XML declaration is located at the top of your XML file and helps tools (and readers) identify the file as XML, rather than SGML or some other markup. An XML declaration may look like this:
If you have many small XML documents-XML fragments-that you plan to store and assemble, you might want to omit the declaration.That way, you do not end up with multiple declarations in an assembled file. This scenario will cause an error, since the declaration cannot occur below any content.
If you plan to produce valid XML, please note that you must have a declaration for an XML document to be valid.
Rule 2: All XML documents must have a root element.
In the example below, the root element is <zoo>. This root element begins the XML and its corresponding end tag </zoo> comes after all the content in the document, as shown in the following code:
Rule 3: All XML elements must be properly nested within the root element.
Items are nested inside the <zoo> root, as shown in the following code. These nested items include an <animals> child element. Inside this child element are additional elements called and . These are nested child elements.
What is incorrect is that the end tag is inside the reptile start and end tags. The nesting is incorrect because the tags cannot fold inside other tags unless they do so completely. Mathematically speaking, it is the equivalent of mixing up parentheses in a grouping, as illustrated in the following example:
(x + y)/z
does not have the same meaning as:
(x + y/z)
In these equations, having the parentheses in different locations changes what is divided by z and thereby change the value of the equation. In the first equation, x + y is divided by z, while in the second equation y alone is divided by z and then the result is added to x. So, placement of parentheses is important to getting the correct result. As with the equation above, to produce appropriate structure in XML it is necessary to properly nest the beginning and end tags.
This chapter is from XML and Framemaker, by Kay Ethier (Apress, 2004, ISBN: 159059276X). Check it out at your favorite bookstore today.