本文整理汇总了PHP中DomXPath类的典型用法代码示例。如果您正苦于以下问题:PHP DomXPath类的具体用法?PHP DomXPath怎么用?PHP DomXPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DomXPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTransfers
/**
* @param string $accountNumber
* @param int|null $maxItems
* @param \DateTime|null $dateFrom
* @param \DateTime|null $dateTo
* @return \mixed[]
*/
public function getTransfers($accountNumber, $maxItems = null, DateTime $dateFrom = null, DateTime $dateTo = null)
{
$data = $this->getRawData($accountNumber, $dateFrom, $dateTo);
$transferData = substr($data, strpos($data, '<table class=\'main\'>'));
$transferData = substr($transferData, 0, strpos($transferData, '</table>') + 8);
$dom = new \DOMDocument();
$dom->loadHTML($transferData);
$finder = new \DomXPath($dom);
$nodes = $finder->query('//table[@class="main"]//tbody//tr');
$transfers = array();
/** @var \DOMElement $node */
$i = 1;
$length = $nodes->length;
foreach ($nodes as $node) {
$value = str_replace(',', '.', trim($node->childNodes->item(2)->nodeValue));
$value = (double) str_replace(' ', '', $value);
$transfers[] = array(\DateTime::createFromFormat('d.m.Y', $node->childNodes->item(0)->nodeValue), $value, $node->childNodes->item(12)->nodeValue, $node->childNodes->item(14)->nodeValue);
if ($maxItems !== null && $i >= $maxItems) {
break;
}
$i++;
if ($i >= $length) {
break;
}
}
$stateData = substr($data, strpos($data, '<table class=\'summary\'>'));
$stateData = substr($stateData, 0, strpos($stateData, '</table>') + 8);
$dom = new \DOMDocument();
$dom->loadHTML($stateData);
$finder = new \DomXPath($dom);
$nodes = $finder->query('//table[@class="summary"]//tbody//tr//td[2]');
$value = trim($nodes->item(0)->nodeValue);
$value = str_replace(',', '.', $value);
return array('state' => (double) str_replace(' ', '', $value), 'transfers' => $transfers);
}
示例2: getInputs
/**
* Fetch and Parse a form for input fields
*
*/
public function getInputs($type = 'text')
{
$content = preg_replace("/&(?!(?:apos|quot|[gl]t|amp);|#)/", '&', $this->source);
$doc = new DOMDocument();
@$doc->loadHTML($content);
$xpath = new DomXPath($doc);
$list = array();
if ($type == 'text') {
$items = $xpath->query('//form//input | //form//select | //form//textarea');
foreach ($items as $item) {
if ($item->getAttribute('type') != 'submit' and $item->getAttribute('name') != 'Submit-button') {
if ($item->getAttribute('type') != 'hidden') {
$field = str_replace('[]', '', $this->has_attribute($item, 'name'));
$field = trim($field);
array_push($list, $field);
}
}
}
} elseif ($type == 'hidden') {
$items = $xpath->query('//input | //select');
foreach ($items as $item) {
if ($item->getAttribute('type') == 'hidden') {
array_push($list, array('name' => trim($this->has_attribute($item, 'name')), 'value' => trim($this->has_attribute($item, 'value'))));
}
}
}
return $list;
}
示例3: getProductComments
/**
*
* Enter description here ...
* @param unknown_type $url
*/
public static function getProductComments($url)
{
header('Content-type: text/html; charset=utf-8');
$url = "http://ormatek.com/products/980";
$doc = file_get_contents($url);
$doc = mb_convert_encoding($doc, 'HTML-ENTITIES', "UTF-8");
$query = ".//*[@class='comment']";
$dom = new DomDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($doc);
$xpath = new DomXPath($dom);
$nodes = $xpath->query($query);
$i = 0;
if (!is_array($nodes)) {
return null;
}
foreach ($nodes as $node) {
$name = $node->getElementsByTagName("b")->item(0)->nodeValue;
$text = $node->getElementsByTagName("p")->item(0)->nodeValue;
$date = $node->getElementsByTagName("span")->item(0)->nodeValue;
$rating = 0;
$i++;
$param[] = array('id' => $i, 'name' => $name, 'date' => $date, 'rating' => $rating, 'text' => $text);
}
return $param;
}
示例4: handle
/**
* Handle provided directory
*
* Optionally an existing result file can be provided
*
* If a valid file could be generated the file name is supposed to be
* returned, otherwise return null.
*
* @param Project $project
* @param string $existingResult
*
* @return string
*/
public function handle(Project $project, $existingResult = null)
{
if (!isset($project->analyzers['pdepend'])) {
return;
}
$pdependResultFile = $project->dataDir . '/' . $project->analyzers['pdepend'];
$document = new \DomDocument();
$document->load($pdependResultFile);
$xPath = new \DomXPath($document);
foreach ($xPath->query('//package') as $packageNode) {
$packageCommits = 0;
foreach ($xPath->query('./class', $packageNode) as $classNode) {
$fileNode = $xPath->query('./file', $classNode)->item(0);
$file = $fileNode->getAttribute('name');
$classCommits = $this->countGitChangesPerFileRange($project, $file, $classNode->getAttribute('start'), $classNode->getAttribute('end'));
$packageCommits += $classCommits;
$classNode->setAttribute('commits', $classCommits);
foreach ($xPath->query('./method', $classNode) as $methodNode) {
$methodCommits = $this->countGitChangesPerFileRange($project, $file, $methodNode->getAttribute('start'), $methodNode->getAttribute('end'));
$methodNode->setAttribute('commits', $methodCommits);
}
}
$packageNode->setAttribute('commits', $packageCommits);
}
$document->save($pdependResultFile);
return null;
}
示例5: extractFromHtml
/**
* Collects all translateable strings(from tags with 'trans' attribute) from html templates
*
* @param string $file absoulute path to file
*/
function extractFromHtml($file)
{
$dom = new DomDocument();
$dom->loadHTMLFile($file);
$xpath = new DomXPath($dom);
$nodes = $xpath->query("//*[@trans]");
foreach ($nodes as $i => $node) {
// $info = "<{$node->tagName}> at $file";
$info = "";
if ($node->hasAttribute('context')) {
$info = 'Context: ' . $node->getAttribute('context') . '. ' . $info;
}
if ($node->hasAttribute('placeholder')) {
$this->addTranslationStr($node->getAttribute('placeholder'), $info);
}
if ($node->hasAttribute('title')) {
$this->addTranslationStr($node->getAttribute('title'), $info);
}
if ($node->hasAttribute('data-intro')) {
$this->addTranslationStr($node->getAttribute('data-intro'), $info);
}
if ($node->nodeValue != '' && $node->getAttribute('trans') != 'attr-only') {
$this->addTranslationStr($node->nodeValue, $info);
}
}
}
示例6: _createBlockCode
private static function _createBlockCode($code)
{
if (substr($code, 0, 5) == '<span') {
$dom = new DomDocument();
$dom->loadXML($code);
$xpath = new DomXPath($dom);
$parentSpan = $xpath->query('/span')->item(0);
$block_code = self::$_dom->createElement('fo:inline');
$block_code->setAttribute('color', substr($parentSpan->getAttributeNode('style')->value, 7, 7));
$nodes = $xpath->query('/span/node()');
foreach ($nodes as $node) {
if ($node->nodeType == XML_ELEMENT_NODE) {
$child = self::$_dom->createElement('fo:inline', $node->nodeValue);
$child->setAttribute('color', substr($node->getAttributeNode('style')->value, 7, 7));
} else {
$child = self::$_dom->importNode($node, true);
}
$block_code->appendChild($child);
}
if (preg_match("/^\\s+\$/", $block_code->firstChild->textContent)) {
$block_code->removeChild($block_code->firstChild);
}
} else {
$block_code = self::$_dom->createElement('fo:inline', $code);
}
return $block_code;
}
示例7: testSearch
/**
* test xml generation for IPhone
*/
public function testSearch()
{
$doc = new DOMDocument();
$doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
<Search xmlns="uri:Search">
<Store>
<Name>GAL</Name>
<Query>Lars</Query>
<Options>
<Range>0-3</Range>
<RebuildResults/>
<DeepTraversal/>
</Options>
</Store>
</Search>
');
$search = new Syncroton_Command_Search($doc, $this->_device, null);
$search->handle();
$responseDoc = $search->getResponse();
#$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
$xpath = new DomXPath($responseDoc);
$xpath->registerNamespace('Search', 'uri:Search');
$nodes = $xpath->query('//Search:Search/Search:Status');
$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
$nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Total');
$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
$this->assertEquals(5, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
$nodes = $xpath->query('//Search:Search/Search:Response/Search:Store/Search:Result');
$this->assertEquals(4, $nodes->length, $responseDoc->saveXML());
#$this->assertEquals(Syncroton_Command_Search::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $responseDoc->saveXML());
}
示例8: testGetProperties
/**
* test testGetProperties method
*/
public function testGetProperties()
{
$body = '<?xml version="1.0" encoding="utf-8"?>
<propfind xmlns="DAV:">
<prop>
<getlastmodified xmlns="DAV:"/>
<getcontentlength xmlns="DAV:"/>
<resourcetype xmlns="DAV:"/>
<getetag xmlns="DAV:"/>
<id xmlns="http://owncloud.org/ns"/>
</prop>
</propfind>';
$request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/remote.php/webdav/' . Tinebase_Core::getUser()->accountDisplayName, 'HTTP_DEPTH' => '0'));
$request->setBody($body);
$this->server->httpRequest = $request;
$this->server->exec();
//var_dump($this->response->body);
$this->assertEquals('HTTP/1.1 207 Multi-Status', $this->response->status);
$responseDoc = new DOMDocument();
$responseDoc->loadXML($this->response->body);
//$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
$xpath = new DomXPath($responseDoc);
$xpath->registerNamespace('owncloud', 'http://owncloud.org/ns');
$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/owncloud:id');
$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
}
示例9: parse
/**
* @param string $html
* @return TorrentsCollection
*/
public function parse(string $html) : TorrentsCollection
{
libxml_use_internal_errors(true);
$doc = new \DOMDocument();
$doc->loadHTML($html);
$finder = new \DomXPath($doc);
$torrents = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' hl-tr ')]");
$links = $finder->query("//*[contains(@class, 'med tLink hl-tags bold')]");
$result = new TorrentsCollection();
for ($i = 0; $i < $torrents->length; $i++) {
if (is_null($links->item($i))) {
continue;
}
$childNodes = $torrents->item($i)->childNodes;
$status = self::clean($childNodes->item(2)->attributes->getNamedItem('title')->textContent);
$category = self::clean($childNodes->item(4)->textContent);
$title = self::clean($childNodes->item(6)->textContent);
$torrentId = (int) self::clean($links->item($i)->attributes->getNamedItem('data-topic_id')->textContent);
$detailUrl = self::DETAIL_URL . $torrentId;
$authorUrl = parse_url($childNodes->item(8)->firstChild->firstChild->attributes->getNamedItem('href')->textContent);
$authorId = (int) explode('=', $authorUrl['query'])[1];
$authorName = self::clean($childNodes->item(8)->firstChild->firstChild->textContent);
$downloadUrl = self::clean($childNodes->item(10)->childNodes->item(3)->attributes->getNamedItem('href')->textContent);
$downloadUrl = self::DOWNLOAD_URL . $downloadUrl;
$size = self::clean(str_replace(' ↓', '', $childNodes->item(10)->childNodes->item(3)->textContent));
$seeders = (int) self::clean($childNodes->item(12)->firstChild->textContent);
$leachers = (int) self::clean($childNodes->item(14)->textContent);
$downloads = (int) self::clean($childNodes->item(16)->textContent);
$added = (new \DateTimeImmutable())->setTimestamp((int) self::clean($childNodes->item(18)->childNodes->item(1)->textContent));
$torrent = (new Torrent())->setId($torrentId)->setTitle($title)->setCategory($category)->setStatus($status)->setDetailUrl($detailUrl)->setAuthorId($authorId)->setAuthorName($authorName)->setSize($size)->setDownloadUrl($downloadUrl)->setSeeders($seeders)->setLeachers($leachers)->setDownloads($downloads)->setAdded($added);
$result->add($torrent);
}
return $result;
}
示例10: leistungsschutzrecht_fetchsites
function leistungsschutzrecht_fetchsites()
{
require_once "include/network.php";
$sites = array();
$url = "http://www.vg-media.de/lizenzen/digitale-verlegerische-angebote/wahrnehmungsberechtigte-digitale-verlegerische-angebote.html";
$site = fetch_url($url);
$doc = new DOMDocument();
@$doc->loadHTML($site);
$xpath = new DomXPath($doc);
$list = $xpath->query("//td/a");
foreach ($list as $node) {
$attr = array();
if ($node->attributes->length) {
foreach ($node->attributes as $attribute) {
$attr[$attribute->name] = $attribute->value;
}
}
if (isset($attr["href"])) {
$urldata = parse_url($attr["href"]);
if (isset($urldata["host"]) and !isset($urldata["path"])) {
$cleanedurlpart = explode("%", $urldata["host"]);
$hostname = explode(".", $cleanedurlpart[0]);
$site = $hostname[sizeof($hostname) - 2] . "." . $hostname[sizeof($hostname) - 1];
$sites[$site] = $site;
}
}
}
if (sizeof($sites)) {
set_config('leistungsschutzrecht', 'sites', $sites);
}
}
示例11: xpathQuery
protected function xpathQuery($html, $xpath)
{
$dom = new \DomDocument();
$dom->loadHtml($html);
$domXpath = new \DomXPath($dom);
return $domXpath->query($xpath);
}
示例12: ovfImport
public function ovfImport($url, $xpath = false)
{
$this->url = $url;
$dom = new DomDocument();
$loaded = $dom->load($url);
if (!$loaded) {
return $loaded;
}
$xpath = new DomXPath($dom);
// register the namespace
$xpath->registerNamespace('envl', 'http://schemas.dmtf.org/ovf/envelope/1');
$vs_nodes = $xpath->query('//envl:VirtualSystem');
// selects all name element
$refs_nodes = $xpath->query('//envl:References');
// selects all name element
$disk_nodes = $xpath->query('//envl:DiskSection');
// selects all name element
$refs_nodes_0 = $refs_nodes->item(0);
$disk_nodes_0 = $disk_nodes->item(0);
$vs_nodes_0 = $vs_nodes->item(0);
if ($refs_nodes_0 && $disk_nodes_0 && $vs_nodes_0) {
$this->buildReferences($refs_nodes_0);
$this->buildDiskSection($disk_nodes_0);
$this->buildVirtualSystem($vs_nodes_0);
return true;
} else {
return false;
}
}
示例13: DataAsHTML
function DataAsHTML($xslFileName)
{
$xmlData = new SimpleXMLElement('<page/>');
$this->generateXML($xmlData, $this->data);
$xmlfilemodule = simplexml_load_file("modules/" . $this->data['name'] . "/elements.xml");
$xmlData = dom_import_simplexml($xmlData)->ownerDocument;
foreach (dom_import_simplexml($xmlfilemodule)->childNodes as $child) {
$child = $xmlData->importNode($child, TRUE);
$xmlData->documentElement->appendChild($child);
}
$xslfile = "templates/" . $this->template_name . "/" . $xslFileName . ".xsl";
$xslfilemodule = "modules/" . $this->data['name'] . "/elements.xsl";
if (in_array($this->data['name'], $this->selfPages)) {
$xslfile = "templates/" . $this->template_name . "/" . $this->data['name'] . ".xsl";
}
$domXSLobj = new DOMDocument();
$domXSLobj->load($xslfile);
$xpath = new DomXPath($domXSLobj);
$next = $xpath->query('//xsl:include');
$next = $next->item(0);
$next->setAttribute('href', $xslfilemodule);
$next->setAttribute('xml:base', ROOT_SYSTEM);
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($domXSLobj);
return $xsl->transformToXml($xmlData);
}
示例14: getProducts
function getProducts()
{
include "../classes/httpFile.php";
include "../functions/crawler_functions.php";
error_reporting(E_ALL ^ E_WARNING);
$http = new HttpConnection();
$http->setCookiePath("cookies/");
$http->init();
$DOM = new DOMDocument();
$url_array = split(PHP_EOL, file_get_contents('../file/cats_list.ccd'));
while (count($url_array) > 0) {
$url = array_shift($url_array);
$http->get($url, true);
get_dom($url, $DOM, $http);
$finder = new DomXPath($DOM);
$classname = "product-container";
$product = $finder->query("//*[contains( normalize-space( @class ), ' {$classname} ' )\r\n\t\t \t\t\tor substring( normalize-space( @class ), 1, string-length( '{$classname}' ) + 1 ) = '{$classname} '\r\n\t\t \t\t\tor substring( normalize-space( @class ), string-length( @class ) - string-length( '{$classname}' ) ) = ' {$classname}'\r\n\t\t \t\t\tor @class = '{$classname}']");
foreach ($product as $p) {
$enlaces = $p->getElementsByTagName('a');
$enlace = $enlaces->item(0)->getAttribute('href');
echo $enlace . '<br/>';
file_put_contents("../file/url_list.ccd", $enlace . PHP_EOL, FILE_APPEND);
}
}
$http->close();
}
示例15: bold
function bold()
{
$this->CI =& get_instance();
$content = "";
$output = $this->CI->output->get_output();
$dom = new DOMDocument();
$dom->loadHTML($output);
$finder = new DomXPath($dom);
$classname = "lead";
$nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' {$classname} ')]");
foreach ($nodes as $node) {
$words = explode(' ', $node->nodeValue);
$temp = $dom->createElement("p");
$temp->setAttribute("class", "lead");
foreach ($words as $word) {
if (ctype_upper($word[0])) {
//First char is uppercase
$newNode = $dom->createElement('strong', $word . " ");
$temp->appendChild($newNode);
} else {
$newNode = $dom->createTextNode($word . " ");
$temp->appendChild($newNode);
}
}
$node->parentNode->replaceChild($temp, $node);
}
echo $dom->saveHTML();
}