Use SimpleXml in php to add additional data into element and save

shina

New Member
I am using simplexml to load an API URL in the form of an XML through php. In the \[code\]ProductDescription\[/code\] element it contains html that I would like to append onto in the warranty section.I would like to add \[code\]<li>Valid in US</li>\[/code\] in the \[code\]ProductDescription\[/code\] element before the LAST \[code\]</ul>\[/code\] tag:\[code\] <xmldata> <Products> <ProductCode>ACODE</ProductCode> <ProductID>1234</ProductID> <ProductName>PRODUCTTITLE</ProductName> <ProductDescription> <h1>Stuff</h1><p>description</p><hr /><strong>Features & Benefits</strong> <ul><li>feat</li><li>feat</li><li>feat</li></ul><hr /><strong>Specifications</strong><ul><li>spec</li><li>spec</li><li>spec</li></ul> <hr /><strong>Warranty Information for a certain product</strong> <ul><li>3 Years Parts</li><li>3 Years Labor</li></ul><div> <a href="http://stackoverflow.com/ahref" target="_blank">See more products from MFG </a></div> </ProductDescription> <ProductManufacturer>MFG</ProductManufacturer> </Products> </xmldata>\[/code\]Now all I can do is get the bare code out of the ProductDescription, I need to know of a way to add that \[code\]list\[/code\] tag to end of the last \[code\]ul\[/code\] tag before posting or displaying. Here is my partial php:\[code\] foreach( $xml as $NEW_XML ) { $code = $NEW_XML->ProductCode; $name = $NEW_XML->ProductName; $desc = $NEW_XML->ProductDescription; $mfg = $NEW_XML->ProductManufacturer;echo "<textarea rows='13' cols='64' name='DESC' />" . $desc. "</textarea>"; }\[/code\]I am hoping I dont have to use REGex as it could be a pain (unless someone knows of a way). My inital thoughts would be to put it into a \[code\]<textarea>\[/code\] and simply posting it back to an xml, but if there is a way to get to save as an .xml directly that would be more effiecient.
 
Back
Top