Advertisement
Googleinurl

Percorrer XML

Aug 30th, 2012
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. $oldSetting = libxml_use_internal_errors( true );
  2. libxml_clear_errors();
  3.  
  4. $html = new DOMDocument();
  5. $html->loadHtmlFile($_POST['url']);
  6.  
  7. $xpath = new DOMXPath( $html );
  8. $elements = $xpath->query( "//table[@class='maintable']/tr//a" );
  9.  
  10. foreach ( $elements as $item ) {
  11.   $newDom = new DOMDocument;
  12.   $newDom->appendChild($newDom->importNode($item,true));
  13.  
  14.   $xpath = new DOMXPath( $newDom );
  15.  
  16.   foreach ($item->attributes as $attribute) {
  17.  
  18.     for ($node = $item->firstChild; $node !== NULL;
  19.          $node = $node->nextSibling) {
  20.       if (($attribute->nodeName =='valign') && ($attribute->nodeValue=='href'))
  21.       {
  22.         //print($node->nodeValue);
  23.         echo $attribute->nodeValue;
  24.       }
  25.       else
  26.       {
  27.         //print("<br>".$node->nodeValue);
  28.         echo $attribute->nodeValue.'0555';
  29.       }
  30.     }
  31.     print("<br>");
  32.   }
  33. }
  34.  
  35. libxml_clear_errors();
  36. libxml_use_internal_errors($oldSetting);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement