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


PHP DOMXpath::evaluate方法代码示例

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


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

示例1: hasSignificantWhitespace

 /**
  * Returns if significant whitespaces occur in the paragraph.
  *
  * This method checks if the paragraph $element contains significant
  * whitespaces in form of <text:s/> or <text:tab/> elements.
  * 
  * @param DOMElement $element 
  * @return bool
  */
 protected function hasSignificantWhitespace(DOMElement $element)
 {
     $xpath = new DOMXpath($element->ownerDocument);
     $xpath->registerNamespace('text', ezcDocumentOdt::NS_ODT_TEXT);
     $whitespaces = $xpath->evaluate('.//text:s|.//text:tab|.//text:line-break', $element);
     return $whitespaces instanceof DOMNodeList && $whitespaces->length > 0;
 }
开发者ID:axelmdev,项目名称:ecommerce,代码行数:16,代码来源:paragraph.php

示例2: enhance

 /**
  * @param \OCA\News\Db\Item $item
  * @return \OCA\News\Db\Item enhanced item
  */
 public function enhance(Item $item)
 {
     foreach ($this->regexXPathPair as $regex => $search) {
         if (preg_match($regex, $item->getUrl())) {
             $file = $this->getFile($item->getUrl());
             // convert encoding by detecting charset from header
             $contentType = $file->headers['content-type'];
             if (preg_match('/(?<=charset=)[^;]*/', $contentType, $matches)) {
                 $body = mb_convert_encoding($file->body, 'HTML-ENTITIES', $matches[0]);
             } else {
                 $body = $file->body;
             }
             $dom = new \DOMDocument();
             @$dom->loadHTML($body);
             $xpath = new \DOMXpath($dom);
             $xpathResult = $xpath->evaluate($search);
             // in case it wasnt a text query assume its a single
             if (!is_string($xpathResult)) {
                 $xpathResult = $this->domToString($xpathResult);
             }
             // convert all relative to absolute URLs
             $xpathResult = $this->substituteRelativeLinks($xpathResult, $item->getUrl());
             if ($xpathResult) {
                 $item->setBody($xpathResult);
             }
         }
     }
     return $item;
 }
开发者ID:hroo772,项目名称:news,代码行数:33,代码来源:xpatharticleenhancer.php

示例3: testOff

 function testOff()
 {
     $doc = $this->process_post("[bibshow file=custom://data show_links=0][bibcite key=test]", ShowLinks::$data);
     $xpath = new DOMXpath($doc);
     $href = $xpath->evaluate("//a[@class = 'papercite_bibcite']/@href");
     $this->assertEquals(0, $href->length, "There were {$href->length} links detected - expected none");
 }
开发者ID:t-artistik,项目名称:papercite,代码行数:7,代码来源:test-show_links.php

示例4: metascore

 public function metascore($type = "game", $name, $platform = NULL)
 {
     if (!$name) {
         throw new Exception("No parameters.");
     }
     $name = self::stripUrl($name);
     if ($platform) {
         $platform = self::stripUrl($platform);
     }
     $dom = new DomDocument();
     if ($type != ("movie" || "tv")) {
         $dom->loadHtmlFile("http://www.metacritic.com/{$type}/{$platform}/{$name}/");
         //replace this with Metacritics JSON search
     } else {
         $dom->loadHtmlFile("http://www.metacritic.com/{$type}/{$name}/");
         //replace this with Metacritics JSON search
     }
     $xpath = new DOMXpath($dom);
     $nodes = $xpath->evaluate("//span[@property='v:average']");
     if ($nodes) {
         return $nodes->item(0)->nodeValue;
     } else {
         throw new Exception("Could not find Metascore.");
     }
 }
开发者ID:OlegKrasnov,项目名称:Metacritic-PHP-API,代码行数:25,代码来源:MetacriticApi.php

示例5: copyForDeployment

    /**
     * Copy ServiceConfiguration over to build directory given with target path
     * and modify some of the settings to point to development settings.
     *
     * @param string $targetPath
     * @return void
     */
    public function copyForDeployment($targetPath, $development = true)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->loadXML($this->dom->saveXML());
        $xpath = new \DOMXpath($dom);
        $xpath->registerNamespace('sc', $dom->lookupNamespaceUri($dom->namespaceURI));
        $settings = $xpath->evaluate('//sc:ConfigurationSettings/sc:Setting[@name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"]');
        foreach ($settings as $setting) {
            if ($development) {
                $setting->setAttribute('value', 'UseDevelopmentStorage=true');
            } else {
                if (strlen($setting->getAttribute('value')) === 0) {
                    if ($this->storage) {
                        $setting->setAttribute('value', sprintf('DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', $this->storage['accountName'], $this->storage['accountKey']));
                    } else {
                        throw new \RuntimeException(<<<EXC
ServiceConfiguration.csdef: Missing value for
'Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString'.

You have to modify the app/azure/ServiceConfiguration.csdef to contain
a value for the diagnostics connection string or better configure
'windows_azure_distribution.diagnostics.accountName' and
'windows_azure_distribution.diagnostics.accountKey' in your
app/config/config.yml

If you don't want to enable diagnostics you should delete the
connection string elements from ServiceConfiguration.csdef file.
EXC
);
                    }
                }
            }
        }
        $dom->save($targetPath . '/ServiceConfiguration.cscfg');
    }
开发者ID:senthilkumar3282,项目名称:AzureDistributionBundle,代码行数:42,代码来源:ServiceConfiguration.php

示例6: preFilter

 public function preFilter($sHtml, $config, $context)
 {
     if (false === strstr($sHtml, '<a ')) {
         return $sHtml;
     }
     $sId = 'bx-links-' . md5(microtime());
     $dom = new DOMDocument();
     @$dom->loadHTML('<?xml encoding="UTF-8"><div id="' . $sId . '">' . $sHtml . '</div>');
     $xpath = new DOMXpath($dom);
     $oLinks = $xpath->evaluate('//a');
     for ($i = 0; $i < $oLinks->length; $i++) {
         $oLink = $oLinks->item($i);
         $sClasses = $oLink->getAttribute('class');
         if (!$sClasses || false === strpos($sClasses, $this->class)) {
             $sClasses = ($sClasses ? $sClasses . ' ' : '') . $this->class;
         }
         $oLink->removeAttribute('class');
         $oLink->setAttribute("class", $sClasses);
     }
     if (false === ($s = $dom->saveXML($dom->getElementById($sId)))) {
         // in case of error return original string
         return $sHtml;
     }
     return mb_substr($s, 52, -6);
     // strip added tags
 }
开发者ID:Gotgot59,项目名称:dolphin.pro,代码行数:26,代码来源:AddBxLinksClass.php

示例7: testOn

 function testOn()
 {
     $doc = $this->process_post("[bibtex file=custom://data process_titles=1]", Issue95::$data);
     $xpath = new DOMXpath($doc);
     $title = $xpath->evaluate("//ul[@class = 'papercite_bibliography']//span[1]/text()");
     $this->assertTrue($title->length == 1, "There were {$title->length} span detected - expected 1");
     $title = $title->item(0)->textContent;
     $this->assertEquals($title, "11th usenix symposium on networked systems design and implementation (nsdi 14)");
 }
开发者ID:t-artistik,项目名称:papercite,代码行数:9,代码来源:test-issue-95.php

示例8: casValidate

function casValidate($cas)
{
    $service = SimpleSAML_Utilities::selfURL();
    $service = preg_replace("/(\\?|&)?ticket=.*/", "", $service);
    # always tagged on by cas
    /**
     * Got response from CAS server.
     */
    if (isset($_GET['ticket'])) {
        $ticket = urlencode($_GET['ticket']);
        #ini_set('default_socket_timeout', 15);
        if (isset($cas['validate'])) {
            # cas v1 yes|no\r<username> style
            $paramPrefix = strpos($cas['validate'], '?') ? '&' : '?';
            $result = SimpleSAML_Utilities::fetch($cas['validate'] . $paramPrefix . 'ticket=' . $ticket . '&service=' . urlencode($service));
            $res = preg_split("/\r?\n/", $result);
            if (strcmp($res[0], "yes") == 0) {
                return array($res[1], array());
            } else {
                throw new Exception("Failed to validate CAS service ticket: {$ticket}");
            }
        } elseif (isset($cas['serviceValidate'])) {
            # cas v2 xml style
            $paramPrefix = strpos($cas['serviceValidate'], '?') ? '&' : '?';
            $result = SimpleSAML_Utilities::fetch($cas['serviceValidate'] . $paramPrefix . 'ticket=' . $ticket . '&service=' . urlencode($service));
            $dom = DOMDocument::loadXML($result);
            $xPath = new DOMXpath($dom);
            $xPath->registerNamespace("cas", 'http://www.yale.edu/tp/cas');
            $success = $xPath->query("/cas:serviceResponse/cas:authenticationSuccess/cas:user");
            if ($success->length == 0) {
                $failure = $xPath->evaluate("/cas:serviceResponse/cas:authenticationFailure");
                throw new Exception("Error when validating CAS service ticket: " . $failure->item(0)->textContent);
            } else {
                $attributes = array();
                if ($casattributes = $cas['attributes']) {
                    # some has attributes in the xml - attributes is a list of XPath expressions to get them
                    foreach ($casattributes as $name => $query) {
                        $attrs = $xPath->query($query);
                        foreach ($attrs as $attrvalue) {
                            $attributes[$name][] = $attrvalue->textContent;
                        }
                    }
                }
                $casusername = $success->item(0)->textContent;
                return array($casusername, $attributes);
            }
        } else {
            throw new Exception("validate or serviceValidate not specified");
        }
        /**
         * First request, will redirect the user to the CAS server for authentication.
         */
    } else {
        SimpleSAML_Logger::info("AUTH - cas-ldap: redirecting to {$cas['login']}");
        SimpleSAML_Utilities::redirectTrustedURL($cas['login'], array('service' => $service));
    }
}
开发者ID:danielkjfrog,项目名称:docker,代码行数:57,代码来源:login-cas-ldap.php

示例9: setResponse

 /**
  * {@inheritdoc}
  */
 public function setResponse($response)
 {
     $dom = new \DOMDocument();
     try {
         if (!$dom->loadXML($response)) {
             throw new \ErrorException('Could not transform this xml to a \\DOMDocument instance.');
         }
     } catch (\Exception $e) {
         throw new AuthenticationException('Could not retrieve valid user info.');
     }
     $this->xpath = new \DOMXpath($dom);
     $nodes = $this->xpath->evaluate('/api/root');
     $user = $this->xpath->query('./foaf:Person', $nodes->item(0));
     if (1 !== $user->length) {
         throw new AuthenticationException('Could not retrieve user info.');
     }
     $this->response = $user->item(0);
 }
开发者ID:senthilkumar3282,项目名称:HWIOAuthBundle,代码行数:21,代码来源:SensioConnectUserResponse.php

示例10: sanitize

    /**
     * @param string $text
     * @return string
     */
    public function sanitize($text)
    {
        $doc = new DOMDocument('1.0', "UTF-8");
        $text = mb_convert_encoding($text, 'HTML-ENTITIES', 'UTF-8');
        $doc->loadHTML('<?xml encoding="UTF-8">'.$text);
        $doc->encoding = "UTF-8";
        $doc->formatOutput = true;

        // get all the script tags
        $script_tags = $doc->getElementsByTagName('script');
        $length = $script_tags->length;
        // for each tag, remove it from the DOM
        for ($i = 0; $i < $length; $i++) {
            if(($parentNode = $script_tags->item($i)->parentNode))
                $parentNode->removeChild($script_tags->item($i));
        }

        /* @type $parentNode DOMNode */

        $xpath = new DOMXpath($doc);
        foreach ($xpath->evaluate('//*[@onmouseover]') as $input)
        {
            if(($parentNode = $input->parentNode))
                $parentNode->removeChild($input);
        }
        foreach ($xpath->evaluate('//*[@onmouseout]') as $input)
        {
            if(($parentNode = $input->parentNode))
                $parentNode->removeChild($input);
        }
        foreach ($xpath->evaluate('//*[@onerror]') as $input)
        {
            if(($parentNode = $input->parentNode))
                $parentNode->removeChild($input);
        }
        foreach ($xpath->evaluate('//*[@onclick]') as $input)
        {
            if(($parentNode =$input->parentNode))
                $parentNode->removeChild($input);
        }

        $result = $doc->saveHTML();
        return strip_tags($result, "<span><strong><br><div>");
    }
开发者ID:sushilbshinde,项目名称:ezpublish-study,代码行数:48,代码来源:contentListPrintMail.php

示例11: test

 function test()
 {
     $url = "https://gist.githubusercontent.com/bpiwowar/9793f4e2da48dfb34cde/raw/5fbff41218107aa9dcfab4fc53fe8e2b86ea8416/test.bib";
     $doc = $this->process_post("[bibtex ssl_check=true file={$url}]");
     $xpath = new DOMXpath($doc);
     $items = $xpath->evaluate("//ul[@class = 'papercite_bibliography']/li");
     $this->assertTrue($items->length == 1, "{$items->length} items detected - expected 1");
     $text = $items->item(0)->textContent;
     $this->assertRegExp("#Piwowarski#", $text);
 }
开发者ID:t-artistik,项目名称:papercite,代码行数:10,代码来源:test-remote.php

示例12: testHighlight

 function testHighlight()
 {
     $doc = $this->process_post("[bibtex file=custom://data highlight=\"Piwowarski\"]", HighlightTest::$data);
     // print $doc->saveXML();
     $xpath = new DOMXpath($doc);
     $highlight = $xpath->evaluate("//span[@class = 'papercite_highlight']/text()");
     $this->assertTrue($highlight->length == 1, "{$highlight->length} highlights detected - expected 1");
     $highlight = $highlight->item(0)->wholeText;
     $this->assertTrue($highlight == "Piwowarski", "The hilight [{$highlight}] is not as expected");
 }
开发者ID:t-artistik,项目名称:papercite,代码行数:10,代码来源:test-highlight.php

示例13: selectElements

 /**
  * Selects elements that match a CSS selector
  * 
  * Based on the implementation of TJ Holowaychuk <tj@vision-media.ca>
  * @link https://github.com/tj/php-selector
  * @param string $selector
  * @param \DOMDocument $htmlOrDom
  * @return \DOMNodeList
  */
 public static function selectElements($selector, $htmlOrDom)
 {
     if ($htmlOrDom instanceof \DOMDocument) {
         $xpath = new \DOMXpath($htmlOrDom);
     } else {
         $dom = new \DOMDocument();
         @$dom->loadHTML($htmlOrDom);
         $xpath = new \DOMXpath($dom);
     }
     return $xpath->evaluate(self::selectorToXpath($selector));
 }
开发者ID:xprt64,项目名称:php-css,代码行数:20,代码来源:Selector.php

示例14: check

 function check($modifier, $expected)
 {
     $doc = $this->process_post("[bibtex file=custom://data template=custom://template]", array("data" => HTMLModifierTest::$data, "template" => HTMLModifierTest::getTemplate($modifier)));
     $xpath = new DOMXpath($doc);
     $result = $xpath->evaluate("//div[@id = 'abstract']/node()");
     $text = "";
     for ($i = 0; $i < $result->length; $i++) {
         $text .= $doc->saveXML($result->item($i));
     }
     $this->assertEquals($text, $expected, "Error with modifier {$modifier}");
 }
开发者ID:t-artistik,项目名称:papercite,代码行数:11,代码来源:test-html-modifier.php

示例15: parse

 /**
  * Parses the OPML file.
  *
  * @param bool $normalize_case
  *   (optional) True to convert all attributes to lowercase. False, to leave
  *   them as is. Defaults to false.
  *
  * @return array
  *   A structed array.
  *
  * @todo Document the return value.
  */
 public function parse($normalize_case = FALSE)
 {
     $this->normalizeCase = $normalize_case;
     $return = ['head' => ['#title' => '']];
     // Title is a required field, let parsers assume its existence.
     foreach ($this->xpath->query('/opml/head/*') as $element) {
         if ($this->normalizeCase) {
             $return['head']['#' . strtolower($element->nodeName)] = $element->nodeValue;
         } else {
             $return['head']['#' . $element->nodeName] = $element->nodeValue;
         }
     }
     if (isset($return['head']['#expansionState'])) {
         $return['head']['#expansionState'] = array_filter(explode(',', $return['head']['#expansionState']));
     }
     $return['outlines'] = [];
     if ($content = $this->xpath->evaluate('/opml/body', $this->xpath->document)->item(0)) {
         $return['outlines'] = $this->getOutlines($content);
     }
     return $return;
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:33,代码来源:GenericOpmlParser.php


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