I heard about XML 7-8 years ago when I started doing web development. I remember when I tried to learn it for the first time I never understood anything about it but Later when I worked on some web services then I came to know what XML is all about.  Here I am trying to explain very basic of XML and how to parse XML in PHP.  If you are a Fresher then you are at a write place to learn about XML. XML full form is Extensible Markup Language. it is use to transport data and it is both  human- and machine-readable. In XML we can create user defined tags. XML Make things simple such as data sharing, data transport, platform changes and data availability. EG: For Mobile app data between Mobile and Database is transported through the XML or JSON.  I will write a Post for JSON as well.

Well Formed XML Documents must have

  • Root element
  • Closing tag
  • Tags are case sensitive
  • XML elements must be properly nested
  • XML attribute values must be quoted

XML Example

<?xml version='1.0'?> 
<name>Technologies Axis</name> 
<name>Technologies Axis</name>
i saved a file as technologiesaxis.xml

Here you can see user defined tags. Now a days XML is playing an important role. Every Web developer must be familiar with the XML.

Now You will learn how to parse it in PHP

 $companyInfo = simplexml_load_file('technologiesaxis.xml');
 foreach ($companyInfo as $company) {
 echo $title=$company->name." - ".$company->city." - ".$company->phone."<br/>"; 
output :
Technologies Axis - Pickering - 647-575-9815
Technologies Axis - Phagwara - 98158-81165
simplexml_load_file() is a magical function available in PHP. In this you you can get the data from the xml. 
There is lot more available in XML. I am trying to give you the basic example of xml. I hope it will be helpful. In next coming days
I will try to explain more about xml by creating a web service for the mobile.

Read More




You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *