What is SimpleXML in PHP

In this article I am going to explain about SimpleXML in PHP.
  • 2147

PHP SimpleXML

PHP Version 5 introduce simpleXML. SimpleXML handles the most common tasks and the main benefit of using SimpleXML, you do not have to worry about encoding and poorly formatted XML.

SimpleXML converts the XML document into an object:

  • Element

    Elements are converted to single attributes of the SimpleXMlElement. If in the one level, there is a more than one element, they are paced inside array.
     
  • Element data

    Text data from elements are converted to string.

Example of SimpleXML

To use SimpleXML ,follow the fallowing steps:

First create an XML file:

<?xml version="1.0" encoding="ISONO"?>

<note>

  <to>Mcn_Solution</to>

  <from>Dinesh</from>

  <heading>Singhr</heading>

  <body>Don't forget me this weekend!</body>

</note>


After it, create a PHP application:
 

<html>

<body>

 

<?php

$xml = simplexml_load_file("test.xml");

 

echo $xml->getName() . "<br />";

 

foreach($xml->children() as $child)

  {

  echo $child->getName() . ": " . $child . "<br />";

  }

?>

 

</body>

</html>


Output:

simplexml php.jpg

You may also want to read these related articles :
here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.