diff options
author | godzilla80@gmx.net <> | 2009-04-16 09:26:55 +0000 |
---|---|---|
committer | godzilla80@gmx.net <> | 2009-04-16 09:26:55 +0000 |
commit | 76c718e9afde72ba03c79bcfe39f63f7c8d2b9d0 (patch) | |
tree | b074babb55023b1f10308278f1c5d27c63179e35 /framework | |
parent | 16f3e16a4da781e56064402e0cf48c5a5bae1c78 (diff) |
Fixed Issue #112 - TXmlDocument add support for namespaces: for backward compatibility only if SimpleXml installed
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Xml/TXmlDocument.php | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/framework/Xml/TXmlDocument.php b/framework/Xml/TXmlDocument.php index d7ddf187..7d506852 100644 --- a/framework/Xml/TXmlDocument.php +++ b/framework/Xml/TXmlDocument.php @@ -396,8 +396,27 @@ class TXmlDocument extends TXmlElement $attributes=$this->getAttributes(); $elements->clear(); $attributes->clear(); + + static $bSimpleXml; + if($bSimpleXml === null) + $bSimpleXml = (boolean)function_exists('simplexml_load_string'); + + if($bSimpleXml) + { + $simpleDoc = simplexml_load_string($string); + $docNamespaces = $simpleDoc->getDocNamespaces(false); + $simpleDoc = null; + foreach($docNamespaces as $prefix => $uri) + { + if($prefix === '') + $attributes->add('xmlns', $uri); + else + $attributes->add('xmlns:'.$prefix, $uri); + } + } + foreach($element->attributes as $name=>$attr) - $attributes->add($name,$attr->value); + $attributes->add(($attr->prefix === '' ? '' : $attr->prefix . ':') .$name,$attr->value); foreach($element->childNodes as $child) { if($child instanceof DOMElement) @@ -464,7 +483,8 @@ class TXmlDocument extends TXmlElement $element=new TXmlElement($node->tagName); $element->setValue($node->nodeValue); foreach($node->attributes as $name=>$attr) - $element->getAttributes()->add($name,$attr->value); + $element->getAttributes()->add(($attr->prefix === '' ? '' : $attr->prefix . ':') . $name,$attr->value); + foreach($node->childNodes as $child) { if($child instanceof DOMElement) |