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

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 Attributes

                         

XML elements can have attributes in the start tag, just like HTML. Attributes are used to provide additional information about elements. Attributes often provide information that is not a part of the data. In the example below, the file type is irrelevant to the data, but important to the software that wants to manipulate the element:

<file type="gif">roseindia.gif</file>

Use the quote styles: "red" or 'red'

Attribute values must always be enclosed in quotes. Use either single or double quotes  eg..

<color="red">

or like this:

<color='red'>

Note: If the attribute value itself contains double quotes it is necessary to use single quotes, like in this example: 

<name='Rose "India" Net'>

Note: If the attribute value itself contains single quotes it is necessary to use double quotes, like in this example: 

<name="Rose 'India' Net">

Use of Elements vs. Attributes

If you start using attributes as containers for XML data, you might end up with the documents that are both difficult to maintain and  manipulate. So the user should use elements to describe the data. Use attributes only to provide data that is not relevant to the reader. Only metadata (data about data) should be stored as attributes, and that data itself should be stored as elements.

This is not the way to use attributes eg..

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

Try to avoid using attributes in few of the situations.

Lot of  problems occur with using attributes values. They are not easily expandable and cannot contain multiple values .They are not easy to test against a Document Type Definition and are also unable to describe their structure. Becomes more  irritating ,because of its difficultly to get manipulated by program code.

Here is an example, demonstrating how elements can be used instead of attributes. The following three XML documents contain exactly the same information. A date attribute is used in the first, a date element is used in the second, and an expanded date element is used in the third:

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

First  xml document contains date as a attribute which can not  be further extended. But date used a element in second document makes it more flexible.

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

Second xml document can be further extended as.. 

<?xml version="1.0" encoding="ISO-8859-1"?>
<E-mail >
<date> 
      <day>12</day> 
      <month>11</month> 
      <year>99</year> 
</date>

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

                         

Ask programming questions?

 

 

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

Current Comments

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

if u want to do xml parsing use this pattern


it's open source with a complete document :
http://SourceForge.net/projects/shine-enterpris/files/

Posted by ali on Friday, 07.2.10 @ 14:45pm | #97906

I need the xml tags for creating border with header

Posted by uma on Tuesday, 01.6.09 @ 17:50pm | #83542

date field not closed in one example

try to correct it

Posted by ajay on Monday, 10.1.07 @ 18:01pm | #30825

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
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.

[an error occurred while processing this directive]