diff options
Diffstat (limited to 'framework/Xml/TXmlDocument.php')
-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) |