Jump to content

Xml To Array --- Array To Xml


harshpandya

Recommended Posts

Hi guys, I want to write a XML to Array --- Array to XML functions........So basically function should read entire XML and convert into an array. Then i can update the array and pass array to another function array2XML(array) so it will convert array to XML file. Can you guys give me any working examples......Appreciate it, Thanks,

Link to comment
Share on other sites

Are you doing it with html, asp or php?

Hi guys, I want to write a XML to Array --- Array to XML functions........So basically function should read entire XML and convert into an array. Then i can update the array and pass array to another function array2XML(array) so it will convert array to XML file. Can you guys give me any working examples......Appreciate it, Thanks,
Link to comment
Share on other sites

Hi guys, I want to write a XML to Array --- Array to XML functions........So basically function should read entire XML and convert into an array. Then i can update the array and pass array to another function array2XML(array) so it will convert array to XML file. Can you guys give me any working examples......Appreciate it, Thanks,
Before I goe crazy copy and pasting code let me say how I do it.I have three xml files, MENUS, RECORDS, ARTICLESI use asp VBscript server side to pull the database location then sort, filter and display the results with xslt and css.the links are formated with the xml record ID and name, catagory,the output on the html would be likewww.domainname.com/display?q=12&newspaper&Starsandstripeswhen the page loads again the url take the url and I break down into var'sthe asp would filter sort all RECORDS file for ID=12, I also use Newspapers and Stars and Stripes to variables also to be used in the keywords and titles of the html output.------------You case if using asp you could pull your nodes from one xml, then if selected you could use them as var's into a form to submit and those vaules could be written into a 2 nd xml file.-----------If you are not using asp and need php, you will need a php guru to explain how to do it in php.
Link to comment
Share on other sites

I am sorry - I use PHP, Can you please help?Appreciate it
Personally, I don't like the whole idea of XML2Array or vise versa. XML is richer than that.The closest you can go, without doing some very wacky stuff that's also going to deminish your XML, is to use SimpleXML.With it, you can go to elements as if they're PHP objects, and update them as you update variables or properties. For example, if your XML was
<?xml version='1.0' standalone='yes'?><movies> <movie>  <title>PHP: Behind the Parser</title>  <characters>   <character>	<name>Ms. Coder</name>	<actor>Onlivia Actora</actor>   </character>   <character>	<name>Mr. Coder</name>	<actor>El ActÓr</actor>   </character>  </characters>  <plot>   So, this language. It's like, a programming language. Or is it a   scripting language? All is revealed in this thrilling horror spoof   of a documentary.  </plot>  <great-lines>   <line>PHP solves all my web problems</line>  </great-lines>  <rating type="thumbs">7</rating>  <rating type="stars">5</rating> </movie></movies>

and was located at 'movies.xml', you can edit the first movie's title, and save it by doing:

$xml = 'movies.xml';$sxe = new SimpleXMLElement($xml, null, true);$sxe->movie[0]->title = 'PHP: Put the parser forward brother!!';//I'm not sure if this is needed, as I don't work with SimpleXML... I prefer DOM.file_put_contents($xml, $sxe->asXML());

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...