XML can be defined as building blocks of an XML document. Elements can behave as containers to hold text, elements, attributes, media objects or all of these. Each XML document contains one or more elements. An XML element is everything delimited by start and end tags which means it is everything within the including the tags themselves. Start and end tags of an element must be identical.
Syntax:
<element-name attributel attribute2>
.................content
</element-name>
Where :
name="value"
Name is followed by an = sign and a string value inside double(" ") or single(' ') Quotes.
Attributes given more information about XML elements. To be more precise they define properties of elements. An XML attribute is always a name-value pair as can be seen in the above example.
Rules for XML elements naming:
For Exmple:Syntax:
<element-name attributel attribute2>
.................content
</element-name>
Where :
- element-name is the name of the element. The start and end tags must be of the same case.
- attribute1,attribute2 are attributes of the element separated by white spaces.
- An attribute defines a property of the element. It associates a name with a value, which is a string of characters.
name="value"
Name is followed by an = sign and a string value inside double(" ") or single(' ') Quotes.
Attributes given more information about XML elements. To be more precise they define properties of elements. An XML attribute is always a name-value pair as can be seen in the above example.
Rules for XML elements naming:
- An element name can contain any alphabet, number and characters.
- Element names must start with a letter or underscore.
- Special characters allowed in names are the hyphen (-), under-score(_) and period (.).
- Names are case sensitive. For example, Term, term and TERM are different names.
- The name cannot contain blank spaces.
- Names cannot start with xml(Xml or XML which is a reserved word)
<element>...</element>
Example of an XML document using various XML elements.
<?xml version="1.0"?>
<contact-info>
<address category="residence">
<name>kumar shivan</name>
<company>HCL pvt ltd</company>
<phone>(001)123-4567</phone>
<address/>
</contact-info>
No comments:
Post a Comment