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


PHP SimpleXMLIterator::attributes方法代码示例

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


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

示例1: attributes

 /**
  * Helper method to retrieve simplexml attributes
  * @param string $ns
  * @param boolean $is_prefix
  * @return array
  */
 function attributes($ns = null, $is_prefix = null)
 {
     $attr = (array) parent::attributes($ns, $is_prefix);
     if (isset($attr['@attributes'])) {
         return $attr['@attributes'];
     }
     return [];
 }
开发者ID:jgswift,项目名称:xral,代码行数:14,代码来源:Iterator.php

示例2: _XMLNodeToArray

 /**
  * Recursively convert \SimpleXMLIterator to array
  *
  * @param \SimpleXMLIterator $XMLNode
  *
  * @return array
  */
 private static function _XMLNodeToArray($XMLNode)
 {
     $result = array();
     $attributes = $XMLNode->attributes();
     foreach ($attributes as $k => $v) {
         $val = (string) $v;
         if ($val == "True" || $val == "False") {
             $val = (bool) $val;
         }
         $result[$k] = $val;
     }
     $children = $XMLNode->children();
     foreach ($children as $chK => $chNode) {
         $result['Items'][] = self::_XMLNodeToArray($chNode);
     }
     return $result;
 }
开发者ID:bfday,项目名称:yii2-payture-module,代码行数:24,代码来源:Payture.php

示例3: getChildrenValues

 /**
  * @param \SimpleXMLIterator $element
  * @param \Twig_Template     $template
  *
  * @param string             $formId
  * @param string             $xPath
  * @param string             $requiredChildren
  * @param array              $identityRefs
  *
  * @return array|bool
  */
 public function getChildrenValues($element, $template, $formId, $xPath = "", $requiredChildren = "", $identityRefs = array())
 {
     $retArr = array();
     $targetAttributes = array('key', 'iskey', 'mandatory');
     foreach ($element as $label => $el) {
         $attributesArr = array_fill_keys($targetAttributes, false);
         foreach ($element->attributes() as $name => $attr) {
             if ($name == "key") {
                 $attributesArr[$name] = (string) $attr[0];
             }
         }
         foreach ($el->attributes() as $name => $attr) {
             if (in_array($name, array('iskey', 'mandatory'))) {
                 $attributesArr[$name] = (string) $attr[0];
             }
         }
         if (($attributesArr['iskey'] !== "true" && $attributesArr['key'] == false || $requiredChildren !== "" && $label != $requiredChildren) && $attributesArr['mandatory'] == false) {
             continue;
         }
         if ($attributesArr['key'] !== false) {
             $requiredChildren = $attributesArr['key'];
         } else {
             $requiredChildren = "";
         }
         $twigArr = array();
         $twigArr['key'] = "";
         $twigArr['xpath'] = "";
         $twigArr['element'] = $el;
         $twigArr['useHiddenInput'] = true;
         $twigArr['moduleIdentityRefs'] = $identityRefs;
         $newXPath = $xPath . "/*";
         $res = $this->getAvailableLabelValuesForXPath($formId, $newXPath);
         $retArr[$label] = array();
         if (isset($res['labelsAttributes'][$label])) {
             $retArr[$label]['labelAttributes'] = $res['labelsAttributes'][$label];
         }
         $retArr[$label]['valueElem'] = $this->removeMultipleWhitespaces($template->renderBlock('configInputElem', $twigArr));
         $retArr[$label]['children'] = $this->getChildrenValues($el, $template, $formId, $newXPath, $requiredChildren);
     }
     return sizeof($retArr) ? $retArr : false;
 }
开发者ID:Barathi07,项目名称:Netopeer-GUI,代码行数:52,代码来源:XMLoperations.php

示例4: createFromXML

 /**
  * This class method is used to construct a ResourceDescriptor object by providing the XML for that object.
  *
  * @param string $xml - XML String defining ResourceDescriptor
  * @return ResourceDescriptor
  */
 public static function createFromXML($xml)
 {
     $sxi = new \SimpleXMLIterator($xml);
     $temp = new self((string) $sxi->attributes()->name, (string) $sxi->attributes()->wsType, (string) $sxi->attributes()->uriString, (string) $sxi->attributes()->isNew);
     $desc = !empty($sxi->description) ? (string) $sxi->description : null;
     $label = !empty($sxi->label) ? (string) $sxi->label : null;
     $date = !empty($sxi->creationDate) ? (string) $sxi->creationDate : null;
     $temp->setLabel($label);
     $temp->setDescription($desc);
     $temp->setCreationDate($date);
     foreach ($sxi->resourceDescriptor as $nestRd) {
         $temp->children[] = ResourceDescriptor::createFromXML($nestRd->asXML());
     }
     foreach ($sxi->resourceProperty as $prop) {
         $temp->properties[] = ResourceProperty::createFromXML($prop->asXML());
     }
     return $temp;
 }
开发者ID:pathumf89,项目名称:AAFrecovery,代码行数:24,代码来源:ResourceDescriptor.php

示例5: arrayFromXml

    /**
     * Create an Array from XML
     *
     * This method sets up the SimpleXMLIterator and starts the parsing
     * of an xml body to iterate through it and transform it into
     * an array that can be used by the developers.
     *
     * @param string $xml
     * @return array An array mapped to the passed xml
     */
    public static function arrayFromXml($xml)
    {
        // replace namespace defs
        $xml = str_replace('xmlns=', 'ns=', $xml);

        // catch libxml errors
        libxml_use_internal_errors(true);
        try {
            $iterator = new SimpleXMLIterator($xml);
        } catch(Exception $e) {
            $xmlErrors = libxml_get_errors();
             return new Frapi_Exception(
                     'Xml Parsing Failed', 
                     'INVALID_XML', 
                     400, 
                     'xml_parsing'
                     );
             libxml_clear_errors();
        }
        
        $xmlRoot = $iterator->getName();
        $type = $iterator->attributes()->type;

        // SimpleXML provides the root information on construct
        self::$_xmlRoot = $iterator->getName();
        self::$_responseType = $type;
        
        // return the mapped array with the root element as the header
        return array($xmlRoot => self::_iteratorToArray($iterator));
    }
开发者ID:reith2004,项目名称:frapi,代码行数:40,代码来源:XmlParser.php

示例6: arrayFromXml

 /**
  * sets up the SimpleXMLIterator and starts the parsing
  * @access public
  * @param string $xml
  * @return array array mapped to the passed xml
  */
 public static function arrayFromXml($xml)
 {
     // SimpleXML provides the root information on construct
     $iterator = new SimpleXMLIterator($xml);
     $xmlRoot = Braintree_Util::delimiterToCamelCase($iterator->getName());
     $type = $iterator->attributes()->type;
     self::$_xmlRoot = $iterator->getName();
     self::$_responseType = $type;
     // return the mapped array with the root element as the header
     return array($xmlRoot => self::_iteratorToArray($iterator));
 }
开发者ID:danielcoats,项目名称:schoolpress,代码行数:17,代码来源:Parser.php


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