當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DOMNodeList類代碼示例

本文整理匯總了PHP中DOMNodeList的典型用法代碼示例。如果您正苦於以下問題:PHP DOMNodeList類的具體用法?PHP DOMNodeList怎麽用?PHP DOMNodeList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DOMNodeList類的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: iterate

 /**
  * @param DOMNodeList $nodeList
  */
 protected function iterate(DOMNodeList $nodeList)
 {
     for ($i = 0; $i < $nodeList->length; $i++) {
         $node = $nodeList->item($i);
         $this->childrenVisitor->visit($node);
     }
 }
開發者ID:Tjorriemorrie,項目名稱:app,代碼行數:10,代碼來源:DOMNodeVisitorBase.php

示例3: 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);
 }
開發者ID:mishki-svami,項目名稱:pa-core,代碼行數:14,代碼來源:ExternalTruckingAbstract.php

示例4: 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));
         }
     }
 }
開發者ID:robertodormepoco,項目名稱:zf2,代碼行數:15,代碼來源:PostList.php

示例5: _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));
         }
     }
 }
開發者ID:brianbui171,項目名稱:website_zend_1.11,代碼行數:15,代碼來源:PostList.php

示例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;
 }
開發者ID:inscriptionweb,項目名稱:kriss_feed,代碼行數:18,代碼來源:Rss.php

示例7: 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++;
         }
     }
 }
開發者ID:Katoga,項目名稱:g-ads,代碼行數:17,代碼來源:SoapRequestXmlFixer.php

示例8: 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;
         }
     }
 }
開發者ID:citypay,項目名稱:php-sdk,代碼行數:15,代碼來源:XmlHelper.php

示例9: addNodes

 /**
  * Add all nodes from the fixtures xml document.
  *
  * If the root node is not called jcr:root, autogenerate a root node.
  *
  * @param string       $workspaceName
  * @param \DOMNodeList $nodes
  *
  * @return DBUnitFixtureXML
  */
 public function addNodes($workspaceName, \DOMNodeList $nodes)
 {
     $node = $nodes->item(0);
     if ('jcr:root' !== $node->getAttributeNS($this->namespaces['sv'], 'name')) {
         $this->addRootNode('tests');
     }
     foreach ($nodes as $node) {
         $this->addNode($workspaceName, $node);
     }
     return $this;
 }
開發者ID:jackalope,項目名稱:jackalope-prismic,代碼行數:21,代碼來源:DBUnitFixtureXML.php

示例10: getElementByNodeName

 public static function getElementByNodeName(DOMNodeList $nodeList, $nodeName)
 {
     for ($i = 0; $i < $nodeList->length; $i++) {
         /*DOMNode*/
         $item = $nodeList->item($i);
         if (self::cleearNS($item->nodeName) == $nodeName) {
             return self::getDOMDocument($item);
         }
     }
     return null;
 }
開發者ID:sigmadesarrollo,項目名稱:logisoft,代碼行數:11,代碼來源:XmlUtil.php

示例11: _transform_elements

 /**
  * Dispatch each element in the nodelist to the transformer
  *
  * Note that we work directly on the DOMNodeList itself. Objects are passed by ref.
  *
  * @since 0.1
  * @param DOMNodeList  $DOMNodeList  List of images
  * @return DOMNodeList  The DOMNodeList. If you want to chain.
  */
 protected function _transform_elements(DOMNodeList $DOMNodeList)
 {
     // A foreach won’t work as we are changing the elements
     for ($i = 0; $i < $DOMNodeList->length; ++$i) {
         $origLength = $DOMNodeList->length;
         $this->_transform_element($DOMNodeList->item($i));
         if ($origLength !== $DOMNodeList->length) {
             // The element is replaced by an element of another type and is no longer in the nodelist
             --$i;
         }
     }
     return $DOMNodeList;
 }
開發者ID:gopinathshiva,項目名稱:wordpress-vip-plugins,代碼行數:22,代碼來源:class-instant-articles-dom-transform-filter.php

示例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;
 }
開發者ID:Rogiel,項目名稱:predb,代碼行數:22,代碼來源:OrlyDB.php

示例13: transcodeList

 /**
  * @param \DOMNodeList $list
  * @param null $parentEvent
  */
 protected function transcodeList(\DOMNodeList $list, $parentEvent = null)
 {
     $i = 0;
     while ($node = $list->item($i)) {
         switch ($node->nodeType) {
             case XML_TEXT_NODE:
                 $event = new TranscodeTextEvent($node, $parentEvent, $i);
                 $this->transcodeTextNode($event);
                 break;
             case XML_ELEMENT_NODE:
                 $event = new TranscodeElementEvent($node, $parentEvent, $i);
                 $this->transcodeElementNode($event);
                 break;
             default:
                 // ?
         }
         $i++;
     }
 }
開發者ID:robmasters,項目名稱:optimus,代碼行數:23,代碼來源:Transcoder.php

示例14: 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 Pre_Release();
     $entry->release = $node->item(1)->nodeValue;
     $entry->type = $node->item(0)->nodeValue;
     if ($node->length == 3) {
         $entry->date = strtotime(substr($node->item(2)->nodeValue, 4)) + $vbulletin->options['release_time_offset'];
     } else {
         $entry->size = intval($node->item(2)->nodeValue) * 1024 * 1024;
         //as bytes
         $entry->files = intval($files);
     }
     return $entry;
 }
開發者ID:raumfish,項目名稱:predb,代碼行數:23,代碼來源:Pre_ScnSrc_Adapter.php

示例15: 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);
 }
開發者ID:robertodormepoco,項目名稱:zf2,代碼行數:13,代碼來源:ResultSet.php


注:本文中的DOMNodeList類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。