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


PHP DOMXPath类代码示例

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


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

示例1: _testXPath

 function _testXPath($xpath_expression)
 {
     if (!class_exists('DOMDocument') || !class_exists('DOMXPath')) {
         if (function_exists('domxml_open_mem')) {
             $dom = domxml_open_mem($this->_response);
             if (!$dom) {
                 $this->fail('Error parsing doc');
                 return false;
             }
             var_dump($dom);
             $xpath = $dom->xpath_init();
             var_dump($xpath);
             $ctx = $dom->xpath_new_context();
             var_dump($xpath_expression);
             $result = $ctx->xpath_eval($xpath_expression);
             var_dump($result);
             $return = new stdClass();
             $return->length = count($result->nodeset);
             return $return;
         }
         $this->fail('No xpath support built in');
         return false;
     } else {
         if (extension_loaded('domxml')) {
             $this->fail('Please disable the domxml extension. Only php5 builtin domxml is supported');
             return false;
         }
     }
     $dom = new DOMDocument();
     $dom->loadHtml($this->_response);
     $xpath = new DOMXPath($dom);
     $node = $xpath->query($xpath_expression);
     return $node;
 }
开发者ID:joeymetal,项目名称:v1,代码行数:34,代码来源:AkTestApplication.php

示例2: process

 function process(&$article)
 {
     $owner_uid = $article["owner_uid"];
     if (strpos($article["guid"], "bunicomic.com") !== FALSE || strpos($article["guid"], "buttersafe.com") !== FALSE || strpos($article["guid"], "whompcomic.com") !== FALSE || strpos($article["guid"], "extrafabulouscomics.com") !== FALSE || strpos($article["guid"], "happyjar.com") !== FALSE || strpos($article["guid"], "csectioncomics.com") !== FALSE) {
         if (strpos($article["plugin_data"], "af_comics,{$owner_uid}:") === FALSE) {
             // lol at people who block clients by user agent
             // oh noes my ad revenue Q_Q
             $res = fetch_file_contents($article["link"], false, false, false, false, false, 0, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
             $doc = new DOMDocument();
             @$doc->loadHTML($res);
             $basenode = false;
             if ($doc) {
                 $xpath = new DOMXPath($doc);
                 $basenode = $xpath->query('//div[@id="comic"]')->item(0);
                 if ($basenode) {
                     $article["content"] = $doc->saveXML($basenode);
                     $article["plugin_data"] = "af_comics,{$owner_uid}:" . $article["plugin_data"];
                 }
             }
         } else {
             if (isset($article["stored"]["content"])) {
                 $article["content"] = $article["stored"]["content"];
             }
         }
         return true;
     }
     return false;
 }
开发者ID:neynah,项目名称:Tiny-Tiny-RSS,代码行数:28,代码来源:af_comics_comicpress.php

示例3: __construct

    /**
     * Constructs a new object object from DOM Document.
     *
     * @param   DomDocument $dom the ReST fragment for this object
     */
    public function __construct(DomDocument $dom)
    {
        $xpath = new DOMXPath($dom);
        $result = $xpath->query('//result/weblog');
        if ($result->length == 1) {
            $this->_weblog = new Zend_Service_Technorati_Weblog($result->item(0));
        } else {
            // follow the same behavior of blogPostTags
            // and raise an Exception if the URL is not a valid weblog
            throw new Zend_Service_Technorati_Exception(
                "Your URL is not a recognized Technorati weblog");
        }

        $result = $xpath->query('//result/url/text()');
        if ($result->length == 1) {
            try {
                // fetched URL often doens't include schema
                // and this issue causes the following line to fail
                $this->_url = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data);
            } catch(Zend_Service_Technorati_Exception $e) {
                if ($this->getWeblog() instanceof Zend_Service_Technorati_Weblog) {
                    $this->_url = $this->getWeblog()->getUrl();
                }
            }
        }

        $result = $xpath->query('//result/inboundblogs/text()');
        if ($result->length == 1) $this->_inboundBlogs = (int) $result->item(0)->data;

        $result = $xpath->query('//result/inboundlinks/text()');
        if ($result->length == 1) $this->_inboundLinks = (int) $result->item(0)->data;

    }
开发者ID:niallmccrudden,项目名称:zf2,代码行数:38,代码来源:BlogInfoResult.php

示例4: generate

 function generate()
 {
     parent::generate();
     $xpath = new DOMXPath($this->_doc);
     $this->appendLine('<?php');
     $this->appendLine('require_once("KalturaClientBase.php");');
     $this->appendLine('');
     // enumes
     $enumNodes = $xpath->query("/xml/enums/enum");
     foreach ($enumNodes as $enumNode) {
         $this->writeEnum($enumNode);
     }
     // classes
     $classNodes = $xpath->query("/xml/classes/class");
     foreach ($classNodes as $classNode) {
         $this->writeClass($classNode);
     }
     $serviceNodes = $xpath->query("/xml/services/service");
     foreach ($serviceNodes as $serviceNode) {
         $this->writeService($serviceNode);
     }
     $this->appendLine();
     $this->writeMainClient($serviceNodes);
     $this->appendLine();
     $this->addFile("KalturaClient.php", $this->getTextBlock());
 }
开发者ID:EfncoPlugins,项目名称:Media-Management-based-on-Kaltura,代码行数:26,代码来源:Php4ClientGenerator.php

示例5: __construct

 /**
  * Constructs a new object from DOM Element.
  *
  * @param   DomElement $dom the ReST fragment for this object
  */
 public function __construct(DomElement $dom)
 {
     $xpath = new DOMXPath($dom->ownerDocument);
     $result = $xpath->query('./firstname/text()', $dom);
     if ($result->length == 1) {
         $this->setFirstName($result->item(0)->data);
     }
     $result = $xpath->query('./lastname/text()', $dom);
     if ($result->length == 1) {
         $this->setLastName($result->item(0)->data);
     }
     $result = $xpath->query('./username/text()', $dom);
     if ($result->length == 1) {
         $this->setUsername($result->item(0)->data);
     }
     $result = $xpath->query('./description/text()', $dom);
     if ($result->length == 1) {
         $this->setDescription($result->item(0)->data);
     }
     $result = $xpath->query('./bio/text()', $dom);
     if ($result->length == 1) {
         $this->setBio($result->item(0)->data);
     }
     $result = $xpath->query('./thumbnailpicture/text()', $dom);
     if ($result->length == 1) {
         $this->setThumbnailPicture($result->item(0)->data);
     }
 }
开发者ID:stunti,项目名称:zf2,代码行数:33,代码来源:Author.php

示例6: parseResinImprFile

function parseResinImprFile($file_path)
{
    global $hostDict;
    $doc = new DOMDocument();
    @$doc->loadHTMLFile($file_path);
    $query = "//table[1]/tr[@class != 'first']/td[position() < 3]";
    $xpath = new DOMXPath($doc);
    $entries = $xpath->query($query);
    $index = 0;
    $key = "";
    $value = "";
    foreach ($entries as $entry) {
        if ($index % 2 == 0) {
            $key = $entry->nodeValue;
        } else {
            $value = $entry->nodeValue;
        }
        if ($index != 0 and $index % 2 == 1) {
            if ($key == "AD_EXCHANGE.bidResult") {
                # 还不能区分bid 和 bidResult, 所以加到一起
                $key = "AD_EXCHANGE.bid";
            }
            if (array_key_exists($key, $hostDict) && !in_array($value, $hostDict[$key])) {
                array_push($hostDict[$key], $value);
            }
        }
        $index++;
    }
}
开发者ID:sleepyycat,项目名称:WebFramework,代码行数:29,代码来源:DeployDirReader.php

示例7: convert

 /**
  * Convert dom node tree to array
  *
  * @param \DOMDocument $source
  * @return array
  * @throws \InvalidArgumentException
  */
 public function convert($source)
 {
     $output = [];
     $xpath = new \DOMXPath($source);
     $indexers = $xpath->evaluate('/config/indexer');
     /** @var $typeNode \DOMNode */
     foreach ($indexers as $indexerNode) {
         $data = [];
         $indexerId = $this->getAttributeValue($indexerNode, 'id');
         $data['indexer_id'] = $indexerId;
         $data['primary'] = $this->getAttributeValue($indexerNode, 'primary');
         $data['view_id'] = $this->getAttributeValue($indexerNode, 'view_id');
         $data['action_class'] = $this->getAttributeValue($indexerNode, 'class');
         $data['title'] = '';
         $data['description'] = '';
         /** @var $childNode \DOMNode */
         foreach ($indexerNode->childNodes as $childNode) {
             if ($childNode->nodeType != XML_ELEMENT_NODE) {
                 continue;
             }
             /** @var $childNode \DOMElement */
             $data = $this->convertChild($childNode, $data);
         }
         $output[$indexerId] = $data;
     }
     return $output;
 }
开发者ID:nja78,项目名称:magento2,代码行数:34,代码来源:Converter.php

示例8: unserialize

 /**
  * Unserializes the property.
  *
  * This static method should return a an instance of this object.
  *
  * @param \DOMElement $prop
  * @param array $propertyMap
  * @return DAV\IProperty
  */
 static function unserialize(\DOMElement $prop, array $propertyMap)
 {
     $xpath = new \DOMXPath($prop->ownerDocument);
     $xpath->registerNamespace('d', 'urn:DAV');
     // Finding the 'response' element
     $xResponses = $xpath->evaluate('d:response', $prop);
     $result = [];
     for ($jj = 0; $jj < $xResponses->length; $jj++) {
         $xResponse = $xResponses->item($jj);
         // Parsing 'href'
         $href = Href::unserialize($xResponse, $propertyMap);
         $properties = [];
         // Parsing 'status' in 'd:response'
         $responseStatus = $xpath->evaluate('string(d:status)', $xResponse);
         if ($responseStatus) {
             list(, $responseStatus, ) = explode(' ', $responseStatus, 3);
         }
         // Parsing 'propstat'
         $xPropstat = $xpath->query('d:propstat', $xResponse);
         for ($ii = 0; $ii < $xPropstat->length; $ii++) {
             // Parsing 'status'
             $status = $xpath->evaluate('string(d:status)', $xPropstat->item($ii));
             list(, $statusCode, ) = explode(' ', $status, 3);
             $usedPropertyMap = $statusCode == '200' ? $propertyMap : [];
             // Parsing 'prop'
             $properties[$statusCode] = DAV\XMLUtil::parseProperties($xPropstat->item($ii), $usedPropertyMap);
         }
         $result[] = new Response($href->getHref(), $properties, $responseStatus ? $responseStatus : null);
     }
     return new self($result);
 }
开发者ID:enoch85,项目名称:owncloud-testserver,代码行数:40,代码来源:ResponseList.php

示例9: parse

 public static function parse($html, $url)
 {
     $recipe = RecipeParser_Parser_MicrodataSchema::parse($html, $url);
     // Turn off libxml errors to prevent mismatched tag warnings.
     libxml_use_internal_errors(true);
     $doc = new DOMDocument();
     $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
     $doc->loadHTML('<?xml encoding="UTF-8">' . $html);
     $xpath = new DOMXPath($doc);
     // Photo -- skip logo if it was used in place of photo
     if (strpos($recipe->photo_url, "FDC_Logo_vertical.png") !== false || strpos($recipe->photo_url, "FDC_share-logo.png") !== false) {
         $recipe->photo_url = '';
     }
     if ($recipe->photo_url) {
         $recipe->photo_url = str_replace("/thumbs/", "/large/", $recipe->photo_url);
     }
     // Yield
     $yield = '';
     $nodes = $xpath->query('//*[@class="yield"]');
     // Find as 'yield'
     if ($nodes->length) {
         $line = $nodes->item(0)->nodeValue;
         $line = RecipeParser_Text::formatYield($line);
         $recipe->yield = $line;
         // Or as number of 'servings'
     } else {
         $nodes = $xpath->query('//*[@class="servings"]//*[@class="value"]');
         if ($nodes->length) {
             $line = $nodes->item(0)->nodeValue;
             $line = RecipeParser_Text::formatYield($line);
             $recipe->yield = $line;
         }
     }
     return $recipe;
 }
开发者ID:johndunne,项目名称:RecipeParser,代码行数:35,代码来源:Foodcom.php

示例10: addEntriesFromFeed

 /**
  * addEntriesFromFeed adds all the entries from a zotero api feed to the collection
  * @param $feed either a DOMDocument or string xml of the feed
  */
 public function addEntriesFromFeed($feed)
 {
     if (is_string($feed)) {
         $dom = new DOMDocument();
         //cleanup GET param separators in the links in the feed
         $feed = str_replace('&', '&amp;', $feed);
         $dom->loadXML($feed);
     } else {
         if (get_class($feed) == 'DOMDocument') {
             $dom = $feed;
             //$newFeedNode = $dom->importNode($feed, true);
             //$dom->appendChild($newFeedNode);
         } else {
             throw new Exception('Entry must be either an XML string or an ATOM feed DOMNode');
         }
     }
     $xpath = new DOMXPath($dom);
     $xpath->registerNamespace('zxfer', 'http://zotero.org/ns/transfer');
     $xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
     $entryNodes = $xpath->query('//atom:entry');
     for ($i = 0; $i < $entryNodes->length; $i++) {
         $newEntry = new phpZoteroEntry($entryNodes->item($i));
         $this->entries[$newEntry->itemUri] = $newEntry;
     }
 }
开发者ID:patrickmj,项目名称:ZItem,代码行数:29,代码来源:phpZoteroEntries.php

示例11: _doBuild

 /**
  * load all app files for given path and build.xml document
  *
  * @param string $path app base path
  * @param DOMDocument $build build.xml
  * @return boolean
  */
 private function _doBuild($path, DOMDocument $build)
 {
     $Classes = Classes::get();
     $x = new DOMXPath($build);
     $app = $x->query('/build/app');
     if ($app->length != 1) {
         throw new PException('App error!');
     }
     $app = $app->item(0);
     if (!$app->hasAttribute('name')) {
         throw new PException('App name error!');
     }
     $this->_apps[$app->getAttribute('name')] = $build;
     $files = $x->query('/build/files/file');
     foreach ($files as $file) {
         if ($file->hasAttribute('class')) {
             $Classes->addClass($file->getAttribute('class'), $path . $file->nodeValue);
             continue;
         }
         if ($file->hasAttribute('include')) {
             if (!file_exists($path . $file->nodeValue)) {
                 continue;
             }
             $this->_includes[] = $path . $file->nodeValue;
             continue;
         }
     }
     return true;
 }
开发者ID:gpuenteallott,项目名称:rox,代码行数:36,代码来源:apps.lib.php

示例12: handle

 /**
  * Handle a node
  *
  * Handle / transform a given node, and return the result of the
  * conversion.
  *
  * @param ezcDocumentElementVisitorConverter $converter
  * @param DOMElement $node
  * @param mixed $root
  * @return mixed
  */
 public function handle(ezcDocumentElementVisitorConverter $converter, DOMElement $node, $root)
 {
     $quote = $root->ownerDocument->createElement('blockquote');
     // Locate optional attribution elements, and transform them below the
     // recursive quote visiting.
     $xpath = new DOMXPath($node->ownerDocument);
     $attributionNodes = $xpath->query('*[local-name() = "attribution"]', $node);
     $attributions = array();
     foreach ($attributionNodes as $attribution) {
         $attributions[] = $attribution->cloneNode(true);
         $attribution->parentNode->removeChild($attribution);
     }
     // Recursively decorate blockquote, after all attribution nodes are
     // removed
     $quote = $converter->visitChildren($node, $quote);
     $root->appendChild($quote);
     // Append attribution nodes, if any
     foreach ($attributions as $attribution) {
         $div = $root->ownerDocument->createElement('div');
         $div->setAttribute('class', 'attribution');
         $quote->appendChild($div);
         $cite = $root->ownerDocument->createElement('cite', htmlspecialchars($attribution->textContent));
         $div->appendChild($cite);
     }
     return $root;
 }
开发者ID:axelmdev,项目名称:ecommerce,代码行数:37,代码来源:blockquote.php

示例13: findAll

 /**
  * @param \DOMNode $node
  * @param string $selector
  * @return \DOMNodeList
  */
 public function findAll($node, $selector)
 {
     $domXPath = new \DOMXPath($node->ownerDocument);
     $converter = new CssSelectorConverter();
     $xpath = $converter->toXPath($selector);
     return $domXPath->query($xpath, $node);
 }
开发者ID:facebook,项目名称:facebook-instant-articles-sdk-php,代码行数:12,代码来源:ElementGetter.php

示例14: apply

 public function apply(KalturaRelatedFilter $filter, KalturaObject $parentObject)
 {
     $filterProperty = $this->filterProperty;
     $parentProperty = $this->parentProperty;
     KalturaLog::debug("Mapping XPath {$parentProperty} to " . get_class($filter) . "::{$filterProperty}");
     if (!$parentObject instanceof KalturaMetadata) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_TYPE, get_class($parentObject));
     }
     if (!property_exists($filter, $filterProperty)) {
         throw new KalturaAPIException(KalturaErrors::PROPERTY_IS_NOT_DEFINED, $filterProperty, get_class($filter));
     }
     $xml = $parentObject->xml;
     $doc = new KDOMDocument();
     $doc->loadXML($xml);
     $xpath = new DOMXPath($doc);
     $metadataElements = $xpath->query($parentProperty);
     if ($metadataElements->length == 1) {
         $filter->{$filterProperty} = $metadataElements->item(0)->nodeValue;
     } elseif ($metadataElements->length > 1) {
         $values = array();
         foreach ($metadataElements as $element) {
             $values[] = $element->nodeValue;
         }
         $filter->{$filterProperty} = implode(',', $values);
     } elseif (!$this->allowNull) {
         return false;
     }
     return true;
 }
开发者ID:kubrickfr,项目名称:server,代码行数:29,代码来源:KalturaMetadataResponseProfileMapping.php

示例15: patch

 public function patch($version, \DOMDocument $domct, \DOMDocument $domth, Connection $connbas, \unicode $unicode)
 {
     if ($version == "") {
         $th = $domth->documentElement;
         $ct = $domct->documentElement;
         $th->setAttribute("id", "0");
         $xp = new DOMXPath($domth);
         $te = $xp->query("/thesaurus/te");
         if ($te->length > 0) {
             $te0 = $te->item(0);
             $th->setAttribute("nextid", $te0->getAttribute("nextid"));
             $te = $xp->query("te", $te0);
             $te1 = [];
             for ($i = 0; $i < $te->length; $i++) {
                 $te1[] = $te->item($i);
             }
             foreach ($te1 as $tei) {
                 $th->appendChild($tei);
                 $this->fixThesaurus2($domth, $tei, 0, $unicode);
             }
             $te0->parentNode->removeChild($te0);
         }
         $ct->setAttribute("version", $version = "2.0.0");
         $th->setAttribute("version", "2.0.0");
         $th->setAttribute("creation_date", $now = date("YmdHis"));
         $th->setAttribute("modification_date", $now);
         $version = "2.0.0";
     }
     return $version;
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:30,代码来源:100.php


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