本文整理汇总了PHP中DOMNodeList::item方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNodeList::item方法的具体用法?PHP DOMNodeList::item怎么用?PHP DOMNodeList::item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNodeList
的用法示例。
在下文中一共展示了DOMNodeList::item方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _filter_empty_elements
/**
* Remove all empty elements
*
* @param DOMNodeList $DOMNodeList The list of all elements we are checking
* @return DOMNodeList The modified list of all remaining elements
*/
protected function _filter_empty_elements(DOMNodeList $DOMNodeList)
{
$NodeListIndex = 0;
// We might reduce $DOMNodeList->length during the loop
for ($NodeListIndex = 0; $NodeListIndex < $DOMNodeList->length; ++$NodeListIndex) {
$DOMNode = $DOMNodeList->item($NodeListIndex);
if (!isset($DOMNode->nodeName) || !in_array($DOMNode->nodeName, $this->_checkTagNames, true)) {
continue;
}
// Climb up to make sure we’re not in an Instant Article element (which should have proper handling elsewhere)
$parentNode = $DOMNode;
while (isset($parentNode->nodeName) && $parentNode->nodeName != 'body') {
if ('figure' == $parentNode->nodeName && false !== strpos($parentNode->getAttribute('class'), 'op-')) {
// We found an element that’s likely to be an Instant Article element
continue 2;
}
$parentNode = $parentNode->parentNode;
}
// Check all childnodes first
if (is_a($DOMNode, 'DOMElement') && isset($DOMNode->childNodes) && is_a($DOMNode->childNodes, 'DOMNodeList')) {
$this->_filter_empty_elements($DOMNode->childNodes);
}
if (isset($DOMNode->nodeValue) && '' == trim($DOMNode->nodeValue)) {
if (!isset($DOMNode->childNodes) || is_null($DOMNode->childNodes) || is_a($DOMNode->childNodes, 'DOMNodeList') && !$DOMNode->childNodes->length) {
// If the element is an empty node, remove it. But we must have a parentNode to remove a node
if (is_a($DOMNode->parentNode, 'DOMElement')) {
$DOMNode->parentNode->removeChild($DOMNode);
}
}
}
}
return $DOMNodeList;
}
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:39,代码来源:class-instant-articles-dom-transform-filter-emptyelements.php
示例2: getDomNodeValue
/**
* Get single dom node value from node list at 0-index, or null when empty result
*
* @param \DOMNodeList $item
* @throws \Exception
* @return string|null
*/
protected function getDomNodeValue(\DOMNodeList $item)
{
if ($item->length == 0) {
return null;
}
return $item->item(0) instanceof \DOMAttr ? trim($item->item(0)->value) : trim($item->item(0)->nodeValue);
}
示例3: current
/**
* Returns the current value of the iterator
*
* @return DOMNode|NULL Returns NULL if there is no current value
*/
public function current()
{
if ($this->offset === NULL) {
return NULL;
} else {
return $this->nodelist->item($this->offset);
}
}
示例4: current
/**
* Implement SeekableIterator::current()
*
* @return Zend_Service_Amazon_Item
*/
public function current()
{
$dom = $this->_results->item($this->_currentIndex);
if ($dom === null) {
throw new Exception\RuntimeException('no results found');
}
return new Item($dom);
}
示例5: next
public function next()
{
if ($this->index < $this->count() - 1) {
$this->current = $this->domNodeList->item(++$this->index);
} else {
$this->current = null;
}
return $this->current;
}
示例6: filterNodeListByName
/**
* Check if tagName from $nodes are correct depending on $name
*
* @param DOMNodeList $nodes to check
* @param string $name to compare with tagName
*
* @return array of nodes with correct $name
*/
public static function filterNodeListByName($nodes, $name)
{
$res = array();
for ($i = 0; $i < $nodes->length; $i++) {
if ($nodes->item($i)->tagName === $name) {
$res[] = $nodes->item($i);
}
}
return $res;
}
示例7: list
/**
* @param UCS $ucs
* @param \DOMNodeList $cols
* @param \DomXPath $xpath
*/
function __construct($ucs, $cols, $xpath)
{
$this->ucs = $ucs;
$this->contract_id = $ucs->getContractId();
$date_str = $cols->item(0)->nodeValue;
list($date_str) = explode("*", $date_str, 2);
$this->date = new \DateTime($date_str);
$this->currency = $cols->item(1)->nodeValue;
$this->total_amount = floatval(str_replace(" ", "", $cols->item(2)->nodeValue));
$this->total_commission = floatval(str_replace(" ", "", $cols->item(3)->nodeValue));
$link = $cols->item(6);
while (!$link->getAttribute("href")) {
$link = $link->firstChild;
}
$this->terminals_url = UCS::URL_REPORTS . $link->getAttribute("href");
}
示例8: iterate
/**
* @param DOMNodeList $nodeList
*/
protected function iterate(DOMNodeList $nodeList)
{
for ($i = 0; $i < $nodeList->length; $i++) {
$node = $nodeList->item($i);
$this->childrenVisitor->visit($node);
}
}
示例9: current
/**
* Implements SeekableIterator::current().
*
* @return void
* @throws Zend_Service_Exception
* @abstract
*/
public function current()
{
if ($this->_resultClass === null) {
throw new Zend_Service_Exception('Result class not provided');
}
$class = $this->_resultClass;
return new $class($this->_results->item($this->_currentIndex));
}
示例10: offsetGet
/**
* @param int $offset
* @return mixed Can return all value types.
*/
public function offsetGet($offset)
{
$node = $this->nodeList->item($offset);
if ($node instanceof \DOMNode) {
return new DomXPath($this->domDocument, $this->namespaces, $node);
}
return null;
}
示例11: _constructFromNodeList
/**
* Transforms DOMNodeList to array of posts
*
* @param DOMNodeList $nodeList
* @return void
*/
private function _constructFromNodeList(DOMNodeList $nodeList)
{
for ($i = 0; $i < $nodeList->length; $i++) {
$curentNode = $nodeList->item($i);
if ($curentNode->nodeName == 'post') {
$this->_addPost(new Zend_Service_Delicious_Post($this->_service, $curentNode));
}
}
}
示例12: parseRelease
/**
*
* @param DOMNodeList $node
*/
private function parseRelease($node)
{
$extra = $node->item(3)->nodeValue;
if (strlen($extra)) {
list($size, $files) = explode("|", $extra);
$size = trim($size);
$files = trim($files);
}
$entry = new Release();
$entry->release = $node->item(2)->nodeValue;
$entry->type = $node->item(1)->nodeValue;
$entry->date = new DateTime($node->item(0)->nodeValue, new DateTimeZone('UTC'));
$entry->size = intval($size) * 1024 * 1024;
// as bytes
$entry->files = intval($files);
$entry->nuke = $node->item(4)->nodeValue;
return $entry;
}
示例13: constructFromNodeList
/**
* Transforms DOMNodeList to array of posts
*
* @param DOMNodeList $nodeList
* @return void
*/
private function constructFromNodeList(\DOMNodeList $nodeList)
{
for ($i = 0; $i < $nodeList->length; $i++) {
$curentNode = $nodeList->item($i);
if ($curentNode->nodeName == 'post') {
$this->addPost(new Post($this->service, $curentNode));
}
}
}
示例14: getFirstElement
/**
*
* @param DOMNodeList $nodeList
* @return type
*/
public static function getFirstElement($nodeList)
{
if ($nodeList instanceof \DOMNodeList) {
if ($nodeList->length > 0x0) {
return $nodeList->item(0x0);
} else {
return null;
}
}
}
示例15: FixXmlNodes
/**
* Fix a list of nodes corresponding to an array of objects.
*
* @param \DOMNodeList $nodeList the node list matching <var>$objects</var>
* @param array $objects the objects array matching <var>$nodeList</var>
* @param \DOMXPath $xpath the xpath object representing the DOM
*/
private function FixXmlNodes(\DOMNodeList $nodeList, array $objects, \DOMXPath $xpath)
{
if ($nodeList->length == sizeof($objects)) {
$i = 0;
foreach ($objects as $object) {
$this->FixXmlNode($nodeList->item($i), $object, $xpath);
$i++;
}
}
}