Home » XML Basics » 04 - XML Elements
4

Content and Atributes

In this section, you will know how to put a wide array of content into your XML tags. Extensibility and the attributes of XML tags will also be discussed.

Content

You can put all sorts of content into your XML tags. The following are examples of content that you can put into your XML tags.

  1. Elements - you can put elements within your XML tags. They will become children of the said parent element.
  2. Alphanumeric characters - you can put strings of characters, numbers, words, etcetera... into your XML tag.
  3. Elements and Alphanumeric Data - you can mix and match elements, words, and numbers into your XML tag.
  4. Nothing - sometimes you have to leave some XML tags blank in order to maintain consistency in format.

Below is an example of XML code with the different types of content.

<classcard>

<name> Sara </name>
<subject> programming </subject>
<result> <grade> 3.5/4.0 </grade> very industrious and recites a lot </result>
<complaints> </complaints>

</classcard>

Extensibility

If a programmer created an XML application that was designed to extract the name, subject, and grade of the data above, will it crash because there was an extra entry of complaints in it?

The answer is no. XML is an extensible programming language. It is designed to carry as much information as possible. Feel free to load up your XML files with as much data as you need. After all, this is one of the primary purposes of the existence of the XML programming language.

Attributes

Attributes are used to provide more information about elements. You use the following format for adding attributes to an element:

<nametag attribute = "...">

For example, if you want to add information on the date of grading then you can do this:

<classcard dategiven = "9/27/05">

<name> Sara </name>
<subject> programming </subject>
<result> <grade> 3.5/4.0 </grade> very industrious and recites a lot </result>
<complaints> </complaints>

</classcard>

You have now added more information to your elements. Try viewing this code on your browser and see what happens. The result should look something like this: