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


PHP DOMNode::removeAttributeNode方法代码示例

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


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

示例1: process

 /**
  * The main compilation function - called recursivley to process
  *
  * @param DOMNode $node
  * @return void
  */
 public function process(DOMNode $node)
 {
     $end = null;
     $processChildren = true;
     switch ($node->nodeType) {
         case XML_DOCUMENT_NODE:
             break;
         case XML_COMMENT_NODE:
             $body = trim($node->data);
             if (strpos($body, "\n") === false) {
                 $this->write("<?php\n// {$body}\n?>");
             } else {
                 $lines = explode("\n", $body);
                 for ($i = 0; $i < count($lines); $i++) {
                     if ($i == 0) {
                         $buf = '/* ' . $lines[$i] . "\n";
                     } else {
                         $buf .= ' * ' . $lines[$i] . "\n";
                     }
                 }
                 $this->write("<?php\n{$buf} */\n?>");
             }
             break;
         case XML_TEXT_NODE:
         case XML_CDATA_SECTION_NODE:
             $text = PHPSTLExpressionParser::expand($node->nodeValue);
             if ($this->whitespace == self::WHITESPACE_TRIM) {
                 $text = trim($text);
                 $text = preg_replace('/\\s+/s', ' ', $text);
             }
             $this->write($text);
             break;
         case XML_PI_NODE:
             switch ($node->target) {
                 case 'php':
                     $data = trim($node->data);
                     if (!preg_match('/[:;{}]$/', $data)) {
                         $data .= ';';
                     }
                     $this->write("<?php {$data} ?>");
                     break;
                 case 'whitespace':
                     switch (trim($node->data)) {
                         case 'preserve':
                             $this->whitespace = self::WHITESPACE_PRESERVE;
                             break;
                         case 'collapse':
                             $this->whitespace = self::WHITESPACE_COLLAPSE;
                             break;
                         case 'trim':
                             $this->whitespace = self::WHITESPACE_TRIM;
                             break;
                         default:
                             throw new PHPSTLCompilerException($this, "invalid <?whitespace {$node->data} ?>");
                             break;
                     }
                     break;
                 default:
                     throw new PHPSTLCompilerException($this, "unknown processing instruction {$node->target}");
             }
             break;
         case XML_ELEMENT_NODE:
             $attrs = array();
             foreach ($node->attributes as $name => $attr) {
                 if (isset($attr->namespaceURI)) {
                     $handler = $this->handleNamespace($attr->namespaceURI);
                     $val = $handler->handle($attr);
                     $node->removeAttributeNode($attr);
                     if (isset($val)) {
                         $attrs[$attr->name] = $val;
                     }
                 } else {
                     $attrs[$attr->name] = $attr->value;
                 }
             }
             if ($node === $this->dom->documentElement) {
                 foreach ($attrs as $name => $value) {
                     $this->meta[$name] = $value;
                 }
             } elseif (isset($node->namespaceURI)) {
                 $processChildren = false;
                 $handler = $this->handleNamespace($node->namespaceURI);
                 $handler->handle($node);
             } else {
                 $start = "<{$node->nodeName}";
                 foreach ($attrs as $name => $value) {
                     $start .= " {$name}=\"{$value}\"";
                 }
                 if ($node->hasChildNodes() && ($this->meta['type'] != 'text/html' || !in_array($node->nodeName, self::$HTMLSingleTags))) {
                     $start .= '>';
                     $end = "</{$node->nodeName}>";
                 } else {
                     $processChildren = false;
                     $start .= ' />';
//.........这里部分代码省略.........
开发者ID:bprudent,项目名称:php-stl,代码行数:101,代码来源:PHPSTLCompiler.php

示例2: removeNotConfiguredAttributes

 private function removeNotConfiguredAttributes(\DOMNode $node)
 {
     for ($i = 0; $i < $node->attributes->length;) {
         $attribute = $node->attributes->item($i);
         if ($this->hasNoAttribute($attribute->nodeName)) {
             $node->removeAttributeNode($attribute);
             continue;
         }
         $i++;
     }
 }
开发者ID:funddy,项目名称:yodo,代码行数:11,代码来源:Rule.php

示例3: _sanitizeAttributes

 /**
  * Sanitise the attributes of the given nodes according to the internal
  * whitelist and sanitisation checks. A user whitelist may optionally be passed
  * to replace the internal whitelist.
  *
  * @param \DOMNode $node
  * @param array $userWhitelist
  */
 protected function _sanitizeAttributes(\DOMNode $node, array $userWhitelist = null)
 {
     if ($userWhitelist === null) {
         $allowedAttributes = array_merge(Whitelist::$acceptableAttributes, Whitelist::$mathmlAttributes, Whitelist::$svgAttributes);
     } else {
         $allowedAttributes = $userWhitelist;
     }
     foreach ($node->attributes as $attribute) {
         if (!empty($attribute->prefix)) {
             $name = $attribute->prefix . ':' . $attribute->name;
         } else {
             $name = $attribute->name;
         }
         if (!in_array($name, $allowedAttributes)) {
             $node->removeAttributeNode($attribute);
             return;
         }
         if (in_array($name, Whitelist::$attributesWithUriValue)) {
             $unescaped = htmlspecialchars_decode($attribute->value);
             $unescaped = strtolower(preg_replace('/[`\\000-\\040\\177-\\240\\s]+/', '', $unescaped));
             $parts = explode(':', $unescaped);
             $protocol = $parts[0];
             if (preg_match('/^[a-z0-9][-+.a-z0-9]*:/', $unescaped) && !in_array($protocol, Whitelist::$acceptableProtocols)) {
                 $node->removeAttributeNode($attribute);
                 return;
             }
         }
         if (in_array($name, Whitelist::$svgAttributeValueAllowsRef)) {
             $node->setAttribute($name, preg_replace('/url\\s*\\(\\s*[^#\\s][^)]+?\\)/m', ' ', $node->getAttribute($name)));
         }
         if (in_array($node->tagName, Whitelist::$svgAllowLocalHref) && $name == 'xlink:href' && preg_match('/^\\s*[^#\\s].*/m', $node->getAttribute($name))) {
             $node->removeAttributeNode($attribute);
             return;
         }
     }
     if ($node->hasAttribute('style')) {
         $node->setAttribute('style', $this->_sanitizeCSS($node->getAttribute('style')));
     }
 }
开发者ID:padraic,项目名称:wibble,代码行数:47,代码来源:AbstractFilter.php

示例4: treeNodeUpdate

 /**
  * updates the TREE node
  *
  * @access private
  * @param  domnode $node
  * @return void
  */
 private function treeNodeUpdate(DOMNode &$node)
 {
     // List of new attributes
     $newAttributes = array('selectClass' => 'edit_class', 'selectInstance' => 'edit_item', 'moveInstance' => 'move', 'delete' => 'delete');
     $len = $node->attributes->length;
     if ($len) {
         for ($i = $len - 1; $i >= 0; --$i) {
             $attr = $node->attributes->item($i);
             $name = $attr->nodeName;
             switch ($name) {
                 case 'name':
                 case 'className':
                 case 'dataUrl':
                     // these are still valid attributes
                     break;
                 default:
                     if (isset($newAttributes[$name])) {
                         unset($newAttributes[$name]);
                     } else {
                         $this->_createActionFromTreeAttrib($name, $attr->nodeValue);
                         $node->removeAttributeNode($attr);
                     }
             }
         }
     }
     // Add the new default attributes
     foreach ($newAttributes as $name => $value) {
         $node->setAttribute($name, $value);
     }
 }
开发者ID:oat-sa,项目名称:extension-tao-update,代码行数:37,代码来源:class.MigrateStructureXml.php

示例5: cleanAttributes

 /**
  * Clean DOM node attribute against whitelist
  * 
  * @param $node object DOM Node
  */
 protected function cleanAttributes(\DOMNode $node)
 {
     foreach (\iterator_to_array($node->attributes) as $at) {
         $n = $at->nodeName;
         $v = $at->nodeValue;
         # Default action is to remove attribute
         # It will only get added if it's safe
         $node->removeAttributeNode($at);
         if (in_array($n, $this->white[$node->nodeName])) {
             switch ($n) {
                 case 'longdesc':
                 case 'url':
                 case 'src':
                 case 'href':
                     $v = \Blog\Messaging\Uri::cleanUrl($v);
                     break;
                 default:
                     $v = $this->entities($v);
             }
             $node->setAttribute($n, $v);
         }
     }
 }
开发者ID:eksith,项目名称:Blog,代码行数:28,代码来源:HtmlFilter.php


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