0

I'm currently working with Google RSS feeds. Following is my xml response.

<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<title>Example</title>
<link>https://www.example.com</link>
<item>
   <g:id>25</g:id>
   <g:title>Item 1</g:title>
   <g:description>Lorem Ipsum</g:description>
</item>
<item>
   <g:id>26</g:id>
   <g:title>Item 2</g:title>
   <g:description>Lorem Ipsum</g:description>
</item>
</channel>
</rss>

Now, I want to delete Item having g:id 25. Please guide how to delete that node from xml code. Thanks in advance. Tried using following code but $nodelist returning 0 length.

    $dom = new DomDocument;
    $id = 25;
    $productId = $id;
    $dom->loadXML($filecontent);
    // Locate the old product node to modify
    $xpath = new DOMXpath($dom);
    $nodelist = $xpath->query("/channel/item/g:id={$productId}");
    $oldnode = $nodelist->item(0);
    // Remove
    $oldnode->removeChild($oldnode);
    echo $dom->saveXML();//Done output XML 
Pritika
  • 296
  • 1
  • 17
  • Look into http://php.net/domdocument, that allows you to manipulate XML. – Dormilich Jun 04 '18 at 12:35
  • You will also need to look into how to access nodes in namespaces - https://stackoverflow.com/questions/6858136/accessing-namespace-colon-nodes-in-xml-with-simplexml-php may help. – Nigel Ren Jun 04 '18 at 12:48

0 Answers0