本文整理汇总了PHP中DOMXPath::query方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMXPath::query方法的具体用法?PHP DOMXPath::query怎么用?PHP DOMXPath::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMXPath
的用法示例。
在下文中一共展示了DOMXPath::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_page
protected function load_page($link)
{
$doc = new DOMDocument();
# curl does not follow the 301?
$url = str_replace("-rss", "", $link);
$html = fetch_file_contents($url, false, false, false, false, false, 0, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)");
$html_enc = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
$doc->loadHTML($html_enc);
$basenode = false;
$add_content = "";
if ($doc) {
$xpath = new DOMXPath($doc);
$nextpage = $xpath->query('//table[@id="table-jtoc"]/tr/td/a[@id="atoc_next"]');
if ($nextpage && $nextpage->length > 0 && $nextpage->item(0)->hasAttributes()) {
$add_content = $this->load_page("http://www.golem.de" . $nextpage->item(0)->attributes->getNamedItem("href")->value);
}
// first remove advertisement stuff
$stuff = $xpath->query('(//script)|(//noscript)|(//div[contain(@class, "iqad")])|(//ol[@id="list-jtoc"])|(//table[@id="table-jtoc"])|(//header[@class="cluster-header"]/h1)');
foreach ($stuff as $removethis) {
$removethis->parentNode->removeChild($removethis);
}
// now get the (cleaned) article
$entries = $xpath->query('(//article)');
foreach ($entries as $entry) {
$basenode = $entry;
break;
}
if ($basenode) {
return $doc->saveXML($basenode) . $add_content;
} else {
return false;
}
}
}
示例2: __construct
/**
* Parse the given Offer element
*
* @param DOMElement $dom
* @return void
*/
public function __construct(DOMElement $dom)
{
$xpath = new DOMXPath($dom->ownerDocument);
$xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05');
$this->MerchantId = (string) $xpath->query('./az:Merchant/az:MerchantId/text()', $dom)->item(0)->data;
$name = $xpath->query('./az:Merchant/az:Name/text()', $dom);
if ($name->length == 1) {
$this->MerchantName = (string) $name->item(0)->data;
}
$this->GlancePage = (string) $xpath->query('./az:Merchant/az:GlancePage/text()', $dom)->item(0)->data;
$this->Condition = (string) $xpath->query('./az:OfferAttributes/az:Condition/text()', $dom)->item(0)->data;
$this->OfferListingId = (string) $xpath->query('./az:OfferListing/az:OfferListingId/text()', $dom)->item(0)->data;
$Price = $xpath->query('./az:OfferListing/az:Price/az:Amount', $dom);
if ($Price->length == 1) {
$this->Price = (int) $xpath->query('./az:OfferListing/az:Price/az:Amount/text()', $dom)->item(0)->data;
$this->CurrencyCode = (string) $xpath->query('./az:OfferListing/az:Price/az:CurrencyCode/text()', $dom)->item(0)->data;
}
$availability = $xpath->query('./az:OfferListing/az:Availability/text()', $dom)->item(0);
if ($availability instanceof DOMText) {
$this->Availability = (string) $availability->data;
}
$result = $xpath->query('./az:OfferListing/az:IsEligibleForSuperSaverShipping/text()', $dom);
if ($result->length >= 1) {
$this->IsEligibleForSuperSaverShipping = (bool) $result->item(0)->data;
}
}
示例3: 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());
}
示例4: googleArray
/**
* Returns array, containing detailed results for any Google search.
*
* @access private
* @param string $query String, containing the search query.
* @param string $tld String, containing the desired Google top level domain.
* @return array Returns array, containing the keys 'URL', 'Title' and 'Description'.
*/
public static function googleArray($query)
{
$result = array();
$pages = 1;
$delay = 0;
for ($start = 0; $start < $pages; $start++) {
$url = 'http://www.google.' . GOOGLE_TLD . '/custom?q=' . $query . '&filter=0' . '&num=100' . ($start == 0 ? '' : '&start=' . $start . '00');
$str = SEOstats::cURL($url);
if (preg_match("#answer=86640#i", $str)) {
$e = 'Please read: http://www.google.com/support/websearch/' . 'bin/answer.py?&answer=86640&hl=en';
throw new SEOstatsException($e);
} else {
$html = new DOMDocument();
@$html->loadHtml($str);
$xpath = new DOMXPath($html);
$links = $xpath->query("//div[@class='g']//a");
$descs = $xpath->query("//td[@class='j']//div[@class='std']");
$i = 0;
foreach ($links as $link) {
if (!preg_match('#cache#si', $link->textContent) && !preg_match('#similar#si', $link->textContent)) {
$result[] = array('url' => $link->getAttribute('href'), 'title' => utf8_decode($link->textContent), 'descr' => utf8_decode($descs->item($i)->textContent));
$i++;
}
}
if (preg_match('#<div id="nn"><\\/div>#i', $str) || preg_match('#<div id=nn><\\/div>#i', $str)) {
$pages += 1;
$delay += 200000;
usleep($delay);
} else {
$pages -= 1;
}
}
}
return $result;
}
示例5: __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);
/**
* @see Zend_Service_Technorati_Author
*/
require_once 'Zend/Service/Technorati/Author.php';
$result = $xpath->query('//result');
if ($result->length == 1) {
$this->_author = new Zend_Service_Technorati_Author($result->item(0));
}
/**
* @see Zend_Service_Technorati_Weblog
*/
require_once 'Zend/Service/Technorati/Weblog.php';
$result = $xpath->query('//item/weblog');
if ($result->length >= 1) {
foreach ($result as $weblog) {
$this->_weblogs[] = new Zend_Service_Technorati_Weblog($weblog);
}
}
}
示例6: 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;
}
示例7: 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;
}
示例8: run
public function run($args)
{
if (count($args) != 1) {
$this->usageError('Please supply the path to fhir-single.xsd');
}
$output_dir = Yii::app()->basePath . '/components/fhir_schema';
system('mkdir -p ' . escapeshellarg($output_dir));
$doc = new DOMDocument();
$doc->load($args[0]);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('xs', 'http://www.w3.org/2001/XMLSchema');
$types = array();
foreach ($xpath->query('xs:complexType') as $complexType) {
$type = $complexType->getAttribute('name');
$types[$type] = array();
$base = $xpath->evaluate('string(.//xs:extension/@base)', $complexType);
if ($base && isset($types[$base])) {
$types[$type] = $types[$base];
}
foreach ($xpath->query('.//*[@maxOccurs]', $complexType) as $item) {
$plural = $item->getAttribute('maxOccurs') != '1';
if ($item->tagName == 'xs:element') {
$elements = array($item);
} else {
$elements = $xpath->query('.//xs:element', $item);
}
foreach ($elements as $element) {
$el_name = $element->getAttribute('name') ?: $element->getAttribute('ref');
$el_type = $element->getAttribute('type') ?: $element->getAttribute('ref');
$types[$type][$el_name] = array('type' => $el_type, 'plural' => $plural);
}
}
file_put_contents("{$output_dir}/{$type}.json", json_encode($types[$type], JSON_FORCE_OBJECT));
}
}
示例9: DOMDocument
function hook_article_filter($article)
{
if (strpos($article["link"], "daujones.com") !== FALSE) {
$doc = new DOMDocument();
@$doc->loadHTML(mb_convert_encoding(fetch_file_contents($article["link"]), 'HTML-ENTITIES', "UTF-8"));
$basenode = false;
if ($doc) {
$xpath = new DOMXPath($doc);
// first remove advertisement stuff
$stuff = $xpath->query('(//form)|(//span)|(//div[@class="rightnav"])|(//div[@class="kommentare"])|(//a)|(//h2[@style])|(//center)');
foreach ($stuff as $removethis) {
$removethis->parentNode->removeChild($removethis);
}
$entries = $xpath->query('(//div[@class="maincontent"])');
foreach ($entries as $entry) {
$basenode = $entry;
break;
}
if ($basenode) {
$article["content"] = $doc->saveXML($basenode);
}
}
}
return $article;
}
示例10: parseSpecificContributions
/**
* Parse
* @param DOMNode $contribNode
*/
protected function parseSpecificContributions(&$contribNode)
{
parent::parseSpecificContributions($contribNode);
if ($this->pluginConf["ENABLE_324_IMPORT"] == true) {
return;
}
if ($contribNode->nodeName != "actions") {
return;
}
$actionXpath = new DOMXPath($contribNode->ownerDocument);
$compressNodeList = $actionXpath->query('action[@name="import_from_324"]', $contribNode);
if (!$compressNodeList->length) {
return;
}
unset($this->actions["import_from_324"]);
$compressNode = $compressNodeList->item(0);
$contribNode->removeChild($compressNode);
$compressNodeList = $actionXpath->query('action[@name="migrate_metaserial"]', $contribNode);
if (!$compressNodeList->length) {
return;
}
unset($this->actions["import_from_324"]);
$compressNode = $compressNodeList->item(0);
$contribNode->removeChild($compressNode);
}
示例11: OneQuery
function OneQuery($query_key, $text, $limit = 1, $properties = null)
{
$url = 'http://viaf.org/viaf/search?query=' . urlencode('local.personalNames all "' . $text . '"') . '&httpAccept=' . urlencode('application/rss+xml');
//echo $url . "\n";
$xml = get($url);
//echo $xml;
if ($xml != '') {
$dom = new DOMDocument();
$dom->loadXML($xml);
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('opensearch', 'http://a9.com/-/spec/opensearch/1.1/');
$xpath_query = "//opensearch:totalResults";
$count = 0;
$nodeCollection = $xpath->query($xpath_query);
foreach ($nodeCollection as $node) {
$count = $node->firstChild->nodeValue;
}
if ($count > 0) {
$xpath_query = "//item/title";
$nodeCollection = $xpath->query($xpath_query);
foreach ($nodeCollection as $node) {
$hit = new stdclass();
$hit->score = 1;
$hit->match = $count == 1;
$hit->name = $node->firstChild->nodeValue;
$nc = $xpath->query('../guid', $node);
foreach ($nc as $n) {
$hit->id = str_replace('http://viaf.org/viaf/', '', $n->firstChild->nodeValue);
}
$this->StoreHit($query_key, $hit);
}
}
}
}
示例12: run
public function run()
{
header('Content-Type: text/html; charset=UTF-8');
$url = $this->getUrl();
$kategoria = $this->getKategoria();
$dir = opendir('uploads/');
$doc = new \DOMDocument();
@$doc->loadHTMLFile($url);
$xpath = new \DOMXPath($doc);
$titles = $xpath->query('//div[@class="rendslide-box"]//div[@class="product-box"]//td[@class="label"]//p[@class="font-fitter"]');
$links = $xpath->query('//div[@class="rendslide-box"]//div[@class="slide page"]/@onclick');
for ($i = 0; $i < $links->length; $i++) {
$title = iconv('UTF8', 'LATIN1', $titles->item($i)->nodeValue);
$link = str_replace("'", "", str_replace('window.location.href=', '', $links->item($i)->value));
$subDoc = new \DOMDocument();
@$subDoc->loadHTMLFile($link);
$subXpath = new \DOMXPath($subDoc);
$src = $subXpath->query('//div[@id="product"]//div[@class="left"]//a[@class="box"]/@href')->item(0)->value;
$ext = pathinfo($src, PATHINFO_EXTENSION);
$description = $subDoc->saveHTML($subXpath->query('//div[@id="product"]//div[@class="right"]//div[@class="left-margin"]')->item(0));
$permalink = $this->createPermalink($title);
$description = iconv('UTF8', 'LATIN1', $description);
$description = preg_replace('/<p>.<\\/p>/', '', $description);
\DB\base\Manager::connection()->exec("\n INSERT INTO element \n (label, permalink, opis, extension, kategoria_id)\n VALUES\n ('" . $title . "','" . $permalink . "','" . $description . "', '" . $ext . "'," . $kategoria . ")\n ");
$lastId = \DB\base\Manager::connection()->query("\n SELECT id FROM element ORDER BY id DESC LIMIT 1\n ")->fetchColumn();
$imgCt = file_get_contents($src);
$folder = 'uploads/' . $lastId;
mkdir($folder);
$fp = fopen($folder . "/image." . $ext, "w");
fwrite($fp, $imgCt);
fclose($fp);
}
}
示例13: listAll
/**
* Return all languages as array.
*
* @param $keys = an array with values tot return
*
* @return array - resulting languages
*/
public function listAll($keys = null)
{
if ($this->cache === null) {
if ($keys === null) {
$keys = $this->allowed_keys;
} elseif (!is_array($keys)) {
$keys = array($keys);
}
$keys = array_intersect($keys, $this->allowed_keys);
$result = array();
$doc = new DOMDocument();
$doc->load($this->getFile());
$xPath = new DOMXPath($doc);
foreach ($xPath->query("/languages/lang") as $lang) {
/** @var $lang DOMElement */
$r = array();
$code = $lang->getAttribute('code');
foreach ($keys as $key) {
$r[$key] = $xPath->query($key, $lang)->item(0)->nodeValue;
}
$result[$code] = $r;
}
$this->cache = $result;
}
return $this->cache;
}
示例14: getMenus
/**
* get the menus to be added inside the ohers menu item
* @return $menus array of menus
*/
public function getMenus()
{
$menus = array();
if (file_exists(jApp::configPath() . '/havefnubb/hfnumenus.xml')) {
$doc = new DOMDocument();
$doc->load(realpath(jApp::configPath()) . '/havefnubb/hfnumenus.xml');
$xpath = new DOMXPath($doc);
$query = '/menus/menu';
$entries = $xpath->query($query);
$gJConfig = jApp::config();
foreach ($entries as $idx => $menu) {
$queryName = '//name[@lang="' . $gJConfig->locale . '"]';
$items = $xpath->query($queryName);
$name = $items->item($idx)->nodeValue;
$queryItemName = '//menu/itemName';
$items = $xpath->query($queryItemName);
$itemName = $items->item($idx)->nodeValue;
$queryUrl = '//menu/url';
$items = $xpath->query($queryUrl);
$url = $items->item($idx)->nodeValue;
$queryOrder = '//menu/order';
$items = $xpath->query($queryOrder);
$order = $items->item($idx)->nodeValue;
$menus[] = array('itemName' => $itemName, 'name' => $name, 'url' => $url, 'order' => $order);
}
}
return $menus;
}
示例15: testOne
function testOne()
{
$doc = new \DOMDocument();
$doc->load(__DIR__ . '/../../../../../../../resources/sample/Response/response01.xml');
$xpath = new \DOMXPath($doc);
$xpath->registerNamespace('samlp', Protocol::SAML2);
$xpath->registerNamespace('ds', Protocol::NS_XMLDSIG);
$xpath->registerNamespace('a', Protocol::NS_ASSERTION);
$list = $xpath->query('/samlp:Response/a:Assertion/ds:Signature');
$this->assertEquals(1, $list->length);
/** @var $signatureNode \DOMElement */
$signatureNode = $list->item(0);
$signatureValidator = new SignatureXmlValidator();
$signatureValidator->loadFromXml($signatureNode);
$list = $xpath->query('./ds:KeyInfo/ds:X509Data/ds:X509Certificate', $signatureNode);
$this->assertEquals(1, $list->length);
/** @var $signatureNode \DOMElement */
$certificateDataNode = $list->item(0);
$certData = $certificateDataNode->textContent;
$certificate = new X509Certificate();
$certificate->setData($certData);
$key = KeyHelper::createPublicKey($certificate);
$ok = $signatureValidator->validate($key);
$this->assertTrue($ok);
}