Kaushal Prajapati Kaushal Prajapati - 10 months ago 56
PHP Question

Convert SimpleXMLElement object to XML format in php

one xml file view.xml

convert it into SimpleXMLElement Object after get parent node
it's child object need to convert into back in xml format in php




> <cards name="country-cards" model="core_country" title="Country" >
> <field name="name" />
> <field name="code" />
> <template><![CDATA[
> <div class="span12"><strong>{{name}}</strong></div> <div>
> <div class="span8">
> <span>{{name}}<br/>
> {{code}}<br/></span>
> </div></div>]]>
> </template>
> </cards>

**$xml = simplexml_load_file($xmlViewFilePath);**

foreach ($xml as $key=>$value) {

$value want to convert back in to xml formate


QUESTION: Any other simple way to achieve SimpleXMLElement Object to XML parsing and store into Database without any I/O operation?

Already used the php conversion mechanism which results in output as null in database link below



Try Somthing like this..

 $doc = new DOMDocument();
    $doc->formatOutput = TRUE;
    $xml = $doc->saveXML();

For more information check this link