In this tutorial you will learn about the XML Attribute and its application with practical example.
XML Elements can have an optional list of attributes like HTML elements that provides the additional information about the element.Attributes is made of key / value pair separated by the equals (=) sign.Attributes is placed in opening tag and attribute values must always be quoted. Either single or double quotes can be used.
Table Of Contents−
Syntax:
1 |
<tagname attribute-name="attribute-value">content</tagname> |
Example:
1 2 3 4 5 6 7 8 9 10 |
<message msgid="1"> <from>John</from> <subject>Test Message 1</subject> <body>Hello John!</body> </message> <message msgid="2"> <from>Chris</from> <subject>Test Message 2</subject> <body>Hello John!</body> </message> |
In the above example “msgid” is used as attribute.