Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

XML Documents : Page 5

XML documents are similar to HTML documents. They contain information and markup tags that define the information, and are saved as ASCII text.


advertisement
Valid XML
A valid document conforms to the XML syntax rules and follows the guidelines of a Document Type Definition (DTD).

The process of comparing the XML document to the DTD is called validation. This process is performed by a tool called a parser.

Begin the Valid XML Document
To begin a well-formed document, type the XML declaration:

<?xml version="1.0" standalone="no" encode="UTF-8"?>



If you are embedding XML, it will go after the <HTML> and <HEAD> tags, and before any Javascript.

If you are creating an XML-only document, it will be the first thing in the file.

Version
You must include the version attribute for the XML declaration. The version is currently "1.0." Defining the version lets the browser know that the document that follows is an XML document, using XML 1.0 structure and syntax.

Standalone
The standalone="no" attribute tells the computer that it must look for a DTD and validate the XML tags.

Encoding
Finally, declare the encoding of the document. You can leave off this attribute and the processor will default to UTF-8.

Create a DOCTYPE Definition
The second element in a valid XML document is the DOCTYPE definition. This identifies the type of document and DTD in use.

If you look at HTML source files, you'll often see a !DOCTYPE definition, especially if the file was created by a WYSIWYG tool. The DOCTYPE definition points to an HTML DTD.

In a valid XML file, !DOCTYPE tells the program that is processing your XML file two things: the name of the type of document and the name and location of the DTD against which to validate the file's contents.

The DOCTYPE definition looks like this:

<!DOCTYPE type-of-doc SYSTEM/PUBLIC "dtd-name">

!DOCTYPE
This says that you are defining the DOCTYPE.

type-of-doc
This is the name of the type of document contained in this file. Typically, this is the same name as the DTD.

SYSTEM/PUBLIC
SYSTEM tells the processor to look for the private DTD at the following location. PUBLIC tells the processor to look for a public DTD at the following location.

"dtd-name"
The URL after SYSTEM or PUBLIC is the name of the dtd file. All DTDs end with the extension .dtd.

If you want, instead of pointing to an external DTD, you could place the DTD information within the DOCTYPE definition, making it local to your XML document. You should do this only if you want to define a few simple elements and you want them permanently attached to a particular document.

Remember the Root Element
After the declaration, enter the tag for the root element of your document. This is the top-most element, under which all elements are grouped.

Follow XML Syntax
Now, enter the rest of the your content. Remember to follow XML syntax:
  • Remember that capitalization matters;
  • Quote all attribute values;
  • Close all tags;
  • Remember to close empty tags too, like this:

    <br/>





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date