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


PHP DOMNode::hasAttributes方法代码示例

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


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

示例1: 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);
         }
     }
 }
开发者ID:helpfulrobot,项目名称:chrisahhh-silverstripe-importer,代码行数:29,代码来源:XmlDataSource.php

示例2: getElementAttributes

 /**
  * Zwraca liste atrybutow elementu, lub false jeżeli nie ma żadnego
  *
  * @param DOMNode $node
  *
  * @return array|bool
  */
 protected function getElementAttributes(DOMNode $node)
 {
     if ($node->hasAttributes()) {
         $arr = array();
         foreach ($node->attributes as $value) {
             $arr[$value->nodeName] = $value->nodeValue;
         }
         return $arr;
     }
     return false;
 }
开发者ID:b091,项目名称:mkphp-1,代码行数:18,代码来源:DOMDocument.php

示例3: parseNodeProperties

 function parseNodeProperties(DOMNode $paragraph_node)
 {
     /**
      * pPr - text paragraph properties
      */
     $node_properties = array();
     if ($paragraph_node->hasAttributes()) {
         $node_properties['lvl'] = (int) $paragraph_node->getAttribute('lvl');
     }
     $node_properties['bullet_type'] = $this->detectListType($paragraph_node);
     return $node_properties;
 }
开发者ID:TBoonX,项目名称:SlideWiki,代码行数:12,代码来源:Paragraphs.php

示例4: renameNode

 /**
  * Rename DOMNode
  * @param \DOMNode $node
  * @param string $newName
  */
 public static function renameNode($node, $newName)
 {
     $newNode = $node->ownerDocument->createElement($newName);
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attribute) {
             $newNode->setAttribute($attribute->nodeName, $attribute->nodeValue);
         }
     }
     while ($node->firstChild) {
         $newNode->appendChild($node->firstChild);
     }
     $node->parentNode->replaceChild($newNode, $node);
 }
开发者ID:difra-org,项目名称:difra,代码行数:18,代码来源:DOM.php

示例5: getParamDirect

 public function getParamDirect($name = "")
 {
     try {
         if (!$this->node instanceof DOMNode) {
             throw new LBoxExceptionConfig("Cannot get data from destructed config item (after calling config store()). Do get new instance from LBCManager");
         }
         if ($this->node->hasAttributes()) {
             foreach ($this->node->attributes as $attribute) {
                 if ($attribute->name == $name) {
                     return $attribute->value;
                 }
             }
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
开发者ID:palmic,项目名称:lbox,代码行数:17,代码来源:abstract.LBoxConfigItem.php

示例6: toArray

 /**
  * Transform Xml to array
  *
  * @param \DOMNode $node
  * @return array|string
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function toArray(\DOMNode $node)
 {
     $result = [];
     $attributes = [];
     // Collect data from attributes
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attribute) {
             $attributes[$attribute->name] = $attribute->value;
         }
     }
     switch ($node->nodeType) {
         case XML_TEXT_NODE:
         case XML_COMMENT_NODE:
         case XML_CDATA_SECTION_NODE:
             break;
         default:
             if ($node->localName === static::ARGUMENT_KEY) {
                 if (!isset($attributes[static::NAME_ATTRIBUTE_KEY])) {
                     throw new \InvalidArgumentException('Attribute "' . static::NAME_ATTRIBUTE_KEY . '" is absent in the attributes node.');
                 }
                 $result[$attributes[static::NAME_ATTRIBUTE_KEY]] = $this->argumentParser->parse($node);
             } else {
                 $arguments = [];
                 for ($i = 0, $iLength = $node->childNodes->length; $i < $iLength; ++$i) {
                     $itemNode = $node->childNodes->item($i);
                     if (empty($itemNode->localName)) {
                         continue;
                     }
                     if ($itemNode->nodeName === static::ARGUMENT_KEY) {
                         $arguments += $this->toArray($itemNode);
                     } else {
                         $result[$itemNode->localName][] = $this->toArray($itemNode);
                     }
                 }
                 if (!empty($arguments)) {
                     $result[static::DATA_ARGUMENTS_KEY] = $arguments;
                 }
                 if (!empty($attributes)) {
                     $result[static::DATA_ATTRIBUTES_KEY] = $attributes;
                 }
             }
             break;
     }
     return $result;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:54,代码来源:Converter.php

示例7: toArray

 /**
  * Transform Xml to array
  *
  * @param \DOMNode $source
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function toArray(\DOMNode $source)
 {
     $result = [];
     if ($source->hasAttributes()) {
         foreach ($source->attributes as $attr) {
             $result['@attributes'][$attr->name] = $attr->value;
         }
     }
     if (!$source->hasChildNodes()) {
         if (empty($result)) {
             $result = $source->nodeValue;
         }
     } else {
         if ($source->hasChildNodes()) {
             $groups = [];
             foreach ($source->childNodes as $child) {
                 if ($child->nodeType == XML_TEXT_NODE || $child->nodeType == XML_COMMENT_NODE) {
                     continue;
                 }
                 if ($this->isTextNode($child)) {
                     $result[$child->nodeName] = $this->getTextNode($child)->data;
                 } else {
                     if (in_array($child->nodeName, ['validate', 'filter', 'readonly'])) {
                         if (!isset($result[$child->nodeName])) {
                             $result[$child->nodeName] = [];
                         }
                         $result[$child->nodeName][] = $this->toArray($child);
                     } else {
                         if (isset($result[$child->nodeName])) {
                             if (!isset($groups[$child->nodeName])) {
                                 $result[$child->nodeName] = [$result[$child->nodeName]];
                                 $groups[$child->nodeName] = 1;
                             }
                             $result[$child->nodeName][] = $this->toArray($child);
                         } else {
                             $result[$child->nodeName] = $this->toArray($child);
                         }
                     }
                 }
             }
         }
     }
     return $result;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:51,代码来源:Converter.php

示例8: children_to_array

  private static function children_to_array(DOMNode $node) {
    $result = array();
    if ($node->hasAttributes()) {
      foreach ($node->attributes as $name => $attribute) {
	$result[$name] = $attribute->value;
      }
    }

    if ($node->nodeType == XML_TEXT_NODE) {
      $parentName = $node->parentNode->nodeName;
      if ($parentName == 'lat_wgs84' || $parentName == 'long_wgs84') {
	return (double)(trim($node->nodeValue));
      }
      return trim($node->nodeValue);
    }

    $aChild = $node->firstChild;

    while ($aChild !== NULL) {
      $nodeName = $aChild->nodeName;

      if ($nodeName == 'category' || $nodeName == 'contents' || $nodeName == 'floor' || $nodeName == 'altname') {
	if (!array_key_exists($nodeName, $result)) {
	  $result[$nodeName] = array();
	}
	$result[$nodeName][] = self::children_to_array($aChild);
      } else {
	$result[$nodeName] = self::children_to_array($aChild);
      }
      $aChild = $aChild->nextSibling;
    }

    if (array_key_exists('#text', $result)) {
      if (count($result) == 1) {
	return $result['#text'];
      } else {
	return array_diff_key($result, array('#text' => true));
      }
    }

    return $result;

  }
开发者ID:jamespaulmuir,项目名称:MIT-Mobile-Framework,代码行数:43,代码来源:campus_map.php

示例9: wsf_create_payload_for_array

/** create payload for arrays
 * @param $payload_dom - DomDocument for the payload building
 * @param $sig_node - sig model
 * @param $parent_node - The parent node to add the content
 * @param $root_node - The always parent. Just to add all the namespace declaration here..
 * @param $user_arguments - The user given arguments
 * @param $prefix_i - next available prefix index 
 * @param $namespace_map - Just make sure the unique namespace is used. Newly added
    (passed by reference)
 */
function wsf_create_payload_for_array(DomDocument $payload_dom, DOMNode $sig_node, DomNode $parent_node, DomNode $root_node, $user_arguments, &$prefix_i, array &$namespace_map, $mtom_on, &$attachement_map)
{
    ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, "Loading in to creating payload from arrays");
    if (wsf_set_nil_element($user_arguments, $parent_node, $root_node, $prefix_i, $namespace_map)) {
        return TRUE;
    }
    // here we always expect structures with childs
    if (!$sig_node->hasChildNodes()) {
        // Just take the first namespace in the map to create the xml elements in
        // the unknown structure..
        $values = array_values($namespace_map);
        $prefix = $values[0];
        wsf_create_payload_for_unknown_class_map($payload_dom, $parent_node, $user_obj, $prefix);
        return;
    }
    $classmap = NULL;
    if ($sig_node->hasAttributes()) {
        if (!is_array($user_arguments)) {
            ws_log_write(__FILE__, __LINE__, WSF_LOG_DEBUG, $payload_dom->localName . " can not be empty, note: just set to NULL to make it as NULL");
            wsf_set_nil_element(NULL, $parent_node, $root_node, $prefix_i, $namespace_map);
            return;
        }
        wsf_build_content_model($sig_node, $user_arguments, $parent_node, $payload_dom, $root_node, $classmap, $prefix_i, $namespace_map, $mtom_on, $attachement_map);
    } else {
        // this situation meets only for non-wrapped mode as doclit-bare wsdls
        $the_only_node = $sig_node->firstChild;
        //  handle simple content extension seperatly
        if ($the_only_node->attributes->getNamedItem(WSF_CONTENT_MODEL) && $the_only_node->attributes->getNamedItem(WSF_CONTENT_MODEL)->value == WSF_SIMPLE_CONTENT) {
            wsf_build_content_model($the_only_node, $user_arguments, $parent_node, $payload_dom, $root_node, $classmap, $prefix_i, $namespace_map, $mtom_on, $attachement_map);
        } else {
            $is_simple = FALSE;
            if ($the_only_node->attributes->getNamedItem(WSF_WSDL_SIMPLE) && $the_only_node->attributes->getNamedItem(WSF_WSDL_SIMPLE)->value == "yes") {
                $is_simple = TRUE;
            }
            $param_type = NULL;
            if ($the_only_node->attributes->getNamedItem(WSF_TYPE)) {
                $param_type = $the_only_node->attributes->getNamedItem(WSF_TYPE)->value;
            }
            if ($is_simple) {
                $is_list = FALSE;
                if ($the_only_node->attributes->getNamedItem(WSF_LIST) && $the_only_node->attributes->getNamedItem(WSF_LIST)->value == "yes") {
                    $is_list = TRUE;
                }
                if ($user_arguments === NULL || !is_array($user_arguments) || $is_list) {
                    $serialized_value = wsf_wsdl_serialize_php_value($param_type, $user_arguments, $the_only_node, $parent_node, $parent_node, $prefix_i, $namespace_map, $root_node);
                    $text_node = $payload_dom->createTextNode($serialized_value);
                    $parent_node->appendChild($text_node);
                } else {
                    if (is_array($user_arguments)) {
                        ws_log_write(__FILE__, __LINE__, WSF_LOG_ERROR, "Array is specified when non-array is expected for the root node\n");
                    }
                }
                wsf_set_nil_element($user_arguments, $parent_node, $root_node, $prefix_i, $namespace_map);
            }
        }
    }
}
开发者ID:ztobs,项目名称:wsf,代码行数:67,代码来源:wsf_wsdl_serialization.php

示例10: parseXmlAttributes

 /**
  * Parse the input DOMNode attributes into an array.
  *
  * @param \DOMNode $node xml to parse
  *
  * @return array
  */
 private function parseXmlAttributes(\DOMNode $node)
 {
     if (!$node->hasAttributes()) {
         return array();
     }
     $data = array();
     foreach ($node->attributes as $attr) {
         if (ctype_digit($attr->nodeValue)) {
             $data['@' . $attr->nodeName] = (int) $attr->nodeValue;
         } else {
             $data['@' . $attr->nodeName] = $attr->nodeValue;
         }
     }
     return $data;
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:22,代码来源:XmlEncoder.php

示例11: parseNodeAttributes

 private function parseNodeAttributes(DOMNode &$node)
 {
     if ($node->hasAttributes()) {
         foreach ($node->attributes as $attr) {
             if (strpos($attr->value, '${') !== false) {
                 $expressions = array();
                 preg_match_all('/(\\$\\{)(.*)(\\})/imsxU', $attr->value, $expressions);
                 for ($i = 0; $i < count($expressions[0]); $i++) {
                     $toReplace = $expressions[0][$i];
                     $expression = $expressions[2][$i];
                     $expressionResult = ExpressionParser::evaluate($expression, $this->dataContext);
                     switch (strtolower($attr->name)) {
                         case 'repeat':
                             // Can only loop if the result of the expression was an array
                             if (!is_array($expressionResult)) {
                                 throw new ExpressionException("Can't repeat on a singular var");
                             }
                             // Make sure the repeat variable doesn't show up in the cloned nodes (otherwise it would infinit recurse on this->parseNode())
                             $node->removeAttribute('repeat');
                             // Is a named var requested?
                             $variableName = $node->getAttribute('var') ? trim($node->getAttribute('var')) : false;
                             // Store the current 'Cur', index and count state, we might be in a nested repeat loop
                             $previousCount = isset($this->dataContext['Context']['Count']) ? $this->dataContext['Context']['Count'] : null;
                             $previousIndex = isset($this->dataContext['Context']['Index']) ? $this->dataContext['Context']['Index'] : null;
                             $previousCur = $this->dataContext['Cur'];
                             // For information on the loop context, see http://opensocial-resources.googlecode.com/svn/spec/0.9/OpenSocial-Templating.xml#rfc.section.10.1
                             $this->dataContext['Context']['Count'] = count($expressionResult);
                             foreach ($expressionResult as $index => $entry) {
                                 if ($variableName) {
                                     // this is cheating a little since we're not putting it on the top level scope, the variable resolver will check 'Cur' first though so myVar.Something will still resolve correctly
                                     $this->dataContext['Cur'][$variableName] = $entry;
                                 }
                                 $this->dataContext['Cur'] = $entry;
                                 $this->dataContext['Context']['Index'] = $index;
                                 // Clone this node and it's children
                                 $newNode = $node->cloneNode(true);
                                 // Append the parsed & expanded node to the parent
                                 $newNode = $node->parentNode->insertBefore($newNode, $node);
                                 // And parse it (using the global + loop context)
                                 $this->parseNode($newNode, true);
                             }
                             // Restore our previous data context state
                             $this->dataContext['Cur'] = $previousCur;
                             if ($previousCount) {
                                 $this->dataContext['Context']['Count'] = $previousCount;
                             } else {
                                 unset($this->dataContext['Context']['Count']);
                             }
                             if ($previousIndex) {
                                 $this->dataContext['Context']['Index'] = $previousIndex;
                             } else {
                                 unset($this->dataContext['Context']['Index']);
                             }
                             return $node;
                             break;
                         case 'if':
                             if (!$expressionResult) {
                                 return $node;
                             } else {
                                 $node->removeAttribute('if');
                             }
                             break;
                             // These special cases that only apply for certain tag types
                         // These special cases that only apply for certain tag types
                         case 'selected':
                             if ($node->tagName == 'option') {
                                 if ($expressionResult) {
                                     $node->setAttribute('selected', 'selected');
                                 } else {
                                     $node->removeAttribute('selected');
                                 }
                             } else {
                                 throw new ExpressionException("Can only use selected on an option tag");
                             }
                             break;
                         case 'checked':
                             if ($node->tagName == 'input') {
                                 if ($expressionResult) {
                                     $node->setAttribute('checked', 'checked');
                                 } else {
                                     $node->removeAttribute('checked');
                                 }
                             } else {
                                 throw new ExpressionException("Can only use checked on an input tag");
                             }
                             break;
                         case 'disabled':
                             $disabledTags = array('input', 'button', 'select', 'textarea');
                             if (in_array($node->tagName, $disabledTags)) {
                                 if ($expressionResult) {
                                     $node->setAttribute('disabled', 'disabled');
                                 } else {
                                     $node->removeAttribute('disabled');
                                 }
                             } else {
                                 throw new ExpressionException("Can only use disabled on input, button, select and textarea tags");
                             }
                             break;
                         default:
                             // On non os-template spec attributes, do a simple str_replace with the evaluated value
//.........这里部分代码省略.........
开发者ID:ndkhoiits,项目名称:gatein-shindig,代码行数:101,代码来源:TemplateParser.php

示例12: processAttributes

 /**
  * Process element attributes
  *
  * @param \DOMNode $root
  * @return array
  */
 protected function processAttributes(\DOMNode $root)
 {
     $result = [];
     if ($root->hasAttributes()) {
         $attributes = $root->attributes;
         foreach ($attributes as $attribute) {
             $result[$attribute->name] = $attribute->value;
         }
         return $result;
     }
     return $result;
 }
开发者ID:artmouse,项目名称:Umc_Base,代码行数:18,代码来源:Converter.php

示例13: _as_array

	/**
	 * Recursive as_array for child nodes
	 * @param DOMNode $dom_node
	 * @return Array
	 */
	private function _as_array(DOMNode $dom_node)
	{
		// All other nodes shall be parsed normally : attributes then text value and child nodes, running through the XML tree
		$object_element = array();
		
		// Get the desired node name for this node
		$node_name = $this->meta()->key($dom_node->tagName);
			
		// Get attributes
		if ($dom_node->hasAttributes())
		{
	 		$object_element[$dom_node->nodeName]['xml_attributes'] = array();
			foreach($dom_node->attributes as $att_name => $dom_attribute)
			{
				// Get the desired name for this attribute
				$att_name = $this->meta()->key($att_name);
		
				$object_element[$node_name]['xml_attributes'][$att_name] = $dom_attribute->value;
			}
		}
	
		// Get children, run through XML tree
		if ($dom_node->hasChildNodes())
		{
			if (!$dom_node->firstChild->hasChildNodes())
			{	
				// Get text value
				$object_element[$node_name] = trim($dom_node->firstChild->nodeValue);
			}
	
			foreach($dom_node->childNodes as $dom_child)
			{
				if ($dom_child->nodeType === XML_ELEMENT_NODE)
				{
					$child = $this->_as_array($dom_child);
						
					foreach ($child as $key=>$val)
					{
						$object_element[$node_name][$key][]=$val;
					}
				}
			}
		}
		return $object_element;
	}
开发者ID:refo,项目名称:kohana,代码行数:50,代码来源:core.php

示例14: cleanupNode

 /**
  * Clean Processor call
  *
  * @param DOMNode $node DomNode to process
  *
  * @return boolean
  */
 private function cleanupNode(DOMNode $node)
 {
     if ($node->nodeType == XML_COMMENT_NODE) {
         return false;
     }
     // get ns from node
     $xmlns = $node->namespaceURI;
     if (is_null($xmlns)) {
         $xmlns = 'none';
     }
     // filter class for namespace?
     if (isset($this->filterList[$xmlns])) {
         $filterCore = $this->filterList[$xmlns];
         $filter = $filterCore->getInstanceForTagName($node->localName);
         if ($node->hasAttributes()) {
             $this->processAttributes($node, $filter);
         }
         if ($node->hasChildNodes()) {
             $this->processChildNodes($node, $filter);
         }
         return true;
     } else {
         // no filter class for this xmlns, remove node if possible
         if ($node->parentNode instanceof DOMNode) {
             $node->parentNode->removeChild($node);
             return true;
         } else {
             // cannot remove this node here, thus return false
             return false;
         }
     }
 }
开发者ID:khoaanh2212,项目名称:kata-tdd-1-khoa-anh,代码行数:39,代码来源:fDOMFilter.php

示例15: hasIdAttribute

 /**
  * Has ID attribute
  *
  * @param \DOMNode $node
  * @return bool
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function hasIdAttribute(\DOMNode $node)
 {
     if (!$node->hasAttributes()) {
         return false;
     }
     foreach ($node->attributes as $name => $attribute) {
         if (in_array($name, $this->idAttributes)) {
             return true;
         }
     }
     return false;
 }
开发者ID:vrann,项目名称:magento2-from-vendor,代码行数:19,代码来源:DomMerger.php


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