Pages

Friday, 6 July 2012

PHP and XML

Let us first of all know what is XML.We easily say XML is Extened Markup Language which somehow feels like HTML which is also a markup language but much different from XML.Let us  now fhift to XML.
XML is a markup language that looks a lot like HTML. An XML document is plain text and contains tags delimited by < and >.There are two big differences between XML and HTML:
1.XML doesn't define a specific set of tags you must use.
2.XML is extremely picky about document structure.



In XML all the tags are "invented" by the author of the XML document.This is because the XML language has no predefined tag but tags used in HTML are predefined. HTML documents can only use tags defined in the HTML standard (like <p>, <h1>, etc.).XML allows the author to define his/her own tags and his/her own document structure.
XML is Not a Replacement for HTML but is a complement to HTML.XML is very strict when it comes to document structure. HTML let us play fast and loose with some opening and closing tags. But this is not the case with XML.



XML is used in many aspects of web development, often to simplify data storage and sharing.
1.XML Separates Data from HTML
2.XML Simplifies Data Sharing
3.XML Simplifies Data Transport
4.XML Simplifies Platform Changes
5.XML Makes our Data More Available
6.XML is Used to Create New Internet Languages

 

Now we have studied uses of XML let us now talk about its syntax rules:-
XML Syntax Rules

1.All XML Elements Must Have a Closing Tag.
For example:- <Message>This is incorrect</message>

2.XML Tags are Case Sensitive.

For example:-
<Msg>This is incorrect</msg>
 <msg>This is correct</msg>


3.XML Elements Must be Properly Nested.
For example:-
<b><i>This text is bold and italic</b></i>
//this is correct statement in html but incorrect in xml
4.XML Documents Must Have a Root Element.
XML documents contains one element that is the parent of all other elements. This element is called the root element.
The suntax is:-
<root>
<child>
<subchild>.....</subchild>
</child>


</root>

 
Now we take a simple example of xml:-


<bookstore> //it is simple root element
<book category="CHILDREN">
<title>Harry Potter</title> //subchild

<author>J K. Rowling</author>  //subchild
<year>2005</year>
          //subchild
  <price>29.99</price>    
//subchild
</book>
<book category="WEB">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>

No comments:

Post a Comment