Pages

Powered by Blogger.

Thursday 31 October 2013

The XML Language

Howdy! What a pleasent today. Aside from this day being an election day for IIUM Kuantan next SRC Lineup, I would like to post an introduce to all of you a little bit about XML. From reading this post, perhaps; we could answer several questions like what is XML? How can XML be used? What is its syntax, elements, attributes and validation.

A Brief Introduction to XML

What is XML? Just as how HTML actually means HyperText Markup Language, XML means Extensible Markup Language. Both HTML and XML are markup language and they are much alike, but they aren't the same. One obvious different between HTML and XML is tag, HTML has a predefined tags while XML doesn't. Even though both of them are markup languages, XML isn't a replacement for HTML.

Differences between HTML and XML

  • HTML tags are predefined, while XML tags are not predefined.
  • XML focuses on what data is, it is designed to store and transport data, while HTML is more on layout and interface with focus on displaying the data.
  • HTML is about displaying information, while XML is about carrying information

XML doesn't do anything, it itself is just a plain text

The sole reasons why XML was created was to structure, store, and transport information..

Following are one example of XML taken from kirupa.com

What does it mean by plain text? By plain text, it means that it is nothing special, it's just the same with what we write in our notepad, which means, software which could handle plain text document will always occur to support XML. Though, XML tags could be handled specially if the software is XML-aware. The nature of the application will determine the functional meaning of the XML tags.

Tags

This section is based on the example below, note from Jani to Tove.

<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

We told just now that XML's tags, unlike the HTML's tag, are not predefined. It means that the tags are our invention, we could invent our own tags when we use XML. There is, perhaps; no XML standard which define general tags. e.g. <to> and <from> from the example aren't defined by any XML standard, and could be interchanged without any problem facing the content.

Example

<note>
<from>Tove</from>
<to>Jani</to>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

XML Tag are case sensitive

  • XML elements are defined with XML non-predefined tags
  • The tags are case sensitive
  • In XML, <letter> is not the same with <Letter>, while in HTML it is the same.
  • Opening and closing tags should be written with the same case
    • <Message>...</message> is incorrect
    • <message> ...</message> is correct

So if XML is not a replacement for HTML, what is XML?

XML is not HTML, but XML is complement to HTML, which means that XML is used to interoperate with HTML, with XML functioning to transport data, and HTML functioning to display the data.

XML carries data without ever having specific dependence with hardware and software

XML Syntax Rules

  • All XML must have closing tag
    • "<message>...</message>" this is correct
    • "<message>...  " this is incorrect
  • In XML, it is illegal to omit the closing tag
  • XML Elements must be nested
    • <i><o>...</o></i> this is correct
    • <i><o>...</i></o> this is incorrect
  • XML Elements must contain parent/root element
    • e.g.
      <root>
      <child>
      <subchild>...</subchild>
      </child>
      </root>
  • XML attributes must be quoted

No comments:

Post a Comment