当前位置: 首页>>代码示例>>PHP>>正文


PHP SimpleXMLIterator::hasChildren方法代码示例

本文整理汇总了PHP中SimpleXMLIterator::hasChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLIterator::hasChildren方法的具体用法?PHP SimpleXMLIterator::hasChildren怎么用?PHP SimpleXMLIterator::hasChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleXMLIterator的用法示例。


在下文中一共展示了SimpleXMLIterator::hasChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: xmlToArray

 private function xmlToArray(\SimpleXMLIterator $sxi)
 {
     $a = array();
     for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
         $t = array();
         $current = $sxi->current();
         $attributes = $current->attributes();
         $name = isset($attributes->_key) ? strval($attributes->_key) : $sxi->key();
         // save attributes
         foreach ($attributes as $att_key => $att_value) {
             if ($att_key !== '_key') {
                 $t[$att_key] = strval($att_value);
             }
         }
         // we parse nodes
         if ($sxi->hasChildren()) {
             // children
             $t = array_merge($t, $this->xmlToArray($current));
         } else {
             // it's a leaf
             if (empty($t)) {
                 $t = strval($current);
                 // strval will call _toString()
             } else {
                 $t['_value'] = strval($current);
                 // strval will call _toString()
             }
         }
         $a[$name] = $t;
     }
     return $a;
 }
开发者ID:romaricdrigon,项目名称:metayaml,代码行数:32,代码来源:XmlLoader.php

示例2: _unserializeRecurser

 /**
  * _unserializeRecurser()
  *
  * This method will be used to traverse the depths of the structure
  * as needed to *unserialize* the profile from an xmlIterator
  *
  * @param SimpleXMLIterator $xmlIterator
  * @param Zend_Tool_Project_Profile_Resource $resource
  */
 protected function _unserializeRecurser(SimpleXMLIterator $xmlIterator, Zend_Tool_Project_Profile_Resource $resource = null)
 {
     foreach ($xmlIterator as $resourceName => $resourceData) {
         $contextName = $resourceName;
         $subResource = new Zend_Tool_Project_Profile_Resource($contextName);
         $subResource->setProfile($this->_profile);
         if ($resourceAttributes = $resourceData->attributes()) {
             $attributes = array();
             foreach ($resourceAttributes as $attrName => $attrValue) {
                 $attributes[$attrName] = (string) $attrValue;
             }
             $subResource->setAttributes($attributes);
         }
         if ($resource) {
             $resource->append($subResource, false);
         } else {
             $this->_profile->append($subResource);
         }
         if ($this->_contextRepository->isOverwritableContext($contextName) == false) {
             $subResource->initializeContext();
         }
         if ($xmlIterator->hasChildren()) {
             self::_unserializeRecurser($xmlIterator->getChildren(), $subResource);
         }
     }
 }
开发者ID:c12g,项目名称:stratos-php,代码行数:35,代码来源:Xml.php

示例3: parseXML

 /**
  * Converts a SimpleXMLIterator structure into an associative array.
  *
  * Used to parse an XML response from Mollom servers into a PHP array. For
  * example:
  * @code
  * $elements = new SimpleXmlIterator($response_body);
  * $parsed_response = $this->parseXML($elements);
  * @endcode
  *
  * @param SimpleXMLIterator $sxi
  *   A SimpleXMLIterator structure of the server response body.
  *
  * @return array
  *   An associative, possibly multidimensional array.
  */
 public static function parseXML(SimpleXMLIterator $sxi)
 {
     $a = array();
     $remove = array();
     for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
         $key = $sxi->key();
         // Recurse into non-scalar values.
         if ($sxi->hasChildren()) {
             $value = self::parseXML($sxi->current());
         } else {
             $value = strval($sxi->current());
         }
         if (!isset($a[$key])) {
             $a[$key] = $value;
         } else {
             // First time we reach here, convert the existing keyed item. Do not
             // remove $key, so we enter this path again.
             if (!isset($remove[$key])) {
                 $a[] = $a[$key];
                 // Mark $key for removal.
                 $remove[$key] = $key;
             }
             // Add the new item.
             $a[] = $value;
         }
     }
     // Lastly, remove named keys that have been converted to indexed keys.
     foreach ($remove as $key) {
         unset($a[$key]);
     }
     return $a;
 }
开发者ID:SatiricMan,项目名称:addons,代码行数:48,代码来源:class.mollom.php

示例4: _unserializeRecurser

 protected function _unserializeRecurser(SimpleXMLIterator $projectProfileIterator, Zend_Tool_Provider_ZfProject_ProjectContext_ProjectContextAbstract $context = null)
 {
     foreach ($projectProfileIterator as $projectProfileNodeName => $projectProfileNode) {
         $subContextClass = self::getContextByName($projectProfileNodeName);
         $subContext = new $subContextClass();
         if ($subContext->getContextName() === 'projectProfileFile') {
             $subContext->setProjectProfile($this);
         }
         if ($attributes = $projectProfileNode->attributes()) {
             foreach ($attributes as $attrName => $attrValue) {
                 $clnAttrs[$attrName] = (string) $attrValue;
             }
             $subContext->setParameters($clnAttrs);
         }
         if ($context) {
             $context->append($subContext);
         } else {
             $this->appendProjectContext($subContext);
         }
         if ($projectProfileIterator->hasChildren()) {
             self::_unserializeRecurser($projectProfileIterator->getChildren(), $subContext);
         }
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:24,代码来源:ProjectProfile.php

示例5: simplexmlToArray

 /**
  * Converts SimpleXMLIterator object into an array.
  * @param  SimpleXMLIterator $xmlIterator
  * @return string[]
  */
 public function simplexmlToArray($xmlIterator)
 {
     $xmlStringArray = array();
     for ($xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next()) {
         if ($xmlIterator->hasChildren()) {
             $object = $xmlIterator->current();
             $xmlStringArray[$object->getName()] = $this->simplexmlToArray($object);
         } else {
             $object = $xmlIterator->current();
             $xmlStringArray[$object->getName()] = (string) $xmlIterator->current();
         }
     }
     return $xmlStringArray;
 }
开发者ID:rabbitdigital,项目名称:HRM,代码行数:19,代码来源:ReportGeneratorService.php

示例6: SimpleXMLIterator

<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/1
 * Time: 11:29
 */
$it = new SimpleXMLIterator(file_get_contents('test.xml'));
foreach ($it as $key => $node) {
    echo $key . "<br/>";
    if ($it->hasChildren()) {
        foreach ($it->getChildren() as $element => $value) {
            echo "\t" . $element . " : " . $value . "<br/>";
        }
    }
}
开发者ID:quekaihua,项目名称:StudyTest,代码行数:17,代码来源:10-17.php

示例7: hasChildren

 function hasChildren()
 {
     echo __METHOD__ . "\n";
     return parent::hasChildren();
 }
开发者ID:badlamer,项目名称:hhvm,代码行数:5,代码来源:sxe_004.php

示例8: SimpleXMLIterator

<pre>
<?php 
$xml = <<<XML
<books>
    <book>
        <title>PHP Basics</title>
        <author>Jim Smith</author>
    </book>
    <book>XML basics</book>
</books>
XML;
$xmlIterator = new SimpleXMLIterator($xml);
for ($xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next()) {
    if ($xmlIterator->hasChildren()) {
        var_dump($xmlIterator->current());
    }
}
?>
</pre>
开发者ID:pixlr,项目名称:zce-1,代码行数:19,代码来源:next.php

示例9: switch

 // $nXmlSectionKey
 switch ($xmlSetupIterator->key()) {
     case 'special_char':
         // Log special characters
         $strDescription = '-- special characters "' . $xmlSetupIterator->current() . '"' . PHP_EOL;
         $strLine = '';
         logLog(0, $strDescription, $strLine, $nLogModeSetupXml);
         break;
     case 'parameter':
         // Log parameters
         // $strDescription = '-- parameter "' . $xmlSetupIterator->current() . '"' . PHP_EOL;
         // $strLine = '';
         // logLog(0, $strDescription, $strLine, 2);
         break;
     default:
         if (!$xmlSetupIterator->hasChildren()) {
             // XML-setup error, no exit
             if (2 > $nbXmlSetupError) {
                 $nbXmlSetupError = 1;
             }
             // Empty XML-setup section
             $strDescription = '## Empty XML-setup section "' . $xmlSetupIterator->key() . '" ##' . PHP_EOL;
             $strLine = '';
             logError(0, $strDescription, $strLine, $nLogModeSetupXml);
             if ('' !== trim($xmlSetupIterator->current())) {
                 // Empty XML-setup section, element value
                 $strDescription = '## Empty XML-setup section, element value "' . trim($xmlSetupIterator->current()) . '" ##' . PHP_EOL;
                 $strLine = '';
                 logError(0, $strDescription, $strLine, $nLogModeSetupXml);
             }
         } else {
开发者ID:HaakonME,项目名称:xml-analyse,代码行数:31,代码来源:13_setup-read.inc.php

示例10: sxiToArray

 /**
  * @param SimpleXMLIterator $sxi
  */
 public function sxiToArray($sxi)
 {
     $a = array();
     for ($sxi->rewind(); $sxi->valid(); $sxi->next()) {
         if (!array_key_exists($sxi->key(), $a)) {
             $a[$sxi->key()] = array();
         }
         if ($sxi->hasChildren()) {
             $a[$sxi->key()]['children'] = $this->sxiToArray($sxi->current());
         } else {
             $a[$sxi->key()][] = strval($sxi->current());
         }
     }
     return $a;
 }
开发者ID:Ibrahim1,项目名称:aec,代码行数:18,代码来源:admin.acctexp.class.php

示例11: SimpleXMLIterator

var_dump($xml->asXML());
/*
string(181) "<?xml version="1.0"?>
<application name="ls">
   <param long="list">l</param>
   <param>a</param>
   <help>
       <cmd>h</cmd>
   </help>
   <new-node>1</new-node>
</application>
*/
//----------
$iterator = new SimpleXMLIterator($string);
foreach ($iterator as $key => $value) {
    echo "key: {$key}, value: {$value}\n";
    if ($iterator->hasChildren()) {
        var_dump($iterator->current());
    }
}
/*
key: param, value: l
key: param, value: a
key: help, value:


object(SimpleXMLIterator)#5 (1) {
["cmd"]=>
  string(1) "h"
}
*/
开发者ID:pixlr,项目名称:Zce,代码行数:31,代码来源:simplexml.php

示例12: SimpleXMLIterator

 */
try {
    $xmlString = file_get_contents('spl.xml');
    $simpleIt = new SimpleXMLIterator($xmlString);
    // 循环所有的节点
    foreach (new RecursiveIteratorIterator($simpleIt, 1) as $name => $data) {
        //echo $name, '=>', $data, "<br />";
    }
    // while 循环
    $simpleIt->rewind();
    while ($simpleIt->valid()) {
        /*var_dump($simpleIt->key());
          echo '=>';
          var_dump($simpleIt->current());*/
        // getChildren() 获得当前节点的子节点
        if ($simpleIt->hasChildren()) {
            //var_dump($simpleIt->getChildren());
        }
        $simpleIt->next();
    }
    // xpath 可以通过path直接获得指定节点的值
    var_dump($simpleIt->xpath('animal/category/species'));
} catch (Exception $e) {
    echo $e->getMessage();
}
echo '--------------------------------- SimpleXMLIterator END-----------------------------------', '<br />';
echo '--------------------------------- CachingIterator START-----------------------------------', '<br />';
/**
 * CachingIterator 提前读取一个元素
 * 可以用于确定当前元素是否为最后一个元素
 */
开发者ID:ray0916,项目名称:learn,代码行数:31,代码来源:iterator.php

示例13: xmlToArray

 /**
  * Convert XML iterator to array
  *
  * @static
  * @param \SimpleXMLIterator $xml
  * @param null $ns
  * @return array
  */
 public static function xmlToArray(\SimpleXMLIterator $xml, $ns = null)
 {
     $a = [];
     for ($xml->rewind(); $xml->valid(); $xml->next()) {
         $key = $xml->key();
         if (!isset($a[$key])) {
             $a[$key] = [];
         }
         foreach ($xml->current()->attributes() as $k => $v) {
             $a[$key][self::INDEX_ATTRIBUTES][$k] = (string) $v;
         }
         if ($ns) {
             foreach ($ns as $name) {
                 foreach ($xml->current()->attributes($name) as $k => $v) {
                     $a[$key][self::INDEX_ATTRIBUTES][$k] = (string) $v;
                 }
             }
         }
         if ($xml->hasChildren()) {
             $a[$key][self::INDEX_CONTENT] = self::xmlToArray($xml->current(), $ns);
         } else {
             $a[$key][self::INDEX_CONTENT] = strval($xml->current());
         }
     }
     return $a;
 }
开发者ID:rganin,项目名称:magelight,代码行数:34,代码来源:XmlHelper.php

示例14: _unserializeRecurser

 protected function _unserializeRecurser(SimpleXMLIterator $xmlIterator, Zend_Tool_Project_Structure_Node $node = null)
 {
     foreach ($xmlIterator as $nodeName => $nodeData) {
         $context = Zend_Tool_Project_Structure_Context_Registry::getInstance()->getContext($nodeName);
         $subNode = new Zend_Tool_Project_Structure_Node($context);
         if ($attributes = $nodeData->attributes()) {
             foreach ($attributes as $attrName => $attrValue) {
                 $method = 'set' . $attrName;
                 if (method_exists($subNode, $method)) {
                     $subNode->{$method}((string) $attrValue);
                 } elseif (method_exists($context, $method)) {
                     $context->{$method}((string) $attrValue);
                 }
             }
         }
         if (method_exists($context, 'setGraph')) {
             $context->setGraph($this->_graph);
         }
         if ($node) {
             $node->append($subNode);
         } else {
             $this->_graph->append($subNode);
         }
         if ($xmlIterator->hasChildren()) {
             self::_unserializeRecurser($xmlIterator->getChildren(), $subNode);
         }
     }
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:28,代码来源:Xml.php

示例15: testHasChildrenDuringIteration

function testHasChildrenDuringIteration()
{
    $s = new SimpleXMLIterator(basicXML());
    echo "first level nodes have children: ";
    foreach ($s as $i => $e) {
        echo "{$i}: ", $s->hasChildren() ? 'yes' : 'no', ", ";
    }
    echo "\n";
}
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:builtin_extension_SimpleXMLIterator.php


注:本文中的SimpleXMLIterator::hasChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。