XML - XML Attributes
What are XML Attributes?
-
XML attributes provide additional information about elements.
-
They appear within the start tag of an element.
-
Syntax:
attributeName="value"
-
Rules:
-
Must be quoted.
-
Should not replace element content unless needed.
-
Each attribute must be unique per element.
-
Examples of XML Attributes
1. id
– Unique identifier
<student id="101">
<name>Ravi</name>
</student>
2. type
– Category or data type
<phone type="mobile">9876543210</phone>
3. lang
– Language indicator
<description lang="en">Welcome</description>
4. currency
– Currency code
<price currency="USD">25.50</price>
5. status
– Status label
<order status="shipped">
<item>Books</item>
</order>
6. date
– Date information
<event date="2025-07-23">Meeting</event>
7. gender
– Gender type
<person name="Anita" gender="female" />
8. format
– File or data format
<file name="document" format="pdf" />
9. version
– Version info
<software name="EditorX" version="3.2" />
10. category
– Classification type
<book title="XML Basics" category="technology">
<author>Jane</author>
</book>