Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Features

Technology
  Tech. Home
  GPS
  OSI
  WiMAX
  VoIP
  WiFi
  HSDPA
  LBS
  Vehicle Tracking
  SCADA
  Tech. What is?
Jobs At RoseIndia.net!
 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

XML Syntax Rules

                         

The syntax  rules  for  XML are very simple and strict. These  are  easy to learn and  use. Because of this, creating software that can read and manipulate XML is very easy. Xml enables an user to create  his own tags.

Note - XML documents use a self-describing and simple syntax

 

 

 

 

 

 

Let's develop a simple XML document :

<?xml version="1.0" encoding="ISO-8859-1"?>
<E-mail>
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u  tonight</Body>
</E-mail>

The XML declaration:  Always the first line in the xml document: 

The XML declaration should always be included. It defines the XML version and the character encoding used in the document. In this case the document conforms to the 1.0 specification of  XML and uses the ISO-8859-1 (Latin-1/West European) character set.

<?xml version="1.0" encoding="ISO-8859-1"?>

Root Element: The next line defines the first element of the document . It is called as the root element 

<E-mail>

Child Elements: The next 4 lines describe the four child elements of the root (To, From, Subject and Body).

<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...i will catch u  tonight</Body>

And finally the last line defines the end of the root element .

</E-mail>

you may feel from this example that the XML document contains a  E-mail To Rohan  From Amit. Don't you agree that XML is quite self-descriptive?

Now let's discuss its syntax-rules which are very simple to learn.

All XML elements must have a closing tag

In XML all the elements must have a closing tag like this:

<To>Rohan</To>
<From>Amit</From>

XML tags are case sensitive

XML tags are case sensitive. The tag <To> is different from the tag <to>.Hence the opening and closing tags must  be written with the same case:

<To>Rohan</To>
<to>Rohan</to>

XML Elements Must be Properly Nested

Improper nesting of tags makes no sense to XML. In XML all elements must be properly nested within each other like this in a logical order:

<b><i>Hi , how are you.....</i></b>

XML Documents Must Have a Root Element

All XML documents must contain a single tag pair to define a root element. All other elements must be written within this root element. All elements can have sub elements called as child elements. Sub elements must be correctly nested within their parent element:

<root>
  <child>
    <subchild>.....</subchild>
  </child>
</root> 

Always Quote the XML Attribute Values 

In XML the attribute value must always be quotedXML elements can have attributes in name/value pairs just like in HTML. Just look the two XML documents below.  

The error in the first document is that the date and version attributes are not quoted .
<?xml version=1.0 encoding="ISO-8859-1"?>
<E-mail date=12/11/2002/>

The second document is correct:

<?xml version="1.0" encoding="ISO-8859-1"?>
<E-mail date="12/11/2002"/>

With XML, White Space is Preserved

With XML, the white space in a document is  preserved .

So a sentence like this :   Hello              How are you, will be displayed like this:

Hello              How are you,

Comments in XML

The syntax for writing comments in XML is similar to that of HTML.

<!-- This is a comment -->

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (post your own) View All Comments Latest 10 Comments:

with its easy and clear approach [put in a nutshell] takes away the burden of learning a software application. thanks

Posted by vijayalakshmi on Tuesday, 08.12.08 @ 12:10pm | #72463

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.