About Me

Friday, 13 April 2012

XML Element

XML Element

XML is a markup language that is used to store data in a self-explanatory manner. Making the data "self-explanatory" comes about by containing information in elements. If a piece of text is a title then it will be contained within a "title" element.

XML Tag

A tag is just a generic name for a <element>. An opening tag looks like <element>, while a closing tag has a slash that is placed before the element's name: </element>. From now on we will refer to the opening or closing of an element as open or close tags. All information that belongs to an element must be contained between the opening and closing tags of an element.

XML Attribute

Attributes are used to specify additional information about the element. It may help to think of attributes as a means of specializing generic elements to fit your needs. An attribute for an element appears within the opening tag.
If there are multiple values an attribute may have, then the value of the attribute must be specified. For example, if a tag had a color attribute then the value would be: red, blue, green, etc. The syntax for including an attribute in an element is:
  • <element attributeName="value">
In this example we will be using a madeup XML element named "friend" that has an optional attribute age.

XML Code:

<friend age="23">Samantha</friend>

Element Review

  • Elements are used to classify data in an XML document so that the data becomes "self-explanatory".
  • Opening and closing tags represent the start and end of an element.
  • Attributes are used to include additional information on top of the data that falls between the opening and closing tag.

0 comments:

Post a Comment