本文整理汇总了PHP中DOMNode::hasChildNodes方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNode::hasChildNodes方法的具体用法?PHP DOMNode::hasChildNodes怎么用?PHP DOMNode::hasChildNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNode
的用法示例。
在下文中一共展示了DOMNode::hasChildNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _parseNode
/**
* Parse dom node
*
* @param \DOMNode $node
* @return array
*/
protected function _parseNode(\DOMNode $node)
{
$result = [];
if (false === $node->hasChildNodes()) {
$result = $this->_getSimpleNodeValue($node);
} else {
foreach ($node->childNodes as $childNode) {
$sameNodesCount = $this->_getSameNodesCount($node->getElementsByTagName($childNode->nodeName), $childNode);
/** @var array $nodeValue */
$nodeValue = $this->_parseNode($childNode);
$siblingKey = $this->_getSiblingKey($childNode);
if ($siblingKey !== 0) {
$nodeValue = isset($nodeValue[$childNode->nodeName]) ? $nodeValue[$childNode->nodeName] : $nodeValue;
} elseif (empty($nodeValue)) {
continue;
}
// how many of these child nodes do we have?
if ($sameNodesCount > 1) {
// more than 1 child - make numeric array
$result[$siblingKey][] = $nodeValue;
} else {
$result[$siblingKey] = $nodeValue;
}
}
// if the child is <foo>bar</foo>, the result will be array(bar)
// make the result just 'bar'
if (count($result) == 1 && isset($result[0])) {
$result = current($result);
}
}
$attributes = $this->_parseNodeAttributes($node);
$result = array_merge($result, $attributes);
return $result;
}
示例2: process
/**
* @param DOMNode $node
* @param ProxyObject $proxy
*/
private function process(DOMNode $node, ProxyObject $proxy)
{
$proxy->setName($node->nodeName);
if ($node->hasAttributes()) {
for ($i = 0; $i < $node->attributes->length; $i++) {
$attribute = $node->attributes->item($i);
$proxy->set($attribute->name, $attribute->value);
}
}
if ($node->hasChildNodes()) {
$nodeTypes = array();
foreach ($node->childNodes as $childNode) {
if ($childNode->nodeName === '#text') {
$proxy->setValue($childNode->nodeValue);
} else {
$childProxy = new ProxyObject();
$this->process($childNode, $childProxy);
$nodeTypes[$childProxy->getName()][] = $childProxy;
}
}
foreach ($nodeTypes as $tagName => $nodes) {
$proxy->set($tagName, $nodes);
}
}
}
示例3: getXml
/**
* @param \DOMNode $parent
* @param \AerialShip\LightSaml\Meta\SerializationContext $context
* @return \DOMNode
*/
function getXml(\DOMNode $parent, SerializationContext $context)
{
$objXMLSecDSig = new \XMLSecurityDSig();
$objXMLSecDSig->setCanonicalMethod($this->getCanonicalMethod());
$key = $this->getXmlSecurityKey();
switch ($key->type) {
case \XMLSecurityKey::RSA_SHA256:
$type = \XMLSecurityDSig::SHA256;
break;
case \XMLSecurityKey::RSA_SHA384:
$type = \XMLSecurityDSig::SHA384;
break;
case \XMLSecurityKey::RSA_SHA512:
$type = \XMLSecurityDSig::SHA512;
break;
default:
$type = \XMLSecurityDSig::SHA1;
}
$objXMLSecDSig->addReferenceList(array($parent), $type, array(Protocol::XMLSEC_TRANSFORM_ALGORITHM_ENVELOPED_SIGNATURE, \XMLSecurityDSig::EXC_C14N), array('id_name' => $this->getIDName(), 'overwrite' => FALSE));
$objXMLSecDSig->sign($key);
$objXMLSecDSig->add509Cert($this->getCertificate()->getData(), false, false);
$firstChild = $parent->hasChildNodes() ? $parent->firstChild : null;
if ($firstChild && $firstChild->localName == 'Issuer') {
// The signature node should come after the issuer node
$firstChild = $firstChild->nextSibling;
}
$objXMLSecDSig->insertSignature($parent, $firstChild);
}
示例4: drawThumbnailZone
/**
* Draw a final layout zone on its thumbnail.
*
* @access private
*
* @param ressource $thumbnail The thumbnail ressource
* @param DOMNode $node The current node zone
* @param array $clip The clip rect to draw
* @param int $background The background color
* @param int $gridcolumn The number of columns in the grid
* @param boolean $lastChild True if the current node is the last child of its parent node
*
* @return int The new X axis position;
*/
private function drawThumbnailZone(&$thumbnail, $node, $clip, $background, $gridcolumn, $lastChild = false)
{
$x = $clip[0];
$y = $clip[1];
$width = $clip[2];
$height = $clip[3];
if (null !== ($spansize = preg_replace('/[^0-9]+/', '', $node->getAttribute('class')))) {
$width = floor($width * $spansize / $gridcolumn);
}
if (false !== strpos($node->getAttribute('class'), 'Child')) {
$height = floor($height / 2);
}
if (!$node->hasChildNodes()) {
$this->drawRect($thumbnail, array($x, $y, $width, $height), $background, $width == $clip[2] || strpos($node->getAttribute('class'), 'hChild'), $lastChild);
return $width + 2;
}
foreach ($node->childNodes as $child) {
if (is_a($child, 'DOMText')) {
continue;
}
if ('clear' == $child->getAttribute('class')) {
$x = $clip[0];
$y = $clip[1] + floor($height / 2) + 2;
continue;
}
$x += $this->drawThumbnailZone($thumbnail, $child, array($x, $y, $clip[2], $height), $background, $gridcolumn, $node->isSameNode($node->parentNode->lastChild));
}
return $x + $width - 2;
}
示例5: _parseInto
/**
* Parse through a child node of this table, usually a tr, thead, or tbody.
*
* This is a recursive safe function.
*
* @param \DOMNode $node
*/
private function _parseInto(\DOMNode $node){
if($node->hasChildNodes()){
$nodes = $node->childNodes;
for($i = 0; $i < $nodes->length; $i++){
/** @var \DOMNode $node */
$node = $nodes->item($i);
$nodeType = $node->nodeName;
switch($nodeType){
case 'tr':
// Increment to the next row on a TR tag!
++$this->_currentRow;
$this->_currentCol = 0;
$this->_parseInto($node);
break;
case 'thead':
case 'tbody':
// These simply get parsed again for TR tags.
$this->_parseInto($node);
break;
case 'td':
case 'th':
$this->_parseCell($node);
break;
}
}
}
}
示例6: queryChildren
/**
*通过指定的XPath和DOM对象查找子节点信息
*@param string $path xpath格式路径(example: '/Location/CountryRegion', './State') 具体参考:http://www.w3school.com.cn/xpath/
*@param DOMNode $DOMNode
*@param DOMXpath $xpath
*@return DOMNodeList|[] $children 返回一个空数组或者一个DOMNodeList对象
*/
function queryChildren($path, $DOMNode, $xpath)
{
$children = array();
if ($DOMNode->hasChildNodes()) {
$children = $xpath->query($path, $DOMNode);
}
return $children;
}
示例7: mobilize_remove_element
function mobilize_remove_element(DOMNode $link)
{
// Move all link tag content to its parent node just before it.
while ($link->hasChildNodes()) {
$child = $link->removeChild($link->firstChild);
$link->parentNode->insertBefore($child, $link);
}
// Remove the link tag.
$link->parentNode->removeChild($link);
}
示例8: processNode
private function processNode( DOMNode $node ) {
if( $node ) {
// make sure we are processing a module document
if ( PAGE_TAG == $node->tagName ) {
// process the child documents
if ( $node->hasChildNodes() ) {
$this->processNodeList( $node->childNodes );
}
}
}
}
示例9: checkNode
/**
*
* @param \AppShed\Remote\XML\DOMDocument $xml
* @param \DOMNode $node
*/
private function checkNode($xml, $node)
{
if ($node->hasChildNodes()) {
for ($i = 0; $i < $node->childNodes->length; $i++) {
$this->checkNode($xml, $node->childNodes->item($i));
}
} else {
if ($node instanceof \DOMElement && !in_array($node->tagName, ['img', 'br'])) {
$node->appendChild($xml->createTextNode(''));
}
}
}
示例10: setParent
/**
* @param DOMNode $parentElement - root element iteratoru
* @throws LBoxExceptionConfig
*/
public function setParent(DOMNode $parentElement)
{
if (strlen($this->nodeName) < 1) {
throw new LBoxExceptionConfig(LBoxExceptionConfig::MSG_ABSTRACT_NODENAME_NOT_DEFINED, LBoxExceptionConfig::CODE_ABSTRACT_NODENAME_NOT_DEFINED);
}
$this->parentElement = $parentElement;
// nacteme first child
if ($this->parentElement->hasChildNodes()) {
$firstChild = $this->parentElement->firstChild;
// preskakovani irelevantnich nodu (#TEXT, #COMMENT etc..)
while ($firstChild->nodeName != $this->nodeName) {
if (!$firstChild->nextSibling instanceof DOMNode) {
break;
}
$firstChild = $firstChild->nextSibling;
}
if ($firstChild->nodeName == $this->nodeName) {
$this->items[] = $firstChild;
}
}
}
示例11: insertChildrenBefore
/**
* Insert nodes into target as first childs.
*
* @param DOMNode $targetNode
* @param array|DOMNodeList|FluentDOM $contentNodes
*/
public static function insertChildrenBefore($targetNode, $contentNodes)
{
$result = array();
if ($targetNode instanceof DOMElement) {
$firstChild = $targetNode->hasChildNodes() ? $targetNode->childNodes->item(0) : NULL;
foreach ($contentNodes as $contentNode) {
if ($contentNode instanceof DOMElement || $contentNode instanceof DOMText) {
$result[] = $targetNode->insertBefore($contentNode->cloneNode(TRUE), $firstChild);
}
}
}
return $result;
}
示例12: nodeValue
/**
* @param \DOMNode $node
* @return array|null|string
*/
private function nodeValue(\DOMNode $node)
{
$typeAttribute = $node->attributes->getNamedItem('type');
if ($typeAttribute && $typeAttribute->textContent === 'collection') {
return $this->collectionToArray($node->childNodes);
} elseif ($node->hasChildNodes()) {
if ($node->childNodes->length === 1 && $node->childNodes->item(0) instanceof \DOMText) {
return $node->textContent;
} else {
return $this->nodesToArray($node->childNodes);
}
}
return null;
}
示例13: removeCharacterDataNodes
private static function removeCharacterDataNodes(\DOMNode $node)
{
$node->normalize();
if ($node->hasChildNodes()) {
for ($i = $node->childNodes->length - 1; $i >= 0; $i--) {
$child = $node->childNodes->item($i);
if ($child instanceof \DOMCharacterData) {
if (!strlen(trim($child->data))) {
$node->removeChild($child);
}
}
}
}
}
示例14: setNodeContent
/**
* Set the contents of a DOMNode.
*
* @param \DOMNode $node
* A DOMNode object.
* @param string $content
* The text or HTML that will replace the contents of $node.
*/
protected function setNodeContent(\DOMNode $node, $content)
{
// Remove all children of the DOMNode.
while ($node->hasChildNodes()) {
$node->removeChild($node->firstChild);
}
if (strlen($content)) {
// Load the contents into a new DOMDocument and retrieve the elements.
$replacement_nodes = Html::load($content)->getElementsByTagName('body')->item(0);
// Finally, import and append the contents to the original node.
foreach ($replacement_nodes->childNodes as $replacement_node) {
$replacement_node = $node->ownerDocument->importNode($replacement_node, TRUE);
$node->appendChild($replacement_node);
}
}
}
示例15: findStringNode
/**
* @param string $needle
* @param DOMNode $elem
* @return \DOMNode|bool
*/
private function findStringNode($needle, DOMNode $elem)
{
if ($elem->nodeType === XML_TEXT_NODE && strpos($elem->data, $needle) !== false) {
return $elem;
}
if (!$elem->hasChildNodes()) {
return false;
}
foreach ($elem->childNodes as $child) {
$node = $this->findStringNode($needle, $child);
if ($node !== false) {
return $node;
}
}
return false;
}