Source code for file /openid/Services/Yadis/XML.php
Documentation is available at XML.php
* XML-parsing classes to wrap the domxml and DOM extensions for PHP 4
* The base class for wrappers for available PHP XML-parsing
* extensions. To work with this Yadis library, subclasses of this
* class MUST implement the API as defined in the remarks for this
* class. Subclasses of Services_Yadis_XMLParser are used to wrap
* particular PHP XML extensions such as 'domxml'. These are used
* internally by the library depending on the availability of
* supported PHP XML extensions.
* Initialize an instance of Services_Yadis_XMLParser with some
* XML and namespaces. This SHOULD NOT be overridden by
* @param string $xml_string A string of XML to be parsed.
* @param array $namespace_map An array of ($ns_name => $ns_uri)
* to be registered with the XML parser. May be empty.
* @return boolean $result True if the initialization and
* namespace registration(s) succeeded; false otherwise.
function init($xml_string, $namespace_map)
if (!$this->setXML($xml_string)) {
foreach ($namespace_map as $prefix =>
$uri) {
* Register a namespace with the XML parser. This should be
* overridden by subclasses.
* @param string $prefix The namespace prefix to appear in XML tag
* @param string $uri The namespace URI to be used to identify the
* @return boolean $result True if the registration succeeded;
* Set this parser object's XML payload. This should be
* overridden by subclasses.
* @param string $xml_string The XML string to pass to this
* @return boolean $result True if the initialization succeeded;
* Evaluate an XPath expression and return the resulting node
* list. This should be overridden by subclasses.
* @param string $xpath The XPath expression to be evaluated.
* @param mixed $node A node object resulting from a previous
* evalXPath call. This node, if specified, provides the context
* for the evaluation of this xpath expression.
* @return array $node_list An array of matching opaque node
* objects to be used with other methods of this parser class.
* Return the textual content of a specified node.
* @param mixed $node A node object from a previous call to
* @return string $content The content of this node.
* Return the attributes of a specified node.
* @param mixed $node A node object from a previous call to
* @return array $attrs An array mapping attribute names to
* This concrete implementation of Services_Yadis_XMLParser implements
* the appropriate API for the 'domxml' extension which is typically
* packaged with PHP 4. This class will be used whenever the 'domxml'
* extension is detected. See the Services_Yadis_XMLParser class for
* details on this class's methods.
$this->xml =
$xml_string;
$this->doc =
@domxml_open_mem($xml_string, DOMXML_LOAD_PARSING,
$this->xpath =
$this->doc->xpath_new_context();
return xpath_register_ns($this->xpath, $prefix, $uri);
$result =
@$this->xpath->xpath_eval($xpath, $node);
$result =
@$this->xpath->xpath_eval($xpath);
return $node->get_content();
$arr =
$node->attributes();
foreach ($arr as $attrnode) {
$result[$attrnode->name] =
$attrnode->value;
* This concrete implementation of Services_Yadis_XMLParser implements
* the appropriate API for the 'dom' extension which is typically
* packaged with PHP 5. This class will be used whenever the 'dom'
* extension is detected. See the Services_Yadis_XMLParser class for
* details on this class's methods.
$this->xml =
$xml_string;
$this->doc =
new DOMDocument;
if (!@$this->doc->loadXML($xml_string)) {
$this->xpath =
new DOMXPath($this->doc);
return $this->xpath->registerNamespace($prefix, $uri);
$result =
@$this->xpath->query($xpath, $node);
$result =
@$this->xpath->query($xpath);
for ($i =
0; $i <
$result->length; $i++
) {
$n[] =
$result->item($i);
return $node->textContent;
$arr =
$node->attributes;
for ($i =
0; $i <
$arr->length; $i++
) {
$result[$node->nodeName] =
$node->nodeValue;
$__Services_Yadis_defaultParser =
null;
* Set a default parser to override the extension-driven selection of
* available parser classes. This is helpful in a test environment or
* one in which multiple parsers can be used but one is more
* @param Services_Yadis_XMLParser $parser An instance of a
* Services_Yadis_XMLParser subclass.
global $__Services_Yadis_defaultParser;
$__Services_Yadis_defaultParser =
& $parser;
$GLOBALS['__Services_Yadis_xml_extensions'] =
array(
'dom' =>
array('classname' =>
'Services_Yadis_dom',
'libname' =>
array('dom.so', 'dom.dll')),
'domxml' =>
array('classname' =>
'Services_Yadis_domxml',
'libname' =>
array('domxml.so', 'php_domxml.dll')),
* Returns an instance of a Services_Yadis_XMLParser subclass based on
* the availability of PHP extensions for XML parsing. If
* Services_Yadis_setDefaultParser has been called, the parser used in
* that call will be returned instead.
global $__Services_Yadis_defaultParser,
$__Services_Yadis_xml_extensions;
if (isset
($__Services_Yadis_defaultParser)) {
return $__Services_Yadis_defaultParser;
// Return a wrapper for the resident implementation, if any.
foreach ($__Services_Yadis_xml_extensions as $name =>
$params)
foreach ($params['libname'] as $libname) {
$classname =
$params['classname'];
$classname =
$params['classname'];