Array to Xml Conversion and Xml to Array Convert in PHP

array to xml to array

Hi Geeks,
Today i am sharing you a code snippet for converting xml to array with attributes also and vice versa (Convert array to xml). This class is very useful to parse rss feed and to make rss feed in php programming.

In this code snippet we have made a class to convert array XML using php code and also retaining its attibues stored into array . It returns the XML in form of DOMDocument class for further manipulation. This class will throw exception if the tag name or attribute name has illegal characters.

Usage of this class:

A. Steps for Convert Array to Xml

1.Create a class named Array2XML with following code in file Array2XML.php

2. Now Include the class

3. Defining Array or get it from database then call the createXML method for generating xml file

Now Call createXML method as following

B. Steps for Convert Xml to Array

1. Define the xml oe get the xml string into a varribale

2.Now call the XML_TO_ARR function as following




You May Also Like

About the Author: Admin

We are the Web Developer, technical writer and a blogger from jaipur and worked with PHP,Mysql,JavaScript,Node Js,Angular Js,Jquery,JQuery Mobile,.Net,Sql Server etc., but his language of choice is PHP & JAVASCRIPT. You can learn more and discussion with us at w3school