Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the number of <code>ul</code>s is known, you can add the information like this:</p> <pre><code>$NEW_XML-&gt;ProductDescription-&gt;ul[2]-&gt;addChild('li', 'Valid in US'); </code></pre> <p>This assumes that <code>$NEW_XML</code> is pointing at the <code>Products</code>-Element. To <em>always</em> get the last <code>ul</code> you have to count them first:</p> <pre><code>$desc = $NEW_XML-&gt;ProductDescription; $count = count($desc-&gt;ul); $desc-&gt;ul[$count - 1]-&gt;addChild('li', 'Valid in US'); </code></pre> <p>Then you can just output or save <code>$xml-&gt;asXML()</code>.</p> <p><strong>Update</strong>:</p> <p>Here is the complete code I used, updated according to my assumption from my last comment, maybe this helps:</p> <pre><code>&lt;?php $xmldata = &lt;&lt;&lt;ENDXML &lt;xmldata&gt; &lt;Products&gt; &lt;Product&gt; &lt;ProductCode&gt;ACODE&lt;/ProductCode&gt; &lt;ProductID&gt;1234&lt;/ProductID&gt; &lt;ProductName&gt;PRODUCTTITLE&lt;/ProductName&gt; &lt;ProductDescription&gt; &lt;h1&gt;Stuff&lt;/h1&gt;&lt;p&gt;description&lt;/p&gt;&lt;hr /&gt;&lt;strong&gt;Features &amp;amp; Benefits&lt;/strong&gt; &lt;ul&gt;&lt;li&gt;feat&lt;/li&gt;&lt;li&gt;feat&lt;/li&gt;&lt;li&gt;feat&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt; &lt;strong&gt;Specifications&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;spec&lt;/li&gt;&lt;li&gt;spec&lt;/li&gt;&lt;li&gt;spec&lt;/li&gt;&lt;/ul&gt; &lt;hr /&gt;&lt;strong&gt;Warranty Information for a certain product&lt;/strong&gt; &lt;ul&gt;&lt;li&gt;3 Years Parts&lt;/li&gt;&lt;li&gt;3 Years Labor&lt;/li&gt;&lt;/ul&gt;&lt;div&gt; &lt;a href="/ahref" target="_blank"&gt;See more products from MFG &lt;/a&gt;&lt;/div&gt; &lt;/ProductDescription&gt; &lt;ProductManufacturer&gt;MFG&lt;/ProductManufacturer&gt; &lt;/Product&gt; &lt;Product&gt; &lt;ProductCode&gt;ANOTHERCODE&lt;/ProductCode&gt; &lt;ProductID&gt;98765&lt;/ProductID&gt; &lt;ProductName&gt;PRODUCTTITLE 2&lt;/ProductName&gt; &lt;ProductDescription&gt; &lt;h1&gt;Stuff&lt;/h1&gt;&lt;p&gt;description&lt;/p&gt;&lt;hr /&gt;&lt;strong&gt;Features &amp;amp; Benefits&lt;/strong&gt; &lt;ul&gt;&lt;li&gt;feat&lt;/li&gt;&lt;li&gt;feat&lt;/li&gt;&lt;li&gt;feat&lt;/li&gt;&lt;/ul&gt;&lt;hr /&gt; &lt;strong&gt;Specifications&lt;/strong&gt;&lt;ul&gt;&lt;li&gt;spec&lt;/li&gt;&lt;li&gt;spec&lt;/li&gt;&lt;li&gt;spec&lt;/li&gt;&lt;/ul&gt; &lt;hr /&gt; &lt;strong&gt;Warranty Information for a certain product&lt;/strong&gt; &lt;ul&gt;&lt;li&gt;3 Years Parts&lt;/li&gt;&lt;li&gt;3 Years Labor&lt;/li&gt;&lt;/ul&gt;&lt;div&gt; &lt;a href="/ahref" target="_blank"&gt;See more products from MFG &lt;/a&gt;&lt;/div&gt; &lt;/ProductDescription&gt; &lt;ProductManufacturer&gt;MFG&lt;/ProductManufacturer&gt; &lt;/Product&gt; &lt;/Products&gt; &lt;/xmldata&gt; ENDXML; $xml = simplexml_load_string($xmldata); foreach ($xml-&gt;Products-&gt;Product as $product) { $description = $product-&gt;ProductDescription; $count = count($description-&gt;ul); $description-&gt;ul[$count-1]-&gt;addChild('li', 'Valid in US'); } echo $xml-&gt;asXML(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload