Php kullanarak xml Veli etiketi kaldırmak

2 Cevap php

Ben bir xml dosya düzenleme bir sorunla karşı karşıya duyuyorum.

<?xml version="1.0" encoding="UTF-8"?>

  <urlset>

  <url>
   <loc>http://www.abc.com/</loc>
   <lastmod>2010-04-17T17:23:57+00:00</lastmod>
   <changefreq>daily</changefreq>
   <priority>0.50</priority>
  </url>
  <url>
   <loc>http://www.abc.com/</loc>
   <lastmod>2010-04-17T17:23:57+00:00</lastmod>
   <changefreq>daily</changefreq>
   <priority>0.50</priority>
  </url>

</urlset>

I want to add one more set of records starting with <url> with its other tags, (i.e) "loc,lastmod,changefreq,priority" and than save the xml file.For adding the new record i need to remove the parent closing tag that is </urlset> and than add the rest of the records and close the main tag.
Can anyone please help me solving my problem.Thanks

2 Cevap

Yaklaşım # 1: Evet, urlset düğümü almak için SimpleXMLElement :: xpath kullanın ve sonra istediğiniz düğümleri eklemek SimpleXMLElement :: addChild kullanabilirsiniz.

Link: http://php.net/manual/en/book.simplexml.php

Yaklaşım # 2 (easy one but not recommended): Kullanın str_replace "" Bu yol:

$xmlDoc = str_replace("</urlset>", "<!-- YOURXML--></urlset>", $xmlDoc);

Her iki şekilde de zor olmamalı.

Ben sadece daha iyi bir fikir için bu url görmek için öneririz

http://www.ibm.com/developerworks/library/os-xmldomphp/