|
@@ -47,6 +47,14 @@ class JsXml__ {
|
|
|
public var _attributes : Hash<String>;
|
|
|
public var _children : Array<Xml>;
|
|
|
|
|
|
+ private static function unescape( s : String ) : String {
|
|
|
+ return s.split("<").join("<").split(">").join(">").split(""").join("\"").split("&").join("&");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static function escape( s : String ) : String {
|
|
|
+ return s.split("&").join("&").split("\"").join(""").split("<").join("<").split(">").join(">");
|
|
|
+ }
|
|
|
+
|
|
|
public static function parse( str : String ) : Xml {
|
|
|
var rules = [enode,epcdata,ecdata,edoctype,eend,ecomment,eprolog];
|
|
|
var nrules = rules.length;
|
|
@@ -64,7 +72,7 @@ class JsXml__ {
|
|
|
current.addChild(x);
|
|
|
str = r.matchedRight();
|
|
|
while( eattribute.match(str) ) {
|
|
|
- x.set(eattribute.matched(1),eattribute.matched(2));
|
|
|
+ x.set(eattribute.matched(1),unescape(eattribute.matched(2)));
|
|
|
str = eattribute.matchedRight();
|
|
|
}
|
|
|
if( !eclose.match(str) ) {
|
|
@@ -77,7 +85,7 @@ class JsXml__ {
|
|
|
}
|
|
|
str = eclose.matchedRight();
|
|
|
case 1: // PCData
|
|
|
- var x = Xml.createPCData(r.matched(0));
|
|
|
+ var x = Xml.createPCData(unescape(r.matched(0)));
|
|
|
current.addChild(x);
|
|
|
str = r.matchedRight();
|
|
|
case 2: // CData
|
|
@@ -367,7 +375,11 @@ class JsXml__ {
|
|
|
}
|
|
|
|
|
|
public function toString() {
|
|
|
- if( nodeType == Xml.PCData || nodeType == Xml.CData || nodeType == Xml.Comment || nodeType == Xml.DocType || nodeType == Xml.Prolog )
|
|
|
+ if( nodeType == Xml.PCData )
|
|
|
+ return escape(_nodeValue);
|
|
|
+ if( nodeType == Xml.CData )
|
|
|
+ return "<![CDATA["+_nodeValue+"]]>";
|
|
|
+ if( nodeType == Xml.Comment || nodeType == Xml.DocType || nodeType == Xml.Prolog )
|
|
|
return _nodeValue;
|
|
|
|
|
|
var s = new StringBuf();
|
|
@@ -379,7 +391,7 @@ class JsXml__ {
|
|
|
s.add(" ");
|
|
|
s.add(k);
|
|
|
s.add("=\"");
|
|
|
- s.add(_attributes.get(k));
|
|
|
+ s.add(escape(_attributes.get(k)));
|
|
|
s.add("\"");
|
|
|
}
|
|
|
if( _children.length == 0 ) {
|