1

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

**

View.xml

**

> <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

https://www.php.net/manual/en/simplexmlelement.asxml.php

1 Answer 1

2

Try Somthing like this..

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

For more information check this link

https://www.php.net/manual/en/simplexmlelement.asxml.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.