What is XML?
- XML stands for eXtensible Markup Language.
- Unlike HTML(Hyper Text Markup Language), XML is for carrying data and not for displaying data.
- XML is not a database, but it can store data.
Sample XML code
You can notice the first line of this document. Actually the XML document itself does not need it. That line is for the XML parser to identify this document as an XML file. We will discuss about ‘parser’ in the next post.
A well formatted XML document
- Every staring must have a matching ending tag.
- The elements must be properly nested. (The last opened tag must close first.)
- None of the special characters such as ‘<‘ and ‘&’ must not be in the values.
- A single root element must contain all the elements.
- Tags are case sensitive, so we need to use correct format for all starting and ending tags.
- The attribute values must be quoted.
Comments in XML
Empty elements in XML
Bur it is encouraged to avoid using attributes. Because,
- it gives a flat structure
- cannot have multiple values for a single attribute.
- hard to expand.
Assume we need to insert another mobile number for the student ‘Anne’. Using attributes it is not possible. Here is the solution for that.
In this example you can see ” tag has been introduced. In XML those elements must be wrapped with a single sub root element.
Namespaces in XML
And also we can use default namespace to avoid using the prefix every time in sub elements.
Hope to see you with the next XML session…