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 --- HISTORY | 1 + framework/Xml/TXmlDocument.php | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index a8c2d302..5763e5a4 100644 --- a/HISTORY +++ b/HISTORY @@ -19,6 +19,7 @@ CHG: Issue#7 - Clients Scripts are not combined anymore in Debug application mod ENH: Issue#115 - Registry for Prado generated clientside counterparts of serverside controls (Yves Berkholz) ENH: Issue#135 - Add AutoPostBack property to TActiveFileUpload (Bradley) ENH: Issue#117 - TValidationSummary: new display mode "HeaderOnly" that only render value of HeaderText property (Yves) +BUG/ENH: Issue#112 - TXmlDocument add support for namespaces: for backward compatibility only if SimpleXml installed (Yves) ENH: Added caching of message files to TException (Michael) ENH: Updated to scriptaculous 1.8.2 & Prototype 1.6.0.3 ENH: replace is_null() function calls with native language constuct (Yves) 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