当前位置: 首页>>代码示例>>PHP>>正文


PHP DomDocument::loadXml方法代码示例

本文整理汇总了PHP中DomDocument::loadXml方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::loadXml方法的具体用法?PHP DomDocument::loadXml怎么用?PHP DomDocument::loadXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DomDocument的用法示例。


在下文中一共展示了DomDocument::loadXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: assertMatchesXpath

    protected function assertMatchesXpath($html, $expression, $count = 1)
    {
        $dom = new \DomDocument('UTF-8');
        try {
            // Wrap in <root> node so we can load HTML with multiple tags at
            // the top level
            $dom->loadXml('<root>'.$html.'</root>');
        } catch (\Exception $e) {
            return $this->fail(sprintf(
                "Failed loading HTML:\n\n%s\n\nError: %s",
                $html,
                $e->getMessage()
            ));
        }
        $xpath = new \DOMXPath($dom);
        $nodeList = $xpath->evaluate('/root'.$expression);

        if ($nodeList->length != $count) {
            $dom->formatOutput = true;
            $this->fail(sprintf(
                "Failed asserting that \n\n%s\n\nmatches exactly %s. Matches %s in \n\n%s",
                $expression,
                $count == 1 ? 'once' : $count . ' times',
                $nodeList->length == 1 ? 'once' : $nodeList->length . ' times',
                // strip away <root> and </root>
                substr($dom->saveHTML(), 6, -8)
            ));
        }
    }
开发者ID:usefulthink,项目名称:symfony,代码行数:29,代码来源:AbstractLayoutTest.php

示例2: parseString

 /**
  * Parse the given xml definition string and return a
  * Console_CommandLine instance constructed with the xml data.
  *
  * @param string $xmlstr the xml string to parse
  *
  * @return object a Console_CommandLine instance
  * @access public
  * @static
  */
 public static function parseString($xmlstr)
 {
     $doc = new DomDocument();
     $doc->loadXml($xmlstr);
     self::validate($doc);
     $root = $doc->childNodes->item(0);
     return self::_parseCommandNode($root, true);
 }
开发者ID:hnw,项目名称:php425,代码行数:18,代码来源:XmlParser.php

示例3: parseString

 private function parseString($xmlStr)
 {
     $document = new DomDocument();
     try {
         $document->loadXml($xmlStr);
     } catch (Exception $ex) {
     }
     return new XmlDataType($document);
 }
开发者ID:sigmadesarrollo,项目名称:logisoft,代码行数:9,代码来源:V3XmlReader.php

示例4: parseString

 /**
  * Parses the given xml definition string and returns a
  * Console_CommandLine instance constructed with the xml data.
  *
  * @param string $xmlstr The xml string to parse
  *
  * @return Console_CommandLine A parser instance
  */
 public static function parseString($xmlstr)
 {
     $doc = new DomDocument();
     $doc->loadXml($xmlstr);
     self::validate($doc);
     $nodes = $doc->getElementsByTagName('command');
     $root = $nodes->item(0);
     return self::_parseCommandNode($root, true);
 }
开发者ID:EmmanuelFernando,项目名称:rapport-stock-control,代码行数:17,代码来源:XmlParser.php

示例5: prettyPrint

 public function prettyPrint($code, $lang)
 {
     switch ($lang) {
         case 'json':
             return json_encode(json_decode($code), JSON_PRETTY_PRINT);
         case 'xml':
             $xml = new \DomDocument('1.0');
             $xml->preserveWhiteSpace = false;
             $xml->formatOutput = true;
             $xml->loadXml($code);
             return $xml->saveXml();
         default:
             return $code;
     }
 }
开发者ID:seydu,项目名称:CsaGuzzleBundle,代码行数:15,代码来源:GuzzleExtension.php

示例6: unmarshalRoot

 public static function unmarshalRoot($string)
 {
     $dom = new \DomDocument();
     $dom->loadXml($string);
     $xpath = new \DomXPath($dom);
     $query = "child::*";
     $childs = $xpath->query($query);
     $binding = array();
     foreach ($childs as $child) {
         $legko = new Bind();
         $lDom = new \DomDocument();
         $lDom->appendChild($lDom->importNode($child, true));
         $binding = $legko->unmarshal($lDom->saveXml());
     }
     return $binding;
 }
开发者ID:irfan-blackhawk,项目名称:XSD-to-PHP,代码行数:16,代码来源:SoapServer.php

示例7: parse

 public function parse($content, __Configuration &$configuration)
 {
     libxml_use_internal_errors(true);
     $dom = new DomDocument("1.0");
     $dom->loadXml($content);
     if ($dom->documentElement != null) {
         $this->_parseDomNode($dom->documentElement, $configuration);
     } else {
         $xml_content_array = preg_split('/[\\n\\r]+/', $content);
         $parse_errors = libxml_get_errors();
         $error_descriptions_array = array();
         foreach ($parse_errors as $_parse_error) {
             $error_descriptions_array[] = $this->_getReadableXMLErrorDescription($_parse_error, $xml_content_array);
         }
         $error_description = join("\n", $error_descriptions_array);
         libxml_clear_errors();
         throw new __ConfigurationException($error_description);
     }
 }
开发者ID:laiello,项目名称:lion-framework,代码行数:19,代码来源:XMLConfigurationStorage.class.php

示例8: parseResponse

 /**
  * Parse the response XML into an associative array of values.
  *
  * @param string response XML
  */
 protected function parseResponse($xml)
 {
     $dom = new \DomDocument();
     try {
         // Munge errors into exceptions
         set_error_handler('\\Pway\\Response::domErrorHandler');
         $dom->loadXml($xml);
         restore_error_handler();
     } catch (\DomException $e) {
         $this->error = self::ERROR_XML;
         $this->errorMessage = $e->getMessage();
     }
     if ($this->error) {
         return false;
     }
     foreach ($dom->firstChild->childNodes as $node) {
         $this->responseData[$node->nodeName] = $node->nodeValue;
     }
 }
开发者ID:bluedogtraining,项目名称:pway,代码行数:24,代码来源:Response.php

示例9: fetchAttributes

 /**
  * Fetches the necessary attribute information for
  * the defined media item.
  *
  * @return bool
  */
 protected function fetchAttributes()
 {
     if (ini_get('allow_url_fopen')) {
         $youtubeXml = @file_get_contents($this->apiUrl . '/' . $this->mediaId);
         if (isset($http_response_header) && strpos($http_response_header[0], '200') === false) {
             throw new ExternalMediaDriver_InvalidID('YouTube ID "' . $this->mediaId . '" does not exist');
         }
         $dom = new DomDocument();
         $dom->loadXml($youtubeXml);
         $xPath = new DomXPath($dom);
         // Gather all details
         $group = $xPath->query('//media:group')->item(0);
         $this->attributes['title'] = $xPath->query('media:title', $group)->item(0)->nodeValue;
         $this->attributes['description'] = $xPath->query('media:description', $group)->item(0)->nodeValue;
         $this->attributes['videoUrl'] = $xPath->query('media:content/@url[starts-with(., "http")]', $group)->item(0)->value;
         $this->attributes['thumbUrl'] = $xPath->query('media:thumbnail[position()=1]/@url', $group)->item(0)->value;
         return true;
     } else {
         return false;
     }
 }
开发者ID:jinshana,项目名称:tangocms,代码行数:27,代码来源:Youtube.php

示例10: getOsmChangeXml

 /**
  * Generate and return the OsmChange XML required to record the changes
  * made to the object in question.
  *
  * @return string
  * @link   http://wiki.openstreetmap.org/wiki/OsmChange
  */
 public function getOsmChangeXml()
 {
     $type = $this->getType();
     if ($this->dirty) {
         $version = $this->getVersion();
         $version++;
         $domd = new DomDocument();
         $domd->loadXml($this->getXml());
         $xpath = new DomXPath($domd);
         $nodelist = $xpath->query("//{$type}");
         $nodelist->item(0)->setAttribute('action', $this->action);
         $nodelist->item(0)->setAttribute('id', $this->getId());
         if (!is_null($this->changesetId)) {
             $nodelist->item(0)->setAttribute('changeset', $this->changesetId);
         }
         $tags = $xpath->query("//{$type}/tag");
         $set = array();
         for ($i = 0; $i < $tags->length; $i++) {
             $key = $tags->item($i)->getAttribute('k');
             $val = $tags->item($i)->getAttribute('v');
             $set[$key] = $val;
         }
         $diff = array_diff($this->getTags(), $set);
         // Remove existing tags
         for ($i = 0; $i < $tags->length; $i++) {
             $rkey = $tags->item($i)->getAttribute('k');
             if (isset($diff[$rkey])) {
                 $nodelist->item(0)->removeChild($tags->item($i));
             }
         }
         foreach ($diff as $key => $value) {
             $new = $domd->createElement('tag');
             $new->setAttribute('k', $key);
             $new->setAttribute('v', $value);
             $nodelist->item(0)->appendChild($new);
         }
         $xml = $domd->saveXml($nodelist->item(0));
         $xml = "<{$this->action}>{$xml}</{$this->action}>";
         return $this->osmChangeXml($xml);
     } elseif ($this->action == 'delete') {
         $xml = null;
         $domd = new DomDocument();
         $domd->loadXml($this->getXml());
         $xpath = new DomXPath($domd);
         $n = $xpath->query("//{$type}");
         $version = $this->getVersion();
         $version++;
         if (!is_null($this->changesetId)) {
             $n->item(0)->setAttribute('changeset', $this->changesetId);
         }
         $n->item(0)->setAttribute('action', 'delete');
         $xml = $domd->saveXml($n->item(0));
         return $this->osmChangeXml("<delete>{$xml}</delete>");
     }
 }
开发者ID:AndrOrt,项目名称:Services_Openstreetmap,代码行数:62,代码来源:Object.php

示例11: saveXML

function saveXML($simplexml)
{
    global $config;
    $domDoc = new DomDocument('1.0', 'utf-8');
    $domDoc->formatOutput = true;
    $domDoc->preserveWhiteSpace = false;
    $domDoc->loadXml($simplexml->asXml());
    return file_put_contents($config['xml_tv'], $domDoc->saveXml());
}
开发者ID:embalmed,项目名称:hellavcr,代码行数:9,代码来源:hellavcr.php

示例12: osmChangeXml

 /**
  * Amend osmChangeXml with specific updates pertinent to this Way object.
  *
  * @param string $xml OSM Change XML as generated by getOsmChangeXml
  *
  * @return string
  * @see    getOsmChangeXml
  * @link   http://wiki.openstreetmap.org/wiki/OsmChange
  */
 public function osmChangeXml($xml)
 {
     if ($this->dirtyNodes) {
         $domd = new DomDocument();
         $domd->loadXml($xml);
         $xpath = new DomXPath($domd);
         $nodelist = $xpath->query('//' . $this->action . '/way');
         $nd = $xpath->query("//{$this->action}/way/nd");
         // Remove nodes if appropriate.
         for ($i = 0; $i < $nd->length; $i++) {
             $ref = $nd->item($i)->getAttribute('ref');
             if (array_search($ref, $this->nodes) === false) {
                 $nodelist->item(0)->removeChild($nd->item($i));
             }
         }
         // Add new nodes.
         foreach ($this->nodesNew as $new) {
             $el = $domd->createElement('nd');
             $el->setAttribute('ref', $new);
             $nodelist->item(0)->appendChild($el);
         }
         // Remove blank lines in XML - minimise bandwidth usage.
         return preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", '', $domd->saveXml($nodelist->item(0)));
         return $domd->saveXml($nodelist->item(0));
     } else {
         return $xml;
     }
 }
开发者ID:AndrOrt,项目名称:Services_Openstreetmap,代码行数:37,代码来源:Way.php

示例13: sendRequest

 /**
  * Performs a Plesk API request, returns raw API response text
  *
  * @param string $packet
  *
  * @return string
  * @throws ApiRequestException
  */
 private function sendRequest($packet)
 {
     $domdoc = new \DomDocument('1.0', 'UTF-8');
     if ($domdoc->loadXml($packet) === false) {
         $this->error = 'Failed to load payload';
         return false;
     }
     $body = $domdoc->saveHTML();
     return $this->http->sendRequest($body);
 }
开发者ID:pmill,项目名称:php-plesk,代码行数:18,代码来源:BaseRequest.php

示例14: fromString

 public static function fromString($xmlString)
 {
     $xml = new \DomDocument('1.0', 'UTF-8');
     $xml->loadXml($xmlString);
     return new self($xml);
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:6,代码来源:Document.php

示例15: getDom

 /**
  * Sets up a domdocument for the functions.
  *
  * @return DomDocument
  *   The domdocument to modify
  */
 protected function getDom()
 {
     if (isset($this->datastream->content) && $this->autoCommit) {
         // @todo Proper exception handling.
         $document = new DomDocument();
         $document->preserveWhiteSpace = FALSE;
         $document->loadXml($this->datastream->content);
     } else {
         if (!is_null($this->domCache) && !$this->autoCommit) {
             $document = $this->domCache;
         } else {
             $document = new DomDocument("1.0", "UTF-8");
             $rootelement = $document->createElement('rdf:RDF');
             $document->appendChild($rootelement);
         }
     }
     // Setup the default namespace aliases.
     foreach ($this->namespaces as $alias => $uri) {
         // if we use setAttributeNS here we drop the rdf: from about which
         // breaks things, so we do this, then the hack below.
         $document->documentElement->setAttribute("xmlns:{$alias}", $uri);
     }
     // this is a hack, but it makes sure namespaces are properly registered
     $document_namespaces = new DomDocument();
     $document_namespaces->preserveWhiteSpace = FALSE;
     $document_namespaces->loadXml($document->saveXML());
     return $document_namespaces;
 }
开发者ID:MarmotLibraryNetwork,项目名称:islandora_import,代码行数:34,代码来源:FedoraRelationships.php


注:本文中的DomDocument::loadXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。