XML Syntax

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

xml syntax

If you have already programmed in HTML, XML syntax shouldn't be that much of a leap to grasp. While there are a couple of new items in XML, it is still just a markup language that relies on tags to get the job done.

xml syntax: our example xml document

This lesson will analyze a real XML file to point out the syntax used to create a Well-Formed XML document. This XML document was used to keep track of students in an Computer Application's Course.

XML Code:




  Robert
  A+


  Lenard
  A-
 

 

If you spend a few moments reading through the above XML document, you can see it has two students, Robert and Lenard. This simple XML document readily displays the benefits of XML. The data seems to almost describe itself, which is one of the main reasons XML was created!

Let's take a look at XML syntax by looking at the different parts of this document. Note: This is just an overview of XML's syntax and there are links to more information provided in this lesson.

xml prolog (optional)

I think the only thing not easily understandable in our XML document is that first line with all the symbols and attributes. This rather confusing line in our XML document is referred to as the XML Prolog.

XML Code:

This line with special symbols and attributes is what is referred to as the XML declaration. It simply states what version of XML you are using and the type of encoding you are using. Don't worry too much about this line just always include it exactly as we have above. If you are curious, feel free to learn more about ISO 8859.

xml tag

The XML tag is very similar to that of the HTML tag. Each element is marked with an opening tag and a closing tag. Below, we have highlighted both the opening and closing tags from a piece of our example XML file.

XML Code:

Robert
A+

Later in the tutorial, we talk more about XML Tags, including opening tags, closing tags, and all the text inbetween them, which combine to form XML Elements.

xml elements

XML Elements are the meat and potatoes of XML. They contain the opening and closing tags, child elements, and data. In our XML document the studentelement is comprised of all of the following information. Notice how it has a couple of child elements.

XML Code:


Robert
A+

Check out our XML Elements lesson for more information.

xml attributes

Our simple XML document did not include any examples of XML Attributes, but they will be discussed later on in the tutorial.