本文整理汇总了PHP中DomXPath::query方法的典型用法代码示例。如果您正苦于以下问题:PHP DomXPath::query方法的具体用法?PHP DomXPath::query怎么用?PHP DomXPath::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomXPath
的用法示例。
在下文中一共展示了DomXPath::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: parse_search
private function parse_search($html)
{
$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 = array();
for ($i = 0; $i < $torrents->length; $i++) {
$torrent = $torrents->item($i);
$status = $this->clean($torrent->childNodes->item(2)->attributes->getNamedItem('title')->textContent);
$category = $this->clean($torrent->childNodes->item(4)->textContent);
$title = $this->clean($torrent->childNodes->item(6)->textContent);
$torrent_id = (int) $this->clean($links->item($i)->attributes->getNamedItem('data-topic_id')->textContent);
$detail_url = "http://rutracker.org/forum/viewtopic.php?t={$torrent_id}";
$author_url = parse_url($torrent->childNodes->item(8)->firstChild->firstChild->attributes->getNamedItem('href')->textContent);
$author_id = explode('=', $author_url['query']);
$author_id = $author_id[1];
$author = array("id" => (int) $author_id, "name" => $this->clean($torrent->childNodes->item(8)->firstChild->firstChild->textContent));
$download_url = $this->clean($torrent->childNodes->item(10)->childNodes->item(3)->attributes->getNamedItem('href')->textContent);
$size = $this->clean(str_replace(' ↓', '', $torrent->childNodes->item(10)->childNodes->item(3)->textContent));
$seeders = (int) $this->clean($torrent->childNodes->item(12)->firstChild->textContent);
$leachers = (int) $this->clean($torrent->childNodes->item(14)->textContent);
$downloads = (int) $this->clean($torrent->childNodes->item(16)->textContent);
$added = date('d-m-Y', $this->clean($torrent->childNodes->item(18)->childNodes->item(1)->textContent));
$result[] = array("id" => $torrent_id, "title" => $title, "category" => $category, "status" => $status, "detail_url" => $detail_url, "author" => $author, "size" => $size, "download_url" => $download_url, "seeders" => $seeders, "leachers" => $leachers, "downloads" => $downloads, "added" => $added);
}
return $result;
}
示例3: testAppendXmlData
/**
* test xml generation for IPhone
*
* birthday must have 12 hours added
*/
public function testAppendXmlData()
{
$imp = new DOMImplementation();
$dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
$testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
$testDoc->formatOutput = true;
$testDoc->encoding = 'utf-8';
$appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
$email = new Syncroton_Model_FileReference(array('contentType' => 'text/plain', 'data' => 'Lars'));
$email->appendXML($appData, $this->_testDevice);
#echo $testDoc->saveXML();
$xpath = new DomXPath($testDoc);
$xpath->registerNamespace('AirSync', 'uri:AirSync');
$xpath->registerNamespace('AirSyncBase', 'uri:AirSyncBase');
$xpath->registerNamespace('Email', 'uri:Email');
$xpath->registerNamespace('Email2', 'uri:Email2');
$nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:ContentType');
$this->assertEquals(1, $nodes->length, $testDoc->saveXML());
$this->assertEquals('text/plain', $nodes->item(0)->nodeValue, $testDoc->saveXML());
$nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/ItemOperations:Data');
$this->assertEquals(1, $nodes->length, $testDoc->saveXML());
$this->assertEquals('TGFycw==', $nodes->item(0)->nodeValue, $testDoc->saveXML());
// try to encode XML until we have wbxml tests
$outputStream = fopen("php://temp", 'r+');
$encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
$encoder->encode($testDoc);
}
示例4: _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;
}
示例5: 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());
}
示例6: 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;
}
示例7: 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;
}
}
示例8: 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;
}
示例9: testExpandProperty
public function testExpandProperty()
{
$list = Tinebase_Group::getInstance()->getGroupById(Tinebase_Core::getUser()->accountPrimaryGroup);
$body = '<?xml version="1.0" encoding="UTF-8"?>
<A:expand-property xmlns:A="DAV:">
<A:property name="expanded-group-member-set" namespace="http://calendarserver.org/ns/">
<A:property name="last-name" namespace="http://calendarserver.org/ns/"/>
<A:property name="principal-URL" namespace="DAV:"/>
<A:property name="calendar-user-type" namespace="urn:ietf:params:xml:ns:caldav"/>
<A:property name="calendar-user-address-set" namespace="urn:ietf:params:xml:ns:caldav"/>
<A:property name="first-name" namespace="http://calendarserver.org/ns/"/>
<A:property name="record-type" namespace="http://calendarserver.org/ns/"/>
<A:property name="displayname" namespace="DAV:"/>
</A:property>
</A:expand-property>';
$request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/principals/groups/' . $list->list_id . '/'));
$request->setBody($body);
$this->server->httpRequest = $request;
$this->server->exec();
$responseDoc = new DOMDocument();
$responseDoc->loadXML($this->response->body);
#$responseDoc->formatOutput = true; echo $responseDoc->saveXML();
$xpath = new DomXPath($responseDoc);
$xpath->registerNamespace('cal', 'urn:ietf:params:xml:ns:caldav');
$xpath->registerNamespace('cs', 'http://calendarserver.org/ns/');
$nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/groups/' . $list->list_id . '/"]');
$this->assertEquals(1, $nodes->length, 'group itself (not shown by client) is missing');
$nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/intelligroups/' . $list->list_id . '/"]');
$this->assertEquals(1, $nodes->length, 'intelligroup (to keep group itself) is missing');
$nodes = $xpath->query('///cs:expanded-group-member-set/d:response/d:href[text()="/principals/users/' . Tinebase_Core::getUser()->contact_id . '/"]');
$this->assertEquals(1, $nodes->length, 'user is missing');
}
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:32,代码来源:ExpandedPropertiesReportTest.php
示例10: testGetProperties
/**
* test testGetProperties method
*/
public function testGetProperties()
{
$body = '<?xml version="1.0" encoding="utf-8"?>
<propfind xmlns="DAV:">
<prop>
<default-alarm-vevent-date xmlns="urn:ietf:params:xml:ns:caldav"/>
<default-alarm-vevent-datetime xmlns="urn:ietf:params:xml:ns:caldav"/>
<default-alarm-vtodo-date xmlns="urn:ietf:params:xml:ns:caldav"/>
<default-alarm-vtodo-datetime xmlns="urn:ietf:params:xml:ns:caldav"/>
</prop>
</propfind>';
$request = new Sabre\HTTP\Request(array('REQUEST_METHOD' => 'PROPFIND', 'REQUEST_URI' => '/calendars/' . Tinebase_Core::getUser()->contact_id, '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('cal', 'urn:ietf:params:xml:ns:caldav');
$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vevent-datetime');
$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vevent-date');
$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-datetime');
$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
$nodes = $xpath->query('//d:multistatus/d:response/d:propstat/d:prop/cal:default-alarm-vtodo-date');
$this->assertEquals(1, $nodes->length, $responseDoc->saveXML());
$this->assertNotEmpty($nodes->item(0)->nodeValue, $responseDoc->saveXML());
}
开发者ID:ingoratsdorf,项目名称:Tine-2.0-Open-Source-Groupware-and-CRM,代码行数:38,代码来源:PluginDefaultAlarmsTest.php
示例11: getGlyphs
/**
* This function will return an associative array of all Glyphs equipped on the character.
*
* Associative Array Format:
* "name" - Name of Glyph
* "type" = Major, Minor, or Prime
* "url" - URL of the Glyph
* "itemNumber" - Unique item number of the Glyph.
*
* @return - An Associative Array.
*/
public function getGlyphs($character, $server) {
$cacheFileName = Functions::getCacheDir().'talents_'.$character.'.html';
$contents = Functions::getPageContents($this->talentURLBuilder($character, $server), $cacheFileName);
$dom = Functions::loadNewDom($contents);
$xpath = new DomXPath($dom);
$glyphTypes = array("major", "minor", "prime");
$glyphArray = array();
foreach($glyphTypes as $gT) {
$glyphNames = $xpath->query('//div[@class="character-glyphs-column glyphs-'.$gT.'"]/ul/li[@class="filled"]/a/span[@class="name"]');
$glyphLinks = $xpath->query('//div[@class="character-glyphs-column glyphs-'.$gT.'"]/ul/li[@class="filled"]/a/@href');
$ctr = 0;
foreach($glyphNames as $g) {
$itemNumber = explode("/", $glyphLinks->item($ctr)->nodeValue);
$tmpArray = array(
"name" => trim(utf8_decode($g->nodeValue)),
"type" => $gT,
"url" => $glyphLinks->item($ctr)->nodeValue,
"itemNumber" => $itemNumber[4] );
array_push($glyphArray, $tmpArray);
$ctr++;
}
}
return $glyphArray;
}
示例12: 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;
}
示例13: xpathQuery
protected function xpathQuery($html, $xpath)
{
$dom = new \DomDocument();
$dom->loadHtml($html);
$domXpath = new \DomXPath($dom);
return $domXpath->query($xpath);
}
示例14: 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);
}
示例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();
}