Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Rules For a Well-formed XML Document

You can be loose and sloppy with HTML, making all kinds of coding errors, and browsers will still display the web page, probably with no visible damage. But sloppy XML code is not permitted. An error in an XML document will bring your application to a halt. Here are the basic rules for creating well-formed XML.

An XML document has exactly one root element. The root element encloses all the other elements and is the top-level parent element to all the other elements. In the code shown below, <catalog> is the root element.

<catalog>
   <book newused="new">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in detail.</description>
   </book>
   <book newused="used">
      <author>O'Brien, Tim</author>
      <title>MSXML3: A Comprehensive Guide</title>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in detail.</description>
   </book>
   <book newused="new">
      <author>Galos, Mike</author>
      <title>Visual Studio 7: A Comprehensive Guide</title>
      <price>49.95</price>
      <publish_date>2001-04-16</publish_date>
      <description>Microsoft Visual Studio 7 is explored in depth.</description>
   </book>
</catalog>

XML tags are case sensitive. Closing tags must have the same upper-case, lower-case arrangement as their respective opening tag.

<author>O'Brien, Tim</author>
<TITLE>Microsoft .NET: The Programming Bible</TITLE>
<price>36.95</price>

All XML elements must have a closing tag.

<book newused="new">
   <author>O'Brien, Tim</author>
   <title>Microsoft .NET: The Programming Bible</title>
   <price>36.95</price>
   <publish_date>2000-12-09</publish_date>
   <description>Microsoft's .NET initiative is explored in detail.</description>
</book>

All opening and closing tags must match.

<author>O'Brien, Tim</author>
<title>Microsoft .NET: The Programming Bible</title>
<price>36.95</price>

All tags must be nested correctly. When an element appears within another element, it is said to be nested within that element. An element which is nested inside another element must have its closing tag before the closing tag of the outer element.

<catalog>
   <book newused="new">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
   </book>
</catalog>

All attribute values must be enclosed in single or double quotation characters.

<catalog>
   <book newused="new">
      <author>O'Brien, Tim</author>
      <title>Microsoft .NET: The Programming Bible</title>
      <price>36.95</price>
      <publish_date>2000-12-09</publish_date>
      <description>Microsoft's .NET initiative is explored in detail.</description>
   </book>
   <book newused="used">
      <author>O'Brien, Tim</author>
      <title>MSXML3: A Comprehensive Guide</title>
      <price>36.95</price>
      <publish_date>2000-12-01</publish_date>
      <description>The Microsoft MSXML3 parser is covered in detail.</description>
   </book>
</catalog>

An error in an XML document will bring your application to a halt. If you follow these rule for creating well-formed XML code, there is much less chance of creating an error, and any error will be easier to locate.

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro


Fire HD
[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2010 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269