01/10/2018, 16:20

Lỗi php với DOMDocument

Mình có đoạn code:

$xml_src = 'sitemap.xml';
        $dom = new DOMDocument();
        $dom->validateOnParse = true;
        $dom->load($xml_src); 
$parent_path = "urlset";
        $parent = $dom->getElementsByTagName("urlset"); 
        $selector = new DOMXPath($dom);
        $next = $selector->query("//*[@id='".$article['id']."']");
        if($next->length > 0) {
            $actived_date = date('Y-m-dTH:i:sP', strtotime($article['actived_date']));
    $dom->getElementById($article["id"])->item(0)->getElementsByTagName('loc')->item(0)->childNodes->item(0)->nodeValue='https://hotavn.ga/'.$article["friendly"].'_'.$article["id"];
    $dom->getElementById($article["id"])->item(0)->getElementsByTagName('lastmod')->item(0)->childNodes->item(0)->nodeValue=$actived_date;
    $dom->save($xml_src);
        }

file xml

<url id="100418">
<loc>
https://hotavn.ga/kham-pha-"sieu-xe"-cua-cac-kieu-ong-gia-noel-ma-ban-chua-biet._100418.html
</loc>
<lastmod>2016-12-24T03:19:13+00:00</lastmod>
<changefreq>always</changefreq>
<priority>0.8</priority>
</url>
<url id="100415">
<loc>https://hotavn.ga/gia-dinh-english_100415.html</loc>
<lastmod>2016-12-16T12:26:02+00:00</lastmod>
<changefreq>always</changefreq>
<priority>0.8</priority>
</url>

Khi mình thực hiện thì nó lỗi?

Lỗi: Fatal error: Call to a member function item() on null

Hà Hải Nam viết 18:36 ngày 01/10/2018

Lỗi gi bạn nhỉ? Ghi đầy đủ ra nha.

Bài liên quan
0