當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DOMNode::setAttributeNode方法代碼示例

本文整理匯總了PHP中DOMNode::setAttributeNode方法的典型用法代碼示例。如果您正苦於以下問題:PHP DOMNode::setAttributeNode方法的具體用法?PHP DOMNode::setAttributeNode怎麽用?PHP DOMNode::setAttributeNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DOMNode的用法示例。


在下文中一共展示了DOMNode::setAttributeNode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get_node_id

 /**
  * Find a node ID or generate and set one
  * 
  * @param DOMNode $node
  * @return string
  */
 private function get_node_id(DOMNode $node)
 {
     if ($node->hasAttributes() && $node->attributes->getNamedItem('id')) {
         $id = $node->attributes->getNamedItem('id')->nodeValue;
     } else {
         $id = "pmf_gen-" . count($this->parsedTemplates);
         $node->setAttributeNode(new DOMAttr('id', $id));
     }
     return $id;
 }
開發者ID:jr-ewing,項目名稱:phpMyFAQ,代碼行數:16,代碼來源:Template.php

示例2: encode

 public function encode($variable, \DOMNode $node, Type $type)
 {
     if ($type instanceof AbstractComplexType) {
         foreach ($type->getAttributes() as $attribute) {
             $val = self::getValueFrom($variable, $attribute->getName());
             if ($val !== null) {
                 if ($attribute->getQualification() == "qualified") {
                     $attributeNode = $node->ownerDocument->ocreateAttributeNS($attribute->getNs(), $node->getPrefixFor($attribute->getNs()) . ":" . $attribute->getName());
                     $node->setAttributeNodeNs($attributeNode);
                 } else {
                     $attributeNode = $node->ownerDocument->createAttribute($attribute->getName());
                     $node->setAttributeNode($attributeNode);
                 }
                 $this->convertSimplePhpXml($val, $attributeNode, $attribute->getType());
             } elseif ($attribute->isRequred()) {
                 throw new \Exception("Type {$type}, attributo " . $attribute . " non deve essere vuoto");
             }
         }
         if ($type->getBase()) {
             $this->encode($variable, $node, $type->getBase());
         }
         if ($type instanceof ComplexType) {
             foreach ($type->getElements() as $element) {
                 $elementQualified = $element->getQualification() == "qualified";
                 $newType = $element->getType();
                 if ($element->getMax() > 1 && ($val = self::tryGetValueFrom($variable, $element->getName())) && (is_array($val) || $val instanceof \Traversable)) {
                     foreach ($val as $nval) {
                         if ($elementQualified) {
                             $newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
                         } else {
                             $newNode = $node->addChild($element->getName());
                         }
                         $this->encode($nval, $newNode, $newType);
                     }
                 } elseif ($element->getMax() > 1 && (is_array($variable) || $variable instanceof \Traversable)) {
                     foreach ($variable as $nval) {
                         if ($elementQualified) {
                             $newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
                         } else {
                             $newNode = $node->addChild($element->getName());
                         }
                         $this->encode($nval, $newNode, $newType);
                     }
                 } else {
                     $val = self::getValueFrom($variable, $element->getName());
                     if ($val !== null || $element->isNillable()) {
                         if ($elementQualified) {
                             $newNode = $node->addPrefixedChild($element->getNs(), $element->getName());
                         } else {
                             $newNode = $node->addChild($element->getName());
                         }
                         if ($val === null) {
                             $newNode->setAttributeNS(self::NS_XSI, $newNode->getPrefixFor(self::NS_XSI) . ":nil", "true");
                         } else {
                             $this->encode($val, $newNode, $newType);
                         }
                     } elseif ($element->getMin() > 0) {
                         throw new \Exception($element . " non deve essere vuoto");
                     }
                 }
             }
         }
     }
     if ($type instanceof SimpleType) {
         $this->convertSimplePhpXml($variable, $node, $type);
     }
 }
開發者ID:goetas,項目名稱:xml-xsd-encoder,代碼行數:67,代碼來源:LitteralEncoder.php


注:本文中的DOMNode::setAttributeNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。