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


PHP DOMElement::hasAttributes方法代码示例

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


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

示例1: toArrayTree

 /**
  * @param \DOMNode $node
  * @param $path
  * @return array|string
  */
 protected function toArrayTree(\DOMElement $node, $path)
 {
     $hasChildren = false;
     $record = [];
     $currentPath = $path . '/' . $node->nodeName;
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $child) {
             if ($child instanceof \DOMElement) {
                 $hasChildren = true;
                 if (in_array($currentPath, $this->iterationPath) && in_array($child->nodeName, $this->iterationTag)) {
                     $record[$child->nodeName][] = $this->toArrayTree($child, $currentPath);
                 } else {
                     $record[$child->nodeName] = $this->toArrayTree($child, $currentPath);
                 }
             }
         }
     }
     if ($node->hasAttributes()) {
         $record["_attributes"] = [];
         foreach ($node->attributes as $attr) {
             $record["_attributes"][$attr->name] = $attr->value;
         }
         if (!$hasChildren) {
             $record["_value"] = $node->nodeValue;
         }
     } elseif (!$hasChildren) {
         $record = trim($node->nodeValue);
     }
     return $record;
 }
开发者ID:shopwareLabs,项目名称:SwagImportExport,代码行数:35,代码来源:XmlFileReader.php

示例2: domNodeAttributesToArray

 /**
  * Convert a DOM node's properties into an array
  *
  * @param   DOMElement $node
  * @param   array      $data
  *
  * @return array
  */
 public static function domNodeAttributesToArray($node, $data = array())
 {
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             $data[$attr->nodeName] = $attr->nodeValue;
         }
     }
     return $data;
 }
开发者ID:glauberm,项目名称:cinevi,代码行数:17,代码来源:contenttype.php

示例3: dom_to_array

/**
 * converts a DOMElement to an array representation
 *
 * @param \DOMElement $root
 */
function dom_to_array($root)
{
    // if the node has only a single text node
    if (!$root->hasAttributes() && $root->childNodes->length == 1 && $root->childNodes->item(0)->nodeType == XML_TEXT_NODE) {
        return $root->childNodes->item(0)->nodeValue;
    }
    $result = array();
    if ($root->hasAttributes()) {
        $attrs = $root->attributes;
        foreach ($attrs as $i => $attr) {
            $result["_" . $attr->name] = $attr->value;
        }
    }
    $children = $root->childNodes;
    $group = array();
    $text = "";
    for ($i = 0; $i < $children->length; $i++) {
        $child = $children->item($i);
        if ($child->nodeType == XML_TEXT_NODE) {
            $text = $text . $child->nodeValue;
        } else {
            if (!isset($result[$child->nodeName])) {
                $result[$child->nodeName] = dom_to_array($child);
            } else {
                if (!isset($group[$child->nodeName])) {
                    $tmp = $result[$child->nodeName];
                    $result[$child->nodeName] = array($tmp);
                    $group[$child->nodeName] = 1;
                }
                $result[$child->nodeName][] = dom_to_array($child);
            }
        }
    }
    $trimmed = trim($text);
    if ($trimmed != "") {
        $result['#text'] = $text;
    }
    return $result;
}
开发者ID:dfritschy,项目名称:ezpublish-kernel,代码行数:44,代码来源:convertXML2JSON.php

示例4: createFromXML

 /**
  * Creates and return eZPageBlockItem object from given XML
  *
  * @static
  * @param DOMElement $node
  * @return eZPageBlockItem
  */
 public static function createFromXML(DOMElement $node)
 {
     $newObj = new eZPageBlockItem();
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             $newObj->setAttribute($attr->name, $attr->value);
         }
     }
     foreach ($node->childNodes as $node) {
         if ($node->nodeType == XML_ELEMENT_NODE) {
             $newObj->setAttribute($node->nodeName, $node->nodeValue);
         }
     }
     return $newObj;
 }
开发者ID:nfrp,项目名称:ezflow,代码行数:22,代码来源:ezpageblockitem.php

示例5: parse

 /**
  * Class EcasPhpCASParser
  * @param \DOMElement $root XML element coming from phpCAS
  * @return array Attributes
  * @see \phpCAS
  */
 public function parse(\DOMElement $root)
 {
     phpCAS::trace('Found attribute ' . $root->nodeName);
     $result = array();
     if ($root->hasAttributes()) {
         $attrs = $root->attributes;
         foreach ($attrs as $attr) {
             if ($attr->name == 'number') {
                 continue;
             }
             phpCAS::trace('Additional attribute ' . $attr->name . ' : ' . $attr->value);
             $result['@attributes'][$attr->name] = $attr->value;
         }
     }
     if ($root->hasChildNodes()) {
         $children = $root->childNodes;
         if ($children->length == 1) {
             $child = $children->item(0);
             if ($child->nodeType == XML_TEXT_NODE) {
                 $result['_value'] = $child->nodeValue;
                 return count($result) == 1 ? $result['_value'] : $result;
             }
         }
         $groups = array();
         foreach ($children as $child) {
             $nodeName = str_replace('cas:', '', $child->nodeName);
             phpCAS::traceBegin();
             if ($nodeName == 'groups') {
                 $result['groups'] = array();
                 phpCas::traceBegin();
                 foreach ($child->childNodes as $groupChild) {
                     $result['groups'][] = $this->parse($groupChild);
                 }
                 phpCAS::traceEnd('Parsed groups');
             } elseif (!isset($result[$nodeName])) {
                 $result[$nodeName] = $this->parse($child);
             } else {
                 if (!isset($groups[$nodeName])) {
                     $result[$nodeName] = array($result[$nodeName]);
                     $groups[$nodeName] = 1;
                 }
                 $result[$nodeName][] = $this->parse($child);
             }
             phpCAS::traceEnd();
         }
     }
     return $result;
 }
开发者ID:ec-europa,项目名称:ecas-phpcas-parser,代码行数:54,代码来源:EcasPhpCASParser.php

示例6: purgeEmptyElementsNode

 /**
  * Enlève les élements vide d'un noeud
  *
  * @param DOMElement $node DOMElement
  *
  * @return void
  */
 function purgeEmptyElementsNode($node)
 {
     // childNodes undefined for non-element nodes (eg text nodes)
     if ($node->childNodes) {
         // Copy childNodes array
         $childNodes = array();
         foreach ($node->childNodes as $childNode) {
             $childNodes[] = $childNode;
         }
         // Browse with the copy (recursive call)
         foreach ($childNodes as $childNode) {
             $this->purgeEmptyElementsNode($childNode);
         }
     }
     // Remove if empty
     if (!$node->hasChildNodes() && !$node->hasAttributes() && $node->nodeValue === "") {
         $node->parentNode->removeChild($node);
     }
 }
开发者ID:fbone,项目名称:mediboard4,代码行数:26,代码来源:CCDADomDocument.class.php

示例7: createFromXML

 /**
  * Creates and return eZPageZone object from given XML
  *
  * @static
  * @param DOMElement $node
  * @return eZPageZone
  */
 public static function createFromXML(DOMElement $node)
 {
     $newObj = new eZPageZone();
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             if ($attr->name == 'id') {
                 $value = explode('_', $attr->value);
                 $newObj->setAttribute($attr->name, $value[1]);
             } else {
                 $newObj->setAttribute($attr->name, $attr->value);
             }
         }
     }
     foreach ($node->childNodes as $node) {
         if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'block') {
             $blockNode = eZPageBlock::createFromXML($node);
             $newObj->addBlock($blockNode);
         } elseif ($node->nodeType == XML_ELEMENT_NODE) {
             $newObj->setAttribute($node->nodeName, $node->nodeValue);
         }
     }
     return $newObj;
 }
开发者ID:kuborgh,项目名称:ezflow-ls-extension,代码行数:30,代码来源:ezpagezone.php

示例8: createFromXML

    /**
     * Creates and return eZPageBlock object from given XML
     *
     * @static
     * @param DOMElement $node
     * @return eZPageBlock
     */
    public static function createFromXML( DOMElement $node )
    {
        $newObj = new eZPageBlock();

        if ( $node->hasAttributes() )
        {
            foreach ( $node->attributes as $attr )
            {
                if ( $attr->name == 'id' )
                {
                    $value = explode( '_', $attr->value );
                    $newObj->setAttribute( $attr->name, $value[1] );
                }
                else
                {
                    $newObj->setAttribute( $attr->name, $attr->value );
                }
            }
        }

        foreach ( $node->childNodes as $node )
        {
            if ( $node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'item' )
            {
                $blockItemNode = eZPageBlockItem::createFromXML( $node );
                $newObj->addItem( $blockItemNode );
            }
            elseif ( $node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'rotation' )
            {
                $attrValue = array();

                foreach ( $node->childNodes as $subNode )
                {
                    if ( $subNode->nodeType == XML_ELEMENT_NODE )
                        $attrValue[$subNode->nodeName] = $subNode->nodeValue;
                }

                $newObj->setAttribute( $node->nodeName, $attrValue );
            }
            elseif ( $node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'custom_attributes' )
            {
                $attrValue = array();

                foreach ( $node->childNodes as $subNode )
                {
                    if ( $subNode->nodeType == XML_ELEMENT_NODE )
                        $attrValue[$subNode->nodeName] = $subNode->nodeValue;
                }

                $newObj->setAttribute( $node->nodeName, $attrValue );
            }
            else
            {
                if ( $node->nodeType == XML_ELEMENT_NODE )
                    $newObj->setAttribute( $node->nodeName, $node->nodeValue );
            }
        }

        return $newObj;
    }
开发者ID:ezsystemstraining,项目名称:ez54training,代码行数:67,代码来源:ezpageblock.php

示例9: nodeNotEmpty

 private function nodeNotEmpty(\DOMElement $element)
 {
     return $element->hasChildNodes() || $element->hasAttributes();
 }
开发者ID:baardbaard,项目名称:bb-twitterfeed,代码行数:4,代码来源:XmlSerializationVisitor.php

示例10: getAttributes

 /**
  * 获得节点的属性
  * 
  * 该属性将不包含属性为name的值--规则(name的值将作为解析后数组的key值索引存在)
  * 
  * @param DOMElement $node 节点
  * @return array 返回属性数组
  */
 public function getAttributes($node)
 {
     if (!$node instanceof DOMElement || !$node->hasAttributes()) {
         return array();
     }
     $attributes = array();
     foreach ($node->attributes as $attribute) {
         if (self::NAME != $attribute->nodeName) {
             $value = (string) $attribute->nodeValue;
             $__tmp = strtolower($value);
             $attributes[$attribute->nodeName] = 'false' === $__tmp ? false : ('true' === $__tmp ? true : $value);
         }
     }
     return $attributes;
 }
开发者ID:jellycheng,项目名称:windframework,代码行数:23,代码来源:WindXmlParser.php

示例11: nodeAttr

 private function nodeAttr(\DOMElement $node)
 {
     $attributes = array();
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             $attributes[strtolower($attr->nodeName)] = $attr->nodeValue;
         }
     }
     return $attributes;
 }
开发者ID:donatj,项目名称:mddoc,代码行数:10,代码来源:ConfigParser.php

示例12: parse

 /**
  * Parses the XML element $node and creates a feed element in the current
  * module with name $name.
  *
  * @param string $name The name of the element belonging to the module
  * @param DOMElement $node The XML child from which to take the values for $name
  */
 public function parse($name, DOMElement $node)
 {
     if ($this->isElementAllowed($name)) {
         $element = $this->add($name);
         $value = $node->textContent;
         switch ($name) {
             case 'date':
                 $element->date = $value;
                 break;
             case 'contributor':
             case 'creator':
             case 'publisher':
                 $element->name = $value;
                 break;
             case 'identifier':
                 $element->id = $value;
                 break;
             case 'source':
                 $element->source = $value;
                 break;
             default:
                 $element->text = $value;
         }
         if ($node->hasAttributes()) {
             foreach ($node->attributes as $attribute) {
                 switch ($attribute->name) {
                     case 'lang':
                         $element->language = $attribute->value;
                         break;
                 }
             }
         }
     }
 }
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:41,代码来源:dublincore_module.php

示例13: nodeAttributesToScope

 /**
  * Misc function that maps the node's attributes to a key => value array
  * and results any expressions to actual values
  *
  * @param DOMElement $node
  * @return array
  */
 private function nodeAttributesToScope(DOMElement &$node)
 {
     $myContext = array();
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             if (strpos($attr->value, '${') !== false) {
                 // attribute value contains an expression
                 $expressions = array();
                 preg_match_all('/(\\$\\{)(.*)(\\})/imsxU', $attr->value, $expressions);
                 for ($i = 0; $i < count($expressions[0]); $i++) {
                     $expression = $expressions[2][$i];
                     $myContext[$attr->name] = ExpressionParser::evaluate($expression, $this->dataContext);
                 }
             } else {
                 // plain old string
                 $myContext[$attr->name] = trim($attr->value);
             }
         }
     }
     return $myContext;
 }
开发者ID:ndkhoiits,项目名称:gatein-shindig,代码行数:28,代码来源:TemplateParser.php

示例14: removeChildrenExceptOfKeyElements

 /**
  * removes all children of element except of key elements, which has to remain
  *
  * @param      \DOMElement  $domNode
  * @param      \DOMNodeList $domNodeChildren
  * @param bool              $leaveKey
  * @param bool              $recursive
  *
  * @return int  number of key elements, that remains
  */
 public function removeChildrenExceptOfKeyElements($domNode, $domNodeChildren, $leaveKey = false, $recursive = false)
 {
     $keyElemIndex = $keyElemsCnt = 0;
     while ($domNodeChildren->length > $keyElemIndex) {
         $isKey = $isCreated = false;
         $child = $domNodeChildren->item($keyElemIndex);
         if ($child->hasAttributes()) {
             foreach ($child->attributes as $attr) {
                 if ($attr->nodeName == "iskey" && $attr->nodeValue == "true") {
                     if ($child->hasAttributes()) {
                         foreach ($child->attributes as $attr) {
                             if ($attr->nodeName !== 'xc:operation') {
                                 $attributesArr[] = $attr->nodeName;
                             }
                         }
                         // remove must be in new foreach, previous deletes only first one
                         foreach ($attributesArr as $attrName) {
                             $child->removeAttribute($attrName);
                         }
                     }
                     if ($leaveKey == true) {
                         $keyElemIndex++;
                         $isKey = true;
                     } else {
                         if (isset($child)) {
                             $nodeName = $child->nodeName;
                             $nodeValue = $child->nodeValue;
                             $domNode->setAttribute("GUIcustom_" . $nodeName, $nodeValue);
                         }
                     }
                     $keyElemsCnt++;
                 } elseif ($attr->nodeName == "xc:operation" && $attr->nodeValue == "create") {
                     $keyElemIndex++;
                     $isCreated = true;
                 }
             }
         }
         if (!$isKey && !$isCreated || $leaveKey == false) {
             try {
                 $childrenRemains = 0;
                 // recursively check all children for their key elements
                 if (sizeof($child->childNodes) && $recursive) {
                     foreach ($child->childNodes as $chnode) {
                         if (sizeof($chnode->childNodes)) {
                             $childrenRemains += $this->removeChildrenExceptOfKeyElements($chnode, $chnode->childNodes, $leaveKey, $recursive);
                         }
                     }
                 }
                 if ($childrenRemains == 0) {
                     $domNode->removeChild($child);
                 } else {
                     $keyElemIndex++;
                 }
             } catch (\DOMException $e) {
             }
         }
     }
     if ($domNode->hasAttributes()) {
         foreach ($domNode->attributes as $attr) {
             if (strpos($attr->nodeName, "GUIcustom_") !== 0) {
                 $attributesArr[] = $attr->nodeName;
             }
         }
         // remove must be in new foreach, previous deletes only first one
         foreach ($attributesArr as $attrName) {
             $domNode->removeAttribute($attrName);
         }
     }
     return $keyElemsCnt;
 }
开发者ID:Barathi07,项目名称:Netopeer-GUI,代码行数:80,代码来源:XMLoperations.php

示例15: writeBPT

 /**
  * Writes beginning pair tag.
  *
  * @param XMLWriter $writer
  *   Writer that writes the output.
  * @param DOMElement $node
  *   Current node.
  * @param $id
  *   Current node id.
  */
 protected function writeBPT(\XMLWriter $writer, \DOMElement $node, $id)
 {
     $beginning_tag = '<' . $node->nodeName;
     if ($node->hasAttributes()) {
         $attributes = array();
         /** @var DOMAttr $attribute */
         foreach ($node->attributes as $attribute) {
             $attributes[] = $attribute->name . '="' . $attribute->value . '"';
         }
         $beginning_tag .= ' ' . implode(' ', $attributes);
     }
     $beginning_tag .= '>';
     $writer->startElement('bpt');
     $writer->writeAttribute('id', $id);
     $writer->text($beginning_tag);
     $writer->endElement();
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:27,代码来源:Xliff.php


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