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


PHP SimpleXMLIterator::key方法代码示例

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


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

示例3: printf

}
if (!$quiet) {
    printf("Done." . PHP_EOL . "Getting cash import file list ... ");
}
$files = get_files();
if (!$files) {
    unlink(COOKIE_FILE);
    die("Cannot get file list!" . PHP_EOL);
}
if (!$quiet) {
    printf("Done." . PHP_EOL);
}
$xml = new SimpleXMLIterator($files);
$xml->rewind();
while ($xml->valid()) {
    if ($xml->key() == "rows") {
        $rows = $xml->getChildren();
        $rows->rewind();
        while ($rows->valid()) {
            if ($rows->key() == "row") {
                $fileid = $filename = NULL;
                $props = $rows->getChildren();
                $props->rewind();
                while ($props->valid()) {
                    switch ($props->key()) {
                        case "id":
                            $fileid = strval($props->current());
                            break;
                        case "file_name":
                            $filename = strval($props->current());
                    }
开发者ID:Akheon23,项目名称:lms,代码行数:31,代码来源:lms-cashimport-bgz.php

示例4: parse

 /**
  * Parses object. Turns raw XML(NPRML) into various object properties.
  */
 function parse()
 {
     if (!empty($this->xml)) {
         $xml = $this->xml;
     } else {
         $this->notices[] = 'No XML to parse.';
         return;
     }
     $object = simplexml_load_string($xml);
     $this->add_simplexml_attributes($object, $this);
     if (!empty($object->message)) {
         $this->message->id = $this->get_attribute($object->message, 'id');
         $this->message->level = $this->get_attribute($object->message, 'level');
     }
     if (!empty($object->list->story)) {
         foreach ($object->list->story as $story) {
             $parsed = new NPRMLEntity();
             $this->add_simplexml_attributes($story, $parsed);
             //Iterate trough the XML document and list all the children
             $xml_iterator = new SimpleXMLIterator($story->asXML());
             $key = NULL;
             $current = NULL;
             for ($xml_iterator->rewind(); $xml_iterator->valid(); $xml_iterator->next()) {
                 $current = $xml_iterator->current();
                 $key = $xml_iterator->key();
                 if ($key == 'image' || $key == 'audio' || $key == 'link') {
                     // images
                     if ($key == 'image') {
                         $parsed->{$key}[] = $this->parse_simplexml_element($current);
                     }
                     // audio
                     if ($key == 'audio') {
                         $parsed->{$key}[] = $this->parse_simplexml_element($current);
                     }
                     // links
                     if ($key == 'link') {
                         $type = $this->get_attribute($current, 'type');
                         $parsed->{$key}[$type] = $this->parse_simplexml_element($current);
                     }
                 } else {
                     //if ->$key exist, see if it's an array.  if it is, add the next child.
                     if (!empty($parsed->{$key})) {
                         //if it's not an array, make an array, add the existing element to it
                         if (!is_array($parsed->{$key})) {
                             $parsed->{$key} = array($parsed->{$key});
                         }
                         // then add the new child.
                         $parsed->{$key}[] = $this->parse_simplexml_element($current);
                     } else {
                         //The key wasn't parsed already, so just add the current element.
                         $parsed->{$key} = $this->parse_simplexml_element($current);
                     }
                 }
             }
             $body = '';
             if (!empty($parsed->textWithHtml->paragraphs)) {
                 foreach ($parsed->textWithHtml->paragraphs as $paragraph) {
                     $body = $body . $paragraph->value . "\n\n";
                 }
             }
             $parsed->body = $body;
             $this->stories[] = $parsed;
         }
         //if the query didn't have a sort parameter, reverse the order so that we end up with
         //stories in reverse-chron order.
         //there are no params and 'sort=' is not in the URL
         if (empty($this->request->params) && !stristr($this->request->request_url, 'sort=')) {
             $this->stories = array_reverse($this->stories);
         }
         //there are params, and sort is not one of them
         if (!empty($this->request->params) && !array_key_exists('sort', $this->request->params)) {
             $this->stories = array_reverse($this->stories);
         }
     }
 }
开发者ID:nprds,项目名称:nprapi-wordpress,代码行数:78,代码来源:NPRAPI.php

示例5: key

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

示例6: flushExit

    flushExit();
    exit;
} else {
    // Log open XML-setup filename
    $strDescription = '- open XML-setup filename "' . $filenameXmlSetup . '"' . PHP_EOL;
    $strLine = '';
    logLog(0, $strDescription, $strLine, 2);
}
// parse through XML-setup and store values in
for ($xmlSetupIterator->rewind(); $xmlSetupIterator->valid(); $xmlSetupIterator->next()) {
    // $arrXmlSection[<[section]>] = <0..n>  | Section order from top to bottom
    // $arrXmlSectionKey[<[section]>][<key>] = <0..n>  | Key order from top to bottom
    // $arrXmlParameter[<key>] = <value>
    // $nXmlSection
    // $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
开发者ID:HaakonME,项目名称:xml-analyse,代码行数:31,代码来源:13_setup-read.inc.php

示例7: var_dump

<pre>
<?php 
$xmlIterator = new SimpleXMLIterator('<books><book>PHP basics</book><book>XML basics</book></books>');
print_r($xmlIterator->current());
echo var_dump($xmlIterator->key());
//bool(false)
$xmlIterator->rewind();
// rewind to the first element
print_r($xmlIterator->current());
echo var_dump($xmlIterator->key());
//string(4) "book"
?>
</pre>
开发者ID:pixlr,项目名称:zce-1,代码行数:13,代码来源:key.php

示例8: 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

示例9: key

 function key()
 {
     return $this->it_actual->key();
 }
开发者ID:emma5021,项目名称:toba,代码行数:4,代码来源:toba_importador_plan.php

示例10: 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


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