RSI helpers  0.1
RSI helpers
Xml.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Rsi;
4 
5 /**
6  * XML helper functions.
7  */
8 class Xml{
9 
10  /**
11  * Check wether a name is a valid XML tag name.
12  * @param string $name Tag name.
13  * @return bool True if valid.
14  */
15  public static function validTag($name){
16  return !preg_match('/(^[\\.\\-\\d]|^xml|[' . preg_quote('!"#$%&\'()*+,/;<=>?@[\\]^`{|}~','/') . '\\s])/i',$name);
17  }
18  /**
19  * Covert a DOM node to a (simple) XML node.
20  * @param \DOMNode $node
21  * @param string $class_name Class name for the XML object (descendant of SimpleXMLElement).
22  * @return SimpleXMLElement
23  */
24  public static function fromDom($node,$class_name = 'SimpleXMLElement'){
25  return simplexml_import_dom((new \DomDocument())->importNode($node,true),$class_name);
26  }
27 
28 }
static fromDom($node, $class_name='SimpleXMLElement')
Covert a DOM node to a (simple) XML node.
Definition: Xml.php:24
static validTag($name)
Check wether a name is a valid XML tag name.
Definition: Xml.php:15
XML helper functions.
Definition: Xml.php:8
Definition: Color.php:3