0

How to some div value export to xml with tag in php code.
I search my site and from div value export to external xml file.

?php
$some_link = 'http://www.popusti.rs/';
$tagName = 'div';
$attrName = 'class';
$attrValue = 'offer-list-item';

$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
@$dom->loadHTMLFile($some_link);

$html = getTags( $dom, $tagName, $attrName, $attrValue );
echo $html;

function getTags( $dom, $tagName, $attrName, $attrValue ){
    $html = '';
    $domxpath = new DOMXPath($dom);
    $newDom = new DOMDocument;
    $newDom->formatOutput = true;

    $filtered = $domxpath->query("//$tagName" . '[@' . $attrName . "='$attrValue']");
     $filtered =  $domxpath->query('//div[@class="offer-list-item"]');
    // '//' when you don't know 'absolute' path


    $i = 0;
    while( $myItem = $filtered->item($i++) ){
        $node = $newDom->importNode( $myItem, true );   
        $newDom->appendChild($node);                   
    }
    $html = $newDom->savehtml();
    return $html;
}

?>
2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by diafol
0

How to some div value export to xml with tag in php code.
I search my site and from div value export to external xml file.

This doesn't make much sense. Perhaps if you rephrase the question.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.