Browse Source

some xml fixes for flash8/php

Nicolas Cannasse 15 years ago
parent
commit
2e101823bb
2 changed files with 16 additions and 14 deletions
  1. 9 5
      std/php/PhpXml__.hx
  2. 7 9
      tests/unit/TestXML.hx

+ 9 - 5
std/php/PhpXml__.hx

@@ -352,10 +352,6 @@ class PhpXml__ {
 	public function toString() {
 		if( nodeType == Xml.PCData )
 			return _nodeValue;
-		if( nodeType == Xml.CData )
-			return "<![CDATA["+_nodeValue+"]]>";
-		if( nodeType == Xml.Comment || nodeType == Xml.DocType || nodeType == Xml.Prolog )
-			return _nodeValue;
 
 		var s = "";
 
@@ -374,7 +370,15 @@ class PhpXml__ {
 				return s;
 			}
 			s += ">";
-		}
+		} else if( nodeType == Xml.CData )
+			return "<![CDATA["+_nodeValue+"]]>";
+		else if( nodeType == Xml.Comment )
+			return "<!--"+_nodeValue+"-->";
+		else if( nodeType == Xml.DocType )
+			return "<!DOCTYPE "+_nodeValue+">";
+		else if( nodeType == Xml.Prolog )
+			return "<?"+_nodeValue+"?>";
+		
 
 		for( x in iterator() )
 			s += x.toString();

+ 7 - 9
tests/unit/TestXML.hx

@@ -50,14 +50,12 @@ class TestXML extends Test {
 		#else
 		eq( Xml.parse("<a><b><c/> <d/> \n <e/><![CDATA[<x>]]></b></a>").toString(), "<a><b><c/> <d/> \n <e/><![CDATA[<x>]]></b></a>" );
 		#end
-		#if flash8
+		#if (flash8 || php)
 		eq( Xml.parse('"').toString(), '&quot;' ); // flash8 has bad habits of escaping entities
 		#else
 		eq( Xml.parse('"').toString(), '"' );
 		#end
-		#if flash8
-		eq( Xml.parse('&quot; &lt; &gt;').toString(), '&amp;quot; &amp;lt; &amp;gt;' ); // flash8 has bad habits of escaping entities
-		#elseif flash9
+		#if flash9
 		eq( Xml.parse('&quot; &lt; &gt;').toString(), '" &lt; &gt;' ); // some entities are resolved but not escaped on printing
 		#else
 		eq( Xml.parse('&quot; &lt; &gt;').toString(), '&quot; &lt; &gt;' );
@@ -68,7 +66,7 @@ class TestXML extends Test {
 		// this is showing some quirks with flash XML parser
 
 		var header = '<?some header?>';
-		var doctype = '<!DOCTYPE Doctype infos>';
+		var doctype = '<!DOCTYPE root SYSTEM "">';
 		var comment = '<!--Comment-->';
 		var xml = '<html><body><![CDATA[<a href="CDATA"/>&lt;]]></body></html>';
 
@@ -81,11 +79,11 @@ class TestXML extends Test {
 
 		#if flash8
 		// cdata is parsed as pcdata in flash8
-		xml = '<html><body>&lt;a href=&quot;CDATA&quot;/&gt;&lt;</body></html>';
+		xml = '<html><body>&lt;a href=&quot;CDATA&quot;/&gt;&amp;lt;</body></html>';
 		#end
 
-		#if flash
-		// doctype is well parsed but is not present in the parsed Xml (both f8 and f9)
+		#if (flash || php)
+		// doctype is well parsed but is not present in the parsed Xml (php, f8 and f9)
 		doctype = '';
 		#end
 
@@ -113,7 +111,7 @@ class TestXML extends Test {
 		var a = el.next();
 		eq( a.firstChild().nodeValue, " ");
 		var b = el.next();
-		#if flash
+		#if (flash || php)
 		eq( b.firstChild(), null);
 		eq( x.toString().split("\n").join("\\n"), '<a> </a><b/> \\n <c/>' );
 		#else