[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
How_To_XML_Create_Attributes_XML_Document

How to create attributes in an XML document?

XML attributes can be thought of as HTML attributes in that they are used to provide more information about an element. In the case of XML, you can define your own elements, attributes and their values.

XML attributes are added to the XML element's starting tag and their value must be enclosed in single or double quotes like this:

<book ISBN="0321173481"> or <book ISBN='0321173481'>

The ISBN is the attribute's name and '0321173481' is the attribute's value.

The two samples are equivalent in terms of information.

<?xml version="1.0"?>
<books>
   <book>
        <ISBN>0321173481</ISBN>
	<title>OpenGL Programming Guide Fourth Edition</title>
   </book>
</books>


<?xml version="1.0"?>
<books>
   <book ISBN="0321173481">
        <title>OpenGL Programming Guide Fourth Edition</title>
   </book>
</books>


You can use either way though attributes may not be as easy to handle as elements. Use attributes when the attribute does not strictly belong to the element but carries some data about it. IDs are typically attributes.

XML FAQ

last edited (April 19, 2004) by lillu, Number of views: 2281, Current Rev: 6 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.