From 76c718e9afde72ba03c79bcfe39f63f7c8d2b9d0 Mon Sep 17 00:00:00 2001 From: "godzilla80@gmx.net" <> Date: Thu, 16 Apr 2009 09:26:55 +0000 Subject: Fixed Issue #112 - TXmlDocument add support for namespaces: for backward compatibility only if SimpleXml installed --- framework/Xml/TXmlDocument.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'framework/Xml/TXmlDocument.php') 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) -- cgit v1.2.3