How to serialize an object to XML with dynamic element's attribute?

How can I read an XML object file with PHP?

  • I am trying to read xml object file and store in an array for example my object file is as follow <object> <deal> <title>deal title</title> <description>deal description</description> <deal> </object> I want to read the above object file and get output likeĀ  xml file as follows <deal> <title>deal title</title> <description>deal description</description> <deal>

  • Answer:

    Try using simpleXml. It can read from a string or a file.

John Cleary at Quora Visit the source

Was this solution helpful to you?

Other answers

You can use SimpleXML...

Dharmalingam Arumugam

// convert XML to an array using JSON encode/decode trick $array = json_decode(json_encode(simplexml_load_string($xml_string)),true);

Nicholas de Jong

SimpleXML( ) will do the trick. Use it to parse the XML document and then delete the node you want using parent/child remove functions.

Caio Bianchi

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.