I’m building an application on Zend Framework and now there is requirement to manipulate a xml file and change few content of it so that I could use the xml as a request file to get a response from other server. Now after a googling I’ve seen popularity of simplexml over others but I’m not sure which implementation would be better for Zend Framework. Any suggestions would be very helpful.
My request XML file is like this:
<?xml version="1.0" encoding="UTF-8"?>
<aa>
<bb>
<cc>
<dd>
<ee/>
</dd>
<ff>
<Identification _FirstName="******" _LastName="*****" _Num="********">
<gg/>
</Identification>
</ff>
</cc>
</bb>
</aa>
Now, I need to be able to change the value of _FirstName, _LastName and Num. Which XML manipulation method should I use with Zend Framework for this and how?
Thanks in advance.
Zend Framework provides the
Zend_DOMlibrary, which builds upon PHP’s native DOM extension (linkage mine):If you don’t need Selectors, you don’t need
Zend_DOM, but can use any of the native XML extensions.How to use
Zend_DOMis explained in the reference guide:So in a nutshell:
$identification will then contain a
DOMElementwhich you can change like any otherDOMElement. There is ample examples on StackOverflow on how to change values in an XML file, so I won’t repeat that here.After you changed the
DOMElement, you need to get hold of theDOMDocumentto serialize the changed document back into XML. To do so, you can useFor an overview of X(HT)ML parsers see