Advertisement
Guest User

swegylaggy

a guest
Oct 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. class XMLStuff
  2. {
  3.     function get_xPath($xmlFileName = 'news.xml')
  4.     {
  5.         $xmlDocument = new DOMDocument();
  6.         // Load the XML document
  7.         $xmlDocument->load($xmlFileName);
  8.         $xPath = new DOMXPath($xmlDocument);
  9.         return $xPath;
  10.     }
  11.  
  12.     function xml2array($xmlObject, $out = array())
  13.     {
  14.         foreach ((array)$xmlObject as $index => $node)
  15.             $out[$index] = (is_object($node)) ? xml2array($node) : $node;
  16.  
  17.         return $out;
  18.     }
  19.  
  20.     function setQuery($xmlFileName = 'news.xml'){
  21.         $xPathQuery = "/articles/article";
  22.         // Execute the query
  23.         $queryNodes = $this->get_xPath($xmlFileName)->query($xPathQuery);
  24.  
  25.         return $queryNodes;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement