/** * Parse an XML string (XRDS document) and return either a * Services_Yadis_XRDS object or null, depending on whether the * XRDS XML is valid. * * @param string $xml_string An XRDS XML string. * @return mixed $xrds An instance of Services_Yadis_XRDS or null, * depending on the validity of $xml_string */ function &parseXRDS($xml_string, $extra_ns_map = null) { $_null = null; if (!$xml_string) { return $_null; } $parser = Services_Yadis_getXMLParser(); $ns_map = Services_Yadis_getNSMap(); if ($extra_ns_map && is_array($extra_ns_map)) { $ns_map = array_merge($ns_map, $extra_ns_map); } if (!($parser && $parser->init($xml_string, $ns_map))) { return $_null; } // Try to get root element. $root = $parser->evalXPath('/xrds:XRDS[1]'); if (!$root) { return $_null; } if (is_array($root)) { $root = $root[0]; } $attrs = $parser->attributes($root); if (array_key_exists('xmlns:xrd', $attrs) && $attrs['xmlns:xrd'] != 'xri://$xrd*($v*2.0)') { return $_null; } else { if (array_key_exists('xmlns', $attrs) && preg_match('/xri/', $attrs['xmlns']) && $attrs['xmlns'] != 'xri://$xrd*($v*2.0)') { return $_null; } } // Get the last XRD node. $xrd_nodes = $parser->evalXPath('/xrds:XRDS[1]/xrd:XRD'); if (!$xrd_nodes) { return $_null; } $xrds = new Services_Yadis_XRDS($parser, $xrd_nodes); return $xrds; }
function detect_xml($r, &$out) { global $__Services_Yadis_xml_extensions; $out .= $r->h2('XML Support'); // Try to get an XML extension. $ext = Services_Yadis_getXMLParser(); if ($ext !== null) { $out .= $r->p('XML parsing support is present using the ' . $r->b(get_class($ext)) . ' interface.'); return true; } else { $out .= $r->p('XML parsing support is absent; please install one ' . 'of the following PHP extensions:'); foreach ($__Services_Yadis_xml_extensions as $name => $cls) { $out .= "<li>" . $r->b($name) . "</li>"; } return false; } }