XML.php

Go to the documentation of this file.
00001 <?php
00002 
00021 class Auth_Yadis_XMLParser {
00033     function init($xml_string, $namespace_map)
00034     {
00035         if (!$this->setXML($xml_string)) {
00036             return false;
00037         }
00038 
00039         foreach ($namespace_map as $prefix => $uri) {
00040             if (!$this->registerNamespace($prefix, $uri)) {
00041                 return false;
00042             }
00043         }
00044 
00045         return true;
00046     }
00047 
00061     function registerNamespace($prefix, $uri)
00062     {
00063         // Not implemented.
00064     }
00065 
00076     function setXML($xml_string)
00077     {
00078         // Not implemented.
00079     }
00080 
00094     function evalXPath($xpath, $node = null)
00095     {
00096         // Not implemented.
00097     }
00098 
00107     function content($node)
00108     {
00109         // Not implemented.
00110     }
00111 
00121     function attributes($node)
00122     {
00123         // Not implemented.
00124     }
00125 }
00126 
00136 class Auth_Yadis_domxml extends Auth_Yadis_XMLParser {
00137     function Auth_Yadis_domxml()
00138     {
00139         $this->xml = null;
00140         $this->doc = null;
00141         $this->xpath = null;
00142         $this->errors = array();
00143     }
00144 
00145     function setXML($xml_string)
00146     {
00147         $this->xml = $xml_string;
00148         $this->doc = @domxml_open_mem($xml_string, DOMXML_LOAD_PARSING,
00149                                       $this->errors);
00150 
00151         if (!$this->doc) {
00152             return false;
00153         }
00154 
00155         $this->xpath = $this->doc->xpath_new_context();
00156 
00157         return true;
00158     }
00159 
00160     function registerNamespace($prefix, $uri)
00161     {
00162         return xpath_register_ns($this->xpath, $prefix, $uri);
00163     }
00164 
00165     function &evalXPath($xpath, $node = null)
00166     {
00167         if ($node) {
00168             $result = @$this->xpath->xpath_eval($xpath, $node);
00169         } else {
00170             $result = @$this->xpath->xpath_eval($xpath);
00171         }
00172 
00173         if (!$result) {
00174             $n = array();
00175             return $n;
00176         }
00177 
00178         if (!$result->nodeset) {
00179             $n = array();
00180             return $n;
00181         }
00182 
00183         return $result->nodeset;
00184     }
00185 
00186     function content($node)
00187     {
00188         if ($node) {
00189             return $node->get_content();
00190         }
00191     }
00192 
00193     function attributes($node)
00194     {
00195         if ($node) {
00196             $arr = $node->attributes();
00197             $result = array();
00198 
00199             if ($arr) {
00200                 foreach ($arr as $attrnode) {
00201                     $result[$attrnode->name] = $attrnode->value;
00202                 }
00203             }
00204 
00205             return $result;
00206         }
00207     }
00208 }
00209 
00219 class Auth_Yadis_dom extends Auth_Yadis_XMLParser {
00220     function Auth_Yadis_dom()
00221     {
00222         $this->xml = null;
00223         $this->doc = null;
00224         $this->xpath = null;
00225         $this->errors = array();
00226     }
00227 
00228     function setXML($xml_string)
00229     {
00230         $this->xml = $xml_string;
00231         $this->doc = new DOMDocument;
00232 
00233         if (!$this->doc) {
00234             return false;
00235         }
00236 
00237         if (!@$this->doc->loadXML($xml_string)) {
00238             return false;
00239         }
00240 
00241         $this->xpath = new DOMXPath($this->doc);
00242 
00243         if ($this->xpath) {
00244             return true;
00245         } else {
00246             return false;
00247         }
00248     }
00249 
00250     function registerNamespace($prefix, $uri)
00251     {
00252         return $this->xpath->registerNamespace($prefix, $uri);
00253     }
00254 
00255     function &evalXPath($xpath, $node = null)
00256     {
00257         if ($node) {
00258             $result = @$this->xpath->query($xpath, $node);
00259         } else {
00260             $result = @$this->xpath->query($xpath);
00261         }
00262 
00263         $n = array();
00264 
00265         if (!$result) {
00266             return $n;
00267         }
00268 
00269         for ($i = 0; $i < $result->length; $i++) {
00270             $n[] = $result->item($i);
00271         }
00272 
00273         return $n;
00274     }
00275 
00276     function content($node)
00277     {
00278         if ($node) {
00279             return $node->textContent;
00280         }
00281     }
00282 
00283     function attributes($node)
00284     {
00285         if ($node) {
00286             $arr = $node->attributes;
00287             $result = array();
00288 
00289             if ($arr) {
00290                 for ($i = 0; $i < $arr->length; $i++) {
00291                     $node = $arr->item($i);
00292                     $result[$node->nodeName] = $node->nodeValue;
00293                 }
00294             }
00295 
00296             return $result;
00297         }
00298     }
00299 }
00300 
00301 global $__Auth_Yadis_defaultParser;
00302 $__Auth_Yadis_defaultParser = null;
00303 
00313 function Auth_Yadis_setDefaultParser(&$parser)
00314 {
00315     global $__Auth_Yadis_defaultParser;
00316     $__Auth_Yadis_defaultParser =& $parser;
00317 }
00318 
00319 function Auth_Yadis_getSupportedExtensions()
00320 {
00321     return array(
00322                  'dom' => array('classname' => 'Auth_Yadis_dom',
00323                        'libname' => array('dom.so', 'dom.dll')),
00324                  'domxml' => array('classname' => 'Auth_Yadis_domxml',
00325                        'libname' => array('domxml.so', 'php_domxml.dll')),
00326                  );
00327 }
00328 
00335 function &Auth_Yadis_getXMLParser()
00336 {
00337     global $__Auth_Yadis_defaultParser;
00338 
00339     if (isset($__Auth_Yadis_defaultParser)) {
00340         return $__Auth_Yadis_defaultParser;
00341     }
00342 
00343     $p = null;
00344     $classname = null;
00345 
00346     $extensions = Auth_Yadis_getSupportedExtensions();
00347 
00348     // Return a wrapper for the resident implementation, if any.
00349     foreach ($extensions as $name => $params) {
00350         if (!extension_loaded($name)) {
00351             foreach ($params['libname'] as $libname) {
00352                 if (@dl($libname)) {
00353                     $classname = $params['classname'];
00354                 }
00355             }
00356         } else {
00357             $classname = $params['classname'];
00358         }
00359         if (isset($classname)) {
00360             $p = new $classname();
00361             return $p;
00362         }
00363     }
00364 
00365     if (!isset($p)) {
00366         trigger_error('No XML parser was found', E_USER_ERROR);
00367     } else {
00368         Auth_Yadis_setDefaultParser($p);
00369     }
00370 
00371     return $p;
00372 }
00373 
00374 ?>

Generated on Thu Feb 19 15:02:21 2009 for OXID eShop CE by  doxygen 1.5.5