Browse Source

Merge pull request #3752 from HaxeFoundation/xml_rewrite

Xml rewrite
Simon Krajewski 10 years ago
parent
commit
7cd974dc36

+ 0 - 11
genas3.ml

@@ -54,14 +54,6 @@ let is_var_field f =
 	| _ ->
 	| _ ->
 		false
 		false
 
 
-let is_special_compare e1 e2 =
-	match e1.eexpr, e2.eexpr with
-	| TConst TNull, _  | _ , TConst TNull -> None
-	| _ ->
-	match follow e1.etype, follow e2.etype with
-	| TInst ({ cl_path = [],"Xml" } as c,_) , _ | _ , TInst ({ cl_path = [],"Xml" } as c,_) -> Some c
-	| _ -> None
-
 let protect name =
 let protect name =
 	match name with
 	match name with
 	| "Error" | "Namespace" -> "_" ^ name
 	| "Error" | "Namespace" -> "_" ^ name
@@ -586,9 +578,6 @@ and gen_expr ctx e =
 		spr ctx "[";
 		spr ctx "[";
 		gen_value ctx e2;
 		gen_value ctx e2;
 		spr ctx "]";
 		spr ctx "]";
-	| TBinop (Ast.OpEq,e1,e2) when (match is_special_compare e1 e2 with Some c -> true | None -> false) ->
-		let c = match is_special_compare e1 e2 with Some c -> c | None -> assert false in
-		gen_expr ctx (mk (TCall (mk (TField (mk (TTypeExpr (TClassDecl c)) t_dynamic e.epos,FDynamic "compare")) t_dynamic e.epos,[e1;e2])) ctx.inf.com.basic.tbool e.epos);
 	(* what is this used for? *)
 	(* what is this used for? *)
 (* 	| TBinop (op,{ eexpr = TField (e1,s) },e2) ->
 (* 	| TBinop (op,{ eexpr = TField (e1,s) },e2) ->
 		gen_value_op ctx e1;
 		gen_value_op ctx e1;

+ 3 - 16
genswf9.ml

@@ -120,14 +120,6 @@ let tid (x : 'a index) : int = Obj.magic x
 let ethis = mk (TConst TThis) (mk_mono()) null_pos
 let ethis = mk (TConst TThis) (mk_mono()) null_pos
 let dynamic_prop = HMMultiNameLate [HNPublic (Some "")]
 let dynamic_prop = HMMultiNameLate [HNPublic (Some "")]
 
 
-let is_special_compare e1 e2 =
-	match e1.eexpr, e2.eexpr with
-	| TConst TNull, _  | _ , TConst TNull -> None
-	| _ ->
-	match follow e1.etype, follow e2.etype with
-	| TInst ({ cl_path = [],"Xml" } as c,_) , _ | _ , TInst ({ cl_path = [],"Xml" } as c,_) -> Some c
-	| _ -> None
-
 let write ctx op =
 let write ctx op =
 	DynArray.add ctx.code op;
 	DynArray.add ctx.code op;
 	ctx.infos.ipos <- ctx.infos.ipos + 1;
 	ctx.infos.ipos <- ctx.infos.ipos + 1;
@@ -1614,12 +1606,7 @@ and gen_binop ctx retval op e1 e2 t p =
 		write ctx (HOp o)
 		write ctx (HOp o)
 	in
 	in
 	let gen_eq() =
 	let gen_eq() =
-		match is_special_compare e1 e2 with
-		| None ->
-			gen_op A3OEq
-		| Some c ->
-			let f = FStatic (c,try PMap.find "compare" c.cl_statics with Not_found -> assert false) in
-			gen_expr ctx true (mk (TCall (mk (TField (mk (TTypeExpr (TClassDecl c)) t_dynamic p,f)) t_dynamic p,[e1;e2])) ctx.com.basic.tbool p);
+		gen_op A3OEq
 	in
 	in
 	match op with
 	match op with
 	| OpAssign ->
 	| OpAssign ->
@@ -1721,8 +1708,8 @@ and jump_expr_gen ctx e jif jfun =
 			jfun (if jif then t else f)
 			jfun (if jif then t else f)
 		in
 		in
 		(match op with
 		(match op with
-		| OpEq when is_special_compare e1 e2 = None -> j J3Eq J3Neq
-		| OpNotEq when is_special_compare e1 e2 = None -> j J3Neq J3Eq
+		| OpEq -> j J3Eq J3Neq
+		| OpNotEq -> j J3Neq J3Eq
 		| OpGt -> j J3Gt J3NotGt
 		| OpGt -> j J3Gt J3NotGt
 		| OpGte -> j J3Gte J3NotGte
 		| OpGte -> j J3Gte J3NotGte
 		| OpLt -> j J3Lt J3NotLt
 		| OpLt -> j J3Lt J3NotLt

+ 6 - 4
genxml.ml

@@ -110,8 +110,7 @@ let rec gen_type ?(values=None) t =
 						let e = PMap.find n values in
 						let e = PMap.find n values in
 						has_value := true;
 						has_value := true;
 						let s = Ast.s_expr e in
 						let s = Ast.s_expr e in
-						(* the XML parser has issues otherwise *)
-						String.concat "'" (ExtString.String.nsplit s "\"")
+						s
 					with Not_found ->
 					with Not_found ->
 						""
 						""
 				) args in
 				) args in
@@ -145,7 +144,7 @@ and gen_field att f =
 		| Var v ->
 		| Var v ->
 			let att = try
 			let att = try
 				begin match Meta.get Meta.Value f.cf_meta with
 				begin match Meta.get Meta.Value f.cf_meta with
-					| (_,[e],_) -> ("expr",String.concat "'" (ExtString.String.nsplit (Ast.s_expr e) "\"")) :: att
+					| (_,[e],_) -> ("expr",Ast.s_expr e) :: att
 					| _ -> att
 					| _ -> att
 				end
 				end
 			with Not_found ->
 			with Not_found ->
@@ -262,8 +261,11 @@ let rec gen_type_decl com pos t =
 		let this = [node "this" [] [gen_type a.a_this]] in
 		let this = [node "this" [] [gen_type a.a_this]] in
 		node "abstract" (gen_type_params pos a.a_private (tpath t) a.a_params a.a_pos m) (sub @ this @ super @ doc @ meta @ impl)
 		node "abstract" (gen_type_params pos a.a_private (tpath t) a.a_params a.a_pos m) (sub @ this @ super @ doc @ meta @ impl)
 
 
+let escape_entities s =
+	Xml.to_string (Xml.PCData s)
+
 let att_str att =
 let att_str att =
-	String.concat "" (List.map (fun (a,v) -> Printf.sprintf " %s=\"%s\"" a v) att)
+	String.concat "" (List.map (fun (a,v) -> Printf.sprintf " %s=\"%s\"" a (escape_entities v)) att)
 
 
 let rec write_xml ch tabs x =
 let rec write_xml ch tabs x =
 	match x with
 	match x with

+ 182 - 85
std/Xml.hx

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (C)2005-2012 Haxe Foundation
+ * Copyright (C)2005-2015 Haxe Foundation
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * copy of this software and associated documentation files (the "Software"),
@@ -19,201 +19,298 @@
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
-/**
-	An abstract type representing the type of the Xml
-	Node. You can compare it to `Xml` statics and can
-	use `Std.string` to get a string reprensation
-	of the type.
-**/
 
 
-
-
-enum XmlType {
+@:enum abstract XmlType(Int) {
+	var Element = 0;
+	var PCData = 1;
+	var CData = 2;
+	var Comment = 3;
+	var DocType = 4;
+	var ProcessingInstruction = 5;
+	var Document = 6;
 }
 }
 
 
-/**
-	The standard Xml class and parsing.
-	More API to manipulate XML are available in the [haxe.xml] package.
-**/
+class Xml {
 
 
-extern class Xml {
+	static public var Element(default,null) = XmlType.Element;
+	static public var PCData(default,null) = XmlType.PCData;
+	static public var CData(default,null) = XmlType.CData;
+	static public var Comment(default,null) = XmlType.Comment;
+	static public var DocType(default,null) = XmlType.DocType;
+	static public var ProcessingInstruction(default,null) = XmlType.ProcessingInstruction;
+	static public var Document(default,null) = XmlType.Document;
 
 
-	/**
-		A type of Xml node.
-	**/
-	static var Element(default,null) : XmlType;
+	static public function parse( str : String ) : Xml {
+		return haxe.xml.Parser.parse(str);
+	}
 
 
 	/**
 	/**
-		A type of Xml node.
+		Returns the type of the Xml Node. This should be used before
+		accessing other functions since some might raise an exception
+		if the node type is not correct.
 	**/
 	**/
-	static var PCData(default,null) : XmlType;
+	public var nodeType(default, null) : XmlType;
 
 
 	/**
 	/**
-		A type of Xml node.
+		Returns the node name of an Element.
 	**/
 	**/
-	static var CData(default,null) : XmlType;
+	@:isVar public var nodeName(get, set) : String;
 
 
 	/**
 	/**
-		A type of Xml node.
+		Returns the node value. Only works if the Xml node is not an Element or a Document.
 	**/
 	**/
-	static var Comment(default,null) : XmlType;
+	@:isVar public var nodeValue(get, set) : String;
 
 
 	/**
 	/**
-		A type of Xml node.
+		Returns the parent object in the Xml hierarchy.
+		The parent can be [null], an Element or a Document.
 	**/
 	**/
-	static var DocType(default,null) : XmlType;
+	public var parent(default, null) : Xml;
 
 
-	/**
-		A type of Xml node.
-	**/
-	static var ProcessingInstruction(default,null) : XmlType;
+	var children:Array<Xml>;
+	var attributeMap:Map<String, String>;
 
 
-	/**
-		A type of Xml node.
-	**/
-	static var Document(default,null) : XmlType;
+	inline function get_nodeName() {
+		if (nodeType != Element) {
+			throw 'Bad node type, expected Element but found $nodeType';
+		}
+		return nodeName;
+	}
 
 
-	/**
-		Parse a String into an Xml object.
-	**/
-	static function parse( str : String ) : Xml;
+	inline function set_nodeName(v) {
+		if (nodeType != Element) {
+			throw 'Bad node type, expected Element but found $nodeType';
+		}
+		return this.nodeName = v;
+	}
 
 
-	/**
-		Creates a node of the given type.
-	**/
-	static function createElement( name : String ) : Xml;
+	inline function get_nodeValue() {
+		if (nodeType == Document || nodeType == Element) {
+			throw 'Bad node type, unexpected $nodeType';
+		}
+		return nodeValue;
+	}
 
 
-	/**
-		Creates a node of the given type.
-	**/
-	static function createPCData( data : String ) : Xml;
+	inline function set_nodeValue(v) {
+		if (nodeType == Document || nodeType == Element) {
+			throw 'Bad node type, unexpected $nodeType';
+		}
+		return this.nodeValue = v;
+	}
 
 
 	/**
 	/**
 		Creates a node of the given type.
 		Creates a node of the given type.
 	**/
 	**/
-	static function createCData( data : String ) : Xml;
+	static public function createElement( name : String ) : Xml {
+		var xml = new Xml(Element);
+		xml.nodeName = name;
+		return xml;
+	}
 
 
 	/**
 	/**
 		Creates a node of the given type.
 		Creates a node of the given type.
 	**/
 	**/
-	static function createComment( data : String ) : Xml;
+	static public function createPCData( data : String ) : Xml {
+		var xml = new Xml(PCData);
+		xml.nodeValue = data;
+		return xml;
+	}
 
 
 	/**
 	/**
 		Creates a node of the given type.
 		Creates a node of the given type.
 	**/
 	**/
-	static function createDocType( data : String ) : Xml;
+	static public function createCData( data : String ) : Xml {
+		var xml = new Xml(CData);
+		xml.nodeValue = data;
+		return xml;
+	}
 
 
 	/**
 	/**
 		Creates a node of the given type.
 		Creates a node of the given type.
 	**/
 	**/
-	static function createProcessingInstruction( data : String ) : Xml;
+	static public function createComment( data : String ) : Xml {
+		var xml = new Xml(Comment);
+		xml.nodeValue = data;
+		return xml;
+	}
 
 
 	/**
 	/**
 		Creates a node of the given type.
 		Creates a node of the given type.
 	**/
 	**/
-	static function createDocument() : Xml;
-
-	/**
-		Returns the type of the Xml Node. This should be used before
-		accessing other functions since some might raise an exception
-		if the node type is not correct.
-	**/
-	var nodeType(default,null) : XmlType;
+	static public function createDocType( data : String ) : Xml {
+		var xml = new Xml(DocType);
+		xml.nodeValue = data;
+		return xml;
+	}
 
 
 	/**
 	/**
-		Returns the node name of an Element.
+		Creates a node of the given type.
 	**/
 	**/
-	var nodeName(get,set) : String;
+	static public function createProcessingInstruction( data : String ) : Xml {
+		var xml = new Xml(ProcessingInstruction);
+		xml.nodeValue = data;
+		return xml;
+	}
 
 
 	/**
 	/**
-		Returns the node value. Only works if the Xml node is not an Element or a Document.
+		Creates a node of the given type.
 	**/
 	**/
-	var nodeValue(get,set) : String;
+	static public function createDocument() : Xml {
+		return new Xml(Document);
+	}
 
 
 	/**
 	/**
 		Get the given attribute of an Element node. Returns [null] if not found.
 		Get the given attribute of an Element node. Returns [null] if not found.
 		Attributes are case-sensitive.
 		Attributes are case-sensitive.
 	**/
 	**/
-	function get( att : String ) : String; // check case insensitivy
+	public function get( att : String ) : String {
+		if (nodeType != Element) {
+			throw 'Bad node type, expected Element but found $nodeType';
+		}
+		return attributeMap[att];
+	}
 
 
 	/**
 	/**
 		Set the given attribute value for an Element node.
 		Set the given attribute value for an Element node.
 		Attributes are case-sensitive.
 		Attributes are case-sensitive.
 	**/
 	**/
-	function set( att : String, value : String ) : Void;
+	public function set( att : String, value : String ) : Void {
+		if (nodeType != Element) {
+			throw 'Bad node type, expected Element but found $nodeType';
+		}
+		attributeMap.set(att, value);
+	}
 
 
 	/**
 	/**
 		Removes an attribute for an Element node.
 		Removes an attribute for an Element node.
 		Attributes are case-sensitive.
 		Attributes are case-sensitive.
 	**/
 	**/
-	function remove( att : String ) : Void;
+	public function remove( att : String ) : Void {
+		if (nodeType != Element) {
+			throw 'Bad node type, expected Element but found $nodeType';
+		}
+		attributeMap.remove(att);
+	}
 
 
 	/**
 	/**
 		Tells if the Element node has a given attribute.
 		Tells if the Element node has a given attribute.
 		Attributes are case-sensitive.
 		Attributes are case-sensitive.
 	**/
 	**/
-	function exists( att : String ) : Bool;
+	public function exists( att : String ) : Bool {
+		if (nodeType != Element) {
+			throw 'Bad node type, expected Element but found $nodeType';
+		}
+		return attributeMap.exists(att);
+	}
 
 
 	/**
 	/**
 		Returns an [Iterator] on all the attribute names.
 		Returns an [Iterator] on all the attribute names.
 	**/
 	**/
-	function attributes() : Iterator<String>;
-
-	/**
-		Returns the parent object in the Xml hierarchy.
-		The parent can be [null], an Element or a Document.
-	**/
-	var parent(get,null) : Xml;
+	public function attributes() : Iterator<String> {
+		if (nodeType != Element) {
+			throw 'Bad node type, expected Element but found $nodeType';
+		}
+		return attributeMap.keys();
+	}
 
 
 	/**
 	/**
 		Returns an iterator of all child nodes.
 		Returns an iterator of all child nodes.
 		Only works if the current node is an Element or a Document.
 		Only works if the current node is an Element or a Document.
 	**/
 	**/
-	function iterator() : Iterator<Xml>;
+	public inline function iterator() : Iterator<Xml> {
+		ensureElementType();
+		return children.iterator();
+	}
 
 
 	/**
 	/**
 		Returns an iterator of all child nodes which are Elements.
 		Returns an iterator of all child nodes which are Elements.
 		Only works if the current node is an Element or a Document.
 		Only works if the current node is an Element or a Document.
 	**/
 	**/
-	function elements() : Iterator<Xml>;
+	public function elements() : Iterator<Xml> {
+		ensureElementType();
+		var ret = [for (child in children) if (child.nodeType == Element) child];
+		return ret.iterator();
+	}
 
 
 	/**
 	/**
 		Returns an iterator of all child nodes which are Elements with the given nodeName.
 		Returns an iterator of all child nodes which are Elements with the given nodeName.
 		Only works if the current node is an Element or a Document.
 		Only works if the current node is an Element or a Document.
 	**/
 	**/
-	function elementsNamed( name : String ) : Iterator<Xml>;
+	public function elementsNamed( name : String ) : Iterator<Xml> {
+		ensureElementType();
+		var ret = [for (child in children) if (child.nodeType == Element && child.nodeName == name) child];
+		return ret.iterator();
+	}
 
 
 	/**
 	/**
 		Returns the first child node.
 		Returns the first child node.
 	**/
 	**/
-	function firstChild() : Xml;
+	public inline function firstChild() : Xml {
+		ensureElementType();
+		return children[0];
+	}
 
 
 	/**
 	/**
 		Returns the first child node which is an Element.
 		Returns the first child node which is an Element.
 	**/
 	**/
-	function firstElement() : Xml;
-
+	public function firstElement() : Xml {
+		ensureElementType();
+		for (child in children) {
+			if (child.nodeType == Element) {
+				return child;
+			}
+		}
+		return null;
+	}
 
 
 	/**
 	/**
 		Adds a child node to the Document or Element.
 		Adds a child node to the Document or Element.
 		One node can only be inside one given node which is indicated by the [parent] property.
 		One node can only be inside one given node which is indicated by the [parent] property.
 	**/
 	**/
-	function addChild( x : Xml ) : Void;
+	public function addChild( x : Xml ) : Void {
+		ensureElementType();
+		if (x.parent == this) {
+			return;
+		} else if (x.parent != null) {
+			x.parent.removeChild(x);
+		}
+		children.push(x);
+		x.parent = this;
+	}
 
 
 	/**
 	/**
 		Removes a child from the Document or Element.
 		Removes a child from the Document or Element.
 		Returns true if the child was successfuly removed.
 		Returns true if the child was successfuly removed.
 	**/
 	**/
-	function removeChild( x : Xml ) : Bool;
+	public function removeChild( x : Xml ) : Bool {
+		ensureElementType();
+		return children.remove(x);
+	}
 
 
 	/**
 	/**
 		Inserts a child at the given position among the other childs.
 		Inserts a child at the given position among the other childs.
 	**/
 	**/
-	function insertChild( x : Xml, pos : Int ) : Void;
+	public function insertChild( x : Xml, pos : Int ) : Void {
+		ensureElementType();
+		children.insert(pos, x);
+	}
 
 
 	/**
 	/**
 		Returns a String representation of the Xml node.
 		Returns a String representation of the Xml node.
 	**/
 	**/
-	function toString() : String;
-
+	public inline function toString() : String {
+		return haxe.xml.Printer.print(this);
+	}
+
+	function new(nodeType:XmlType) {
+		this.nodeType = nodeType;
+		children = [];
+		attributeMap = new Map();
+	}
+
+	inline function ensureElementType() {
+		if (nodeType != Document && nodeType != Element) {
+			throw 'Bad node type, expected Element or Document but found $nodeType';
+		}
+	}
 }
 }

+ 0 - 421
std/cpp/_std/Xml.hx

@@ -1,421 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-enum XmlType {
-}
-
-@:coreApi class Xml {
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-
-	private var _nodeName : String;
-	private var _nodeValue : String;
-	private var _attributes : Dynamic<String>;
-	private var _children : Array<Xml>;
-	private var _parent : Xml;
-
-	function new() : Void {
-	}
-
-	private static var _parse = cpp.Lib.load("std","parse_xml",2);
-
-	@:analyzer(ignore) public static function parse( str : String ) : Xml {
-		var x = new Xml();
-		x._children = new Array();
-		var parser = {
-			cur : x,
-			xml : function(name,att) {
-				var x = new Xml();
-				x._parent = untyped __this__.cur;
-				x.nodeType = Xml.Element;
-				x._nodeName = new String(name);
-				x._attributes = att;
-				x._children = new Array();
-				untyped {
-					var i = 0;
-					__this__.cur.addChild(x);
-					__this__.cur = x;
-				}
-			},
-			cdata : function(text) {
-				var x = new Xml();
-				x._parent = untyped __this__.cur;
-				x.nodeType = Xml.CData;
-				x._nodeValue = new String(text);
-				untyped __this__.cur.addChild(x);
-			},
-			pcdata : function(text) {
-				var x = new Xml();
-				x._parent = untyped __this__.cur;
-				x.nodeType = Xml.PCData;
-				x._nodeValue = new String(text);
-				untyped __this__.cur.addChild(x);
-			},
-			comment : function(text:String) {
-				var x = new Xml();
-				x._parent = untyped __this__.cur;
-				if( untyped text.cca(0) == 63 ) {
-					x.nodeType = Xml.ProcessingInstruction;
-					text = new String(text);
-					text = text.substr(1, text.length - 2);
-				} else {
-					x.nodeType = Xml.Comment;
-					text = new String(text);
-				}
-				x._nodeValue = text;
-				untyped __this__.cur.addChild(x);
-			},
-			doctype : function(text) {
-				var x = new Xml();
-				x._parent = untyped __this__.cur;
-				x.nodeType = Xml.DocType;
-				x._nodeValue = (new String(text)).substr(1);
-				var p : Xml = untyped __this__.cur;
-				p.addChild(x);
-			},
-			done : function() {
-				untyped __this__.cur = __this__.cur._parent;
-			}
-		};
-		untyped _parse(str,parser);
-		x.nodeType = Xml.Document;
-		return x;
-	}
-
-
-	public static function createElement( name : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Element;
-		r._nodeName = name;
-		r._attributes = null;
-		r._children = new Array();
-		return r;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.PCData;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.CData;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createComment( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Comment;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.DocType;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.ProcessingInstruction;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	public var nodeType(default,null) : XmlType;
-
-	public var nodeName(get,set) : String;
-
-	public var nodeValue(get,set) : String;
-
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	public var parent(get,null) : Xml;
-	private function get_parent() : Xml {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.field( _attributes, att );
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		if (_attributes==null)
-			_attributes = {};
-		Reflect.setField (_attributes, att, value );
-		return null;
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		Reflect.deleteField( _attributes, att );
-		return null;
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.hasField( _attributes, att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.fields( _attributes ).iterator();
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if( _children == null )
-			throw "bad nodetype";
-      return untyped _children.iterator();
-	}
-
-
-	@:analyzer(ignore) public function elements(): Iterator<Xml> {
-		if( _children == null )
-			throw "bad nodetype";
-      var children = _children;
-		return untyped {
-			cur: 0,
-			hasNext : function() {
-				var k:Int = __this__.cur;
-				var l = children.length;
-				while( k < l ) {
-					if( children[k].nodeType == Xml.Element )
-						break;
-					k += 1;
-				}
-				__this__.cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = __this__.cur;
-				var l = children.length;
-				while( k < l ) {
-					var n = children[k];
-					k += 1;
-					if( n.nodeType == Xml.Element ) {
-						__this__.cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	@:analyzer(ignore) public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( _children == null )
-			throw "bad nodetype";
-      var children = _children;
-		return untyped {
-			cur: 0,
-			hasNext : function() {
-				var k = __this__.cur;
-				var l = children.length;
-				while( k < l ) {
-					var n = children[k];
-					if( n.nodeType == Xml.Element && n._nodeName == name )
-						break;
-					k++;
-				}
-				__this__.cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = __this__.cur;
-				var l = children.length;
-				while( k < l ) {
-					var n = children[k];
-					k++;
-					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						__this__.cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function firstChild() : Xml {
-		if( _children == null )
-			throw "bad nodetype";
-		return _children[0];
-	}
-
-	public function firstElement() : Xml {
-		if( _children == null )
-			throw "bad nodetype";
-		for( cur in 0..._children.length ) {
-			var n:Xml = _children[cur];
-			if( n.nodeType == Xml.Element )
-				return n;
-		}
-		return null;
-	}
-
-   public function addChild( x : Xml ) : Void {
-		if( _children == null )
-			throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-		return null;
-	}
-
-   public function removeChild( x : Xml ) : Bool {
-		if( _children == null )
-			throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b ) x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( _children == null )
-			throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-		return null;
-	}
-
-	public function toString() : String {
-		var s = new StringBuf();
-		toStringRec(s);
-		return s.toString();
-	}
-
-	private function toStringRec(s: StringBuf) : Void {
-		switch( nodeType ) {
-		case Xml.Document:
-			for( x in _children )
-				x.toStringRec(s);
-		case Xml.Element:
-			s.addChar("<".code);
-			s.add(_nodeName);
-			for( k in Reflect.fields(_attributes) ) {
-				s.addChar(" ".code);
-				s.add(k);
-				s.addChar("=".code);
-				s.addChar("\"".code);
-				s.add(Reflect.field(_attributes,k));
-				s.addChar("\"".code);
-			}
-			if( _children.length == 0 ) {
-				s.addChar("/".code);
-				s.addChar(">".code);
-				return;
-			}
-			s.addChar(">".code);
-			for( x in _children )
-				x.toStringRec(s);
-			s.addChar("<".code);
-			s.addChar("/".code);
-			s.add(_nodeName);
-			s.addChar(">".code);
-		case Xml.PCData:
-			s.add(StringTools.htmlEscape(_nodeValue));
-		case Xml.CData:
-			s.add("<![CDATA[");
-			s.add(_nodeValue);
-			s.add("]]>");
-		case Xml.Comment:
-			s.add("<!--");
-			s.add(_nodeValue);
-			s.add("-->");
-		case Xml.DocType:
-			s.add("<!DOCTYPE ");
-			s.add(_nodeValue);
-			s.add(">");
-		case Xml.ProcessingInstruction:
-			s.add("<?");
-			s.add(_nodeValue);
-			s.add("?>");
-		}
-	}
-
-	static function __init__() : Void untyped {
-		PCData = Type.createEnum(XmlType,"__");
-		Element = Type.createEnum(XmlType,"__");
-		CData =  Type.createEnum(XmlType,"__");
-		Comment = Type.createEnum(XmlType,"__");
-		DocType = Type.createEnum(XmlType,"__");
-		ProcessingInstruction =  Type.createEnum(XmlType,"__");
-		Document = Type.createEnum(XmlType,"__");
-		__global__.__hxcpp_enum_force(PCData , "pcdata", 0);
-		__global__.__hxcpp_enum_force(Element , "element", 1);
-		__global__.__hxcpp_enum_force(CData , "cdata", 2);
-		__global__.__hxcpp_enum_force(Comment , "comment", 3);
-		__global__.__hxcpp_enum_force(DocType , "doctype", 4);
-		__global__.__hxcpp_enum_force(ProcessingInstruction , "processingInstruction", 5);
-		__global__.__hxcpp_enum_force(Document , "document", 6);
-	}
-
-}
-

+ 0 - 345
std/cs/_std/Xml.hx

@@ -1,345 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-@:native("_Xml.RealXmlType")
-extern enum XmlType {
-}
-
-private enum RealXmlType {
-        Element;
-        PCData;
-        CData;
-        Comment;
-        DocType;
-        ProcessingInstruction;
-        Document;
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-
-	var _nodeName : String;
-	var _nodeValue : String;
-	var _attributes : haxe.ds.StringMap<String>;
-	var _children : Array<Xml>;
-	var _parent : Xml;
-
-	public static function parse( str : String ) : Xml {
-		return haxe.xml.Parser.parse(str);
-	}
-
-	private function new() : Void {
-	}
-
-	public static function createElement( name : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Element;
-		r._children = new Array();
-		r._attributes = new haxe.ds.StringMap();
-		r.set_nodeName( name );
-		return r;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.PCData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.CData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createComment( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Comment;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.DocType;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.ProcessingInstruction;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	private function get_parent() : Xml {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.get( att );
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.set( att, value );
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.remove( att );
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.exists( att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.keys();
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = this._children;
-		return {
-			hasNext : function(){
-				return cur < x.length;
-			},
-			next : function(){
-				return x[cur++];
-			}
-		}
-	}
-
-	public function elements() : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = _children;
-		return untyped {
-			hasNext : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					if( x[k].nodeType == Xml.Element )
-						break;
-					k += 1;
-				}
-				cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					k += 1;
-					if( n.nodeType == Xml.Element ) {
-						cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var x = _children;
-		var cur = 0;
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					if( n.nodeType == Xml.Element && n._nodeName == name )
-						break;
-					k++;
-				}
-				cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					k++;
-					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function firstChild() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		return _children[0];
-	}
-
-	public function firstElement() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var l = _children.length;
-		while( cur < l ) {
-			var n = _children[cur];
-			if( n.nodeType == Xml.Element )
-				return n;
-			cur++;
-		}
-		return null;
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( _children == null ) throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b )
-			x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-	}
-
-	public function toString() : String {
-		if( nodeType == Xml.PCData )
-			return StringTools.htmlEscape(_nodeValue);
-		if( nodeType == Xml.CData )
-			return "<![CDATA["+_nodeValue+"]]>";
-		if( nodeType == Xml.Comment )
-			return "<!--"+_nodeValue+"-->";
-		if( nodeType == Xml.DocType )
-			return "<!DOCTYPE "+_nodeValue+">";
-		if( nodeType == Xml.ProcessingInstruction )
-			return "<?"+_nodeValue+"?>";
-		var s = new StringBuf();
-
-		if( nodeType == Xml.Element ) {
-			s.add("<");
-			s.add(_nodeName);
-			for( k in _attributes.keys() ){
-				s.add(" ");
-				s.add(k);
-				s.add("=\"");
-				s.add(_attributes.get(k));
-				s.add("\"");
-			}
-			if( _children.length == 0 ) {
-				s.add("/>");
-				return s.toString();
-			}
-			s.add(">");
-		}
-
-		for( x in iterator() )
-			s.add(x.toString());
-
-		if( nodeType == Xml.Element ) {
-			s.add("</");
-			s.add(_nodeName);
-			s.add(">");
-		}
-		return s.toString();
-	}
-
-	static function __init__() : Void untyped {
-		Xml.Element = cast RealXmlType.Element;
-		Xml.PCData = cast RealXmlType.PCData;
-		Xml.CData = cast RealXmlType.CData;
-		Xml.Comment = cast RealXmlType.Comment;
-		Xml.DocType = cast RealXmlType.DocType;
-		Xml.ProcessingInstruction = cast RealXmlType.ProcessingInstruction;
-		Xml.Document = cast RealXmlType.Document;
-	}
-
-}

+ 0 - 417
std/flash/_std/Xml.hx

@@ -1,417 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-import flash.xml.XML;
-import flash.xml.XMLList;
-
-extern enum XmlType {
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-
-	var _node : flash.xml.XML;
-
-	public static function parse( str : String ) : Xml {
-		XML.ignoreWhitespace = false;
-		XML.ignoreProcessingInstructions = false;
-		XML.ignoreComments = false;
-		var prefix = "<__document";
-		var root = null;
-		while( root == null ) {
-			try {
-				root = new flash.xml.XML(prefix+">" + str + "</__document>");
-			} catch( e : flash.errors.TypeError ) {
-				// if we miss a namespace, let's add it !
-				var r = ~/"([^"]+)"/; //"
-				if( e.errorID == 1083 && r.match(e.message) ) {
-					var ns = r.matched(1);
-					prefix += " xmlns:" + ns + '="@' + ns + '"';
-				} else
-					throw e;
-			}
-		}
-		return wrap( root, Xml.Document );
-	}
-
-	@:keep #if as3 @:hack public #end static function compare( a : Xml, b : Xml ) : Bool {
-		return a == null ? b == null : (b == null ? false : a._node == b._node);
-	}
-
-	private function new() : Void {}
-
-	public static function createElement( name : String ) : Xml {
-		return wrap( new flash.xml.XML("<"+name+"/>"), Xml.Element );
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		XML.ignoreWhitespace = false;
-		return wrap( new flash.xml.XML(data), Xml.PCData );
-	}
-
-	public static function createCData( data : String ) : Xml {
-		return wrap( new flash.xml.XML("<![CDATA["+data+"]]>"), Xml.CData );
-	}
-
-	public static function createComment( data : String ) : Xml {
-		XML.ignoreComments = false;
-		return wrap( new flash.xml.XML("<!--"+data+"-->"), Xml.Comment );
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		return wrap( new flash.xml.XML("<!DOCTYPE "+data+">"), Xml.DocType );
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		XML.ignoreProcessingInstructions = false;
-		return wrap( new flash.xml.XML("<?"+data+"?>"), Xml.ProcessingInstruction );
-	}
-
-	public static function createDocument() : Xml {
-		return wrap( new flash.xml.XML("<__document/>"), Xml.Document );
-	}
-
-	private static function getNodeType( node : flash.xml.XML ) : XmlType {
-		switch( node.nodeKind() ) {
-		case "element":
-			return Xml.Element;
-		case "text":
-			return Xml.PCData;
-		case "processing-instruction":
-			return Xml.ProcessingInstruction;
-		case "comment":
-			return Xml.Comment;
-		default :
-			throw "unimplemented node type: " + node.nodeType;
-		}
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = _node.namespace();
-		return (ns.prefix == "") ? _node.localName() : ns.prefix+":"+_node.localName();
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = n.split(":");
-		if( ns.length == 1 )
-			_node.setLocalName(n);
-		else {
-			_node.setLocalName(ns[1]);
-			_node.setNamespace(_node.namespace(ns[0]));
-		}
-		return n;
-	}
-
-	private function get_nodeValue() : String {
-		var nodeType = nodeType;
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		if( nodeType == Xml.Comment )
-			return _node.toString().substr(4,-7);
-		return _node.toString();
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		var nodeType = nodeType;
-		var x = null;
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		else if( nodeType == Xml.PCData )
-			x = createPCData(v);
-		else if( nodeType == Xml.CData )
-			x = createCData(v);
-		else if( nodeType == Xml.Comment )
-			x = createComment(v);
-		else if( nodeType == Xml.DocType )
-			x = createDocType(v);
-		else
-			x = createProcessingInstruction(v);
-		var p = _node.parent();
-		if( p != null ) {
-			p.insertChildAfter(_node, x._node);
-			var i = _node.childIndex();
-			var children = p.children();
-			untyped __delete__(children, Reflect.fields(children)[i]);
-		}
-		_node = x._node;
-		return v;
-	}
-
-	private function get_parent() :Xml {
-		var p = _node.parent();
-		return p == null ? null : wrap( p );
-	}
-
-	private static function wrap( node : XML, ?type : XmlType ) : Xml {
-		var x = new Xml();
-		x._node = node;
-		x.nodeType = (type != null) ? type : getNodeType( node );
-		return x;
-	}
-
-	private function wraps( xList : XMLList ) : Array<Xml> {
-		var out = new Array<Xml>();
-		for( i in 0...xList.length() )
-			out.push( wrap(xList[i]) );
-		return out;
-	}
-
-	function getAttribNS( cur : XML, ns : Array<String> ) : XMLList {
-		var n = cur.namespace(ns[0]);
-		if( n == null ) {
-			var parent = cur.parent();
-			if( parent == null ) {
-				n = new flash.utils.Namespace(ns[0], "@"+ns[0]);
-				cur.addNamespace(n);
-			} else
-				return getAttribNS(parent, ns);
-		}
-		return _node.attribute(new flash.utils.QName(n,ns[1]));
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = att.split(":");
-		if( ns[0] == "xmlns" ) {
-			var n = _node.namespace((ns[1] == null) ? "" : ns[1]);
-			return (n == null) ? null : n.uri;
-		}
-		if( ns.length == 1 ) {
-			if( !Reflect.hasField(_node,"@"+att) )
-				return null;
-			return Reflect.field(_node, "@"+att);
-		}
-		var a = getAttribNS(_node,ns);
-		return (a.length() == 0) ? null : a.toString();
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = att.split(":");
-		if( ns[0] == "xmlns" ) {
-			var n = _node.namespace((ns[1] == null) ? "" : ns[1]);
-			if( n != null )
-				throw "Can't modify namespace";
-			if( ns[1] == null )
-				throw "Can't set default namespace";
-			_node.addNamespace(new flash.utils.Namespace(ns[1], value));
-			return;
-		}
-		if( ns.length == 1 )
-			Reflect.setField(_node, "@"+att, value);
-		else {
-			var a = getAttribNS(_node,ns);
-			untyped a[0] = value;
-		}
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = att.split(":");
-		if( ns.length == 1 )
-			Reflect.deleteField(_node, "@"+att);
-		else
-			untyped __delete__(getAttribNS(_node,ns),0);
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		var ns = att.split(":");
-		if( ns[0] == "xmlns" )
-			return _node.namespace((ns[1] == null) ? "" : ns[1]) != null;
-		if( ns.length == 1 )
-			return Reflect.hasField(_node, "@"+att);
-		return getAttribNS(_node,ns).length() > 0;
-	}
-
-	public function attributes() : Iterator<String> {
-	    if( nodeType != Xml.Element )
-	        throw "bad nodeType";
-	    var attributes :XMLList = _node.attributes();
-	    var names = Reflect.fields(attributes);
-	    var cur = 0;
-	    var nss = _node.namespaceDeclarations();
-	    return {
-	        hasNext : function(){
-	            return cur < names.length + nss.length;
-	        },
-	        next : function() {
-	            if(cur<names.length){
-	                return attributes[Std.parseInt(names[cur++])].name();
-	            }else {
-	                var ns:flash.utils.Namespace = nss[cur++ - names.length];
-	                return "xmlns:"+ns.prefix;
-	            }
-	        }
-	    }
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var children:XMLList = _node.children();
-		var wrappers :Array<Xml> = wraps(children);
-		var cur = 0;
-		return {
-			hasNext : function(){
-				return cur < wrappers.length;
-			},
-			next : function(){
-				return wrappers[cur++];
-			}
-		};
-	}
-
-	public function elements() : Iterator<Xml> {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var elements:XMLList = _node.elements();
-		var wrappers :Array<Xml> = wraps(elements);
-		var cur = 0;
-		return {
-			hasNext : function(){
-				return cur < wrappers.length;
-			},
-			next : function(){
-				return wrappers[cur++];
-			}
-		};
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var ns = name.split(":");
-		var elements:XMLList;
-		if( ns.length == 1 )
-			elements = _node.elements(name);
-		else
-			elements = _node.elements();
-		var wrappers :Array<Xml> = wraps(elements);
-		if( ns.length != 1 )
-			for( w in wrappers.copy() )
-				if( w._node.localName() != ns[1] || w._node.namespace().prefix != ns[0] )
-					wrappers.remove(w);
-		var cur = 0;
-		return {
-			hasNext : function(){
-				return cur < wrappers.length;
-			},
-			next : function(){
-				return wrappers[cur++];
-			}
-		};
-	}
-
-	public function firstChild() : Xml {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var children:XMLList = _node.children();
-		if( children.length() == 0 )
-			return null;
-		return wrap( children[0] );
-	}
-
-	public function firstElement() : Xml {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var elements:XMLList = _node.elements();
-		if( elements.length() == 0 )
-			return null;
-		return wrap( elements[0] );
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		if (x.parent != null)
-			x.parent.removeChild(x);
-		var children:XMLList = _node.children();
-		_node.appendChild(x._node);
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var children:XMLList = _node.children();
-		if( _node != x._node.parent() )
-			return false;
-		var i = x._node.childIndex();
-		untyped __delete__(children, Reflect.fields(children)[i]);
-		return true;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		if (x.parent != null)
-			x.parent.removeChild(x);
-		var children:XMLList = _node.children();
-		if( pos < children.length() )
-			_node.insertChildBefore(children[pos], x._node);
-		else
-			_node.appendChild(x._node);
-	}
-
-	public function toString() : String {
-		XML.prettyPrinting = false;
-		if( nodeType == Xml.Document ) {
-			var str = _node.toXMLString();
-			// remove <__document xmlns....>STR</__document> wrapper
-			str = str.substr(str.indexOf(">") + 1);
-			str = str.substr(0, str.length - 13);
-			return str;
-		}
-		return _node.toXMLString();
-	}
-
-	static function __init__() : Void untyped {
-		Element = "element";
-		PCData = "pcdata";
-		CData = "cdata";
-		Comment = "comment";
-		DocType = "doctype";
-		ProcessingInstruction = "processingInstruction";
-		Document = "document";
-	}
-
-
-}

+ 0 - 315
std/flash8/_std/Xml.hx

@@ -1,315 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-enum XmlType {
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-	public var nodeType(default,null) : XmlType;
-
-	private var __x : Dynamic;
-
-	private static function convert( o : Dynamic ) : Xml {
-		if( o == null ) return null;
-		if( o.__w != null ) return o.__w;
-
-		var r = new Xml();
-		r.__x = o;
-		o.__w = r;
-
-		r.nodeType = switch( untyped o["nodeType"] ) {
-			case 1:
-				Xml.Element;
-			case 3:
-				Xml.PCData;
-			default:
-				throw "unknow nodeType: "+untyped o["nodeType"];
-		}
-
-		return untyped r;
-	}
-
-	public static function parse( str : String ) : Xml untyped {
-		var x = __new__(_global["XML"]);
-		x["parseXML"](str);
-		if( x["status"] != 0 )
-			throw ("Xml parse error #"+x["status"]);
-
-		var r = convert(x);
-		r.nodeType = Xml.Document;
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var o = untyped __new__(_global["XML"])["createElement"]( "#document" );
-
-		var r = convert(o);
-		r.nodeType = Xml.Document;
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var o = untyped __new__(_global["XML"])["createTextNode"]( data );
-		var x = convert(o);
-		x.nodeType = Xml.CData;
-		return x;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var o = untyped __new__(_global["XML"])["createTextNode"]( data );
-		return convert(o);
-	}
-
-	public static function createElement( name : String ) : Xml {
-		var o = untyped __new__(_global["XML"])["createElement"]( name );
-		return convert(o);
-	}
-
-	public static function createComment( data : String ) : Xml {
-		throw "not implemented";
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var x = createPCData("");
-		x.nodeType = Xml.DocType;
-		x.nodeValue = data;
-		return x;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var x = createPCData("");
-		x.nodeType = Xml.ProcessingInstruction;
-		x.nodeValue = data;
-		return x;
-	}
-
-	private function new() : Void {
-	}
-
-	public function firstChild() : Xml {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		return convert(this.__x[untyped "firstChild"]);
-	}
-
-	public function firstElement() : Xml {
-		if( nodeType != Xml.Element && nodeType != Xml.Document )
-			throw "bad nodeType";
-		var e : Dynamic = __x[untyped "firstChild"];
-		while( e != null && e[untyped "nodeType"] != 1 )
-			e = e[untyped "nextSibling"];
-		return convert(e);
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return __x[untyped "nodeName"] = n;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return __x[untyped "nodeValue"] = v;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return __x[untyped "nodeName"];
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return __x[untyped "nodeValue"];
-	}
-
-	private function get_parent() : Xml {
-		return convert(__x[untyped "parentNode"]);
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if( nodeType != Xml.Document && nodeType != Xml.Element )
-			throw "bad nodeType";
-		return untyped {
-			cur: this.__x[untyped "firstChild"],
-			hasNext : function(){
-				return __this__.cur != null;
-			},
-			next : function(){
-				var r = convert(__this__.cur);
-				__this__.cur = __this__.cur["nextSibling"];
-				return r;
-			}
-		}
-	}
-
-	public function elements() : Iterator<Xml> {
-		if( nodeType != Xml.Document && nodeType != Xml.Element )
-			throw "bad nodeType";
-		return untyped {
-			cur: this.__x[untyped "firstChild"],
-			hasNext : function() {
-				var r = __this__.cur;
-				while( r != null && r["nodeType"] != 1 )
-					r = r["nextSibling"];
-				__this__.cur = r;
-				return r != null;
-			},
-			next : function(){
-				var r = __this__.cur;
-				while( r != null && r["nodeType"] != 1 )
-					r = r["nextSibling"];
-				if( r == null ) {
-					__this__.cur = null;
-					return null;
-				}
-				__this__.cur = r["nextSibling"];
-				return convert(r);
-			}
-		}
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( nodeType != Xml.Document && nodeType != Xml.Element )
-			throw "bad nodeType";
-		return untyped {
-			cur: this.__x[untyped "firstChild"],
-			hasNext : function() {
-				var r = __this__.cur;
-				while( r != null && (r["nodeType"] != 1 || r["nodeName"] != name) )
-					r = r["nextSibling"];
-				__this__.cur = r;
-				return r != null;
-			},
-			next : function(){
-				var r = __this__.cur;
-				while( r != null && (r["nodeType"] != 1 || r["nodeName"] != name) )
-					r = r["nextSibling"];
-				if( r == null ) {
-					__this__.cur = null;
-					return null;
-				}
-				__this__.cur = r["nextSibling"];
-				return convert(r);
-			}
-		}
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.field(__x[untyped "attributes"],att);
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.setField(__x[untyped "attributes"],att,value);
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.hasField(__x[untyped "attributes"],att);
-	}
-
-	public function remove( att : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		Reflect.deleteField(__x[untyped "attributes"],att);
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return untyped __keys__(__x["attributes"])["iterator"]();
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( nodeType != Xml.Document && nodeType != Xml.Element )
-			throw "bad nodeType";
-		untyped __x[untyped "appendChild"](x.__x);
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( nodeType != Xml.Document && nodeType != Xml.Element )
-			throw "bad nodeType";
-		untyped if( x.__x["parentNode"] != __x )
-			return false;
-		untyped x.__x["removeNode"]();
-		return true;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( nodeType != Xml.Document && nodeType != Xml.Element )
-			throw "bad nodeType";
-		var c : Array<Dynamic> = __x[untyped "childNodes"];
-		if( pos <= c.length )
-			__x[untyped "insertBefore"](untyped x.__x,c[pos]);
-	}
-
-	public function toString() : String {
-		if( nodeType == Xml.Document ){
-			var s = "";
-			for( c in iterator() )
-				s += c.toString();
-			return s;
-		}
-		// only works for toplevel elements
-		if( nodeType == Xml.CData )
-			return "<![CDATA["+__x[untyped "nodeValue"]+"]]>";
-		if( nodeType == Xml.ProcessingInstruction )
-			return "<?"+__x[untyped "nodeValue"]+"?>";
-		if( nodeType == Xml.DocType )
-			return "<!DOCTYPE "+__x[untyped "nodeValue"]+">";
-		var s : String = __x.toString();
-		return s.split(" />").join("/>");
-	}
-
-	static function __init__() : Void untyped {
-		Xml.Element = "element";
-		Xml.PCData = "pcdata";
-		Xml.CData = "cdata";
-		Xml.Comment = "comment";
-		Xml.DocType = "doctype";
-		Xml.ProcessingInstruction = "processingInstruction";
-		Xml.Document = "document";
-		#if swf_mark
-		flash.Lib.current["Xml"] = Xml;
-		#end
-	}
-
-}

+ 33 - 21
std/haxe/xml/Parser.hx

@@ -55,7 +55,6 @@ class Parser
 		h.set("amp", "&");
 		h.set("amp", "&");
 		h.set("quot", '"');
 		h.set("quot", '"');
 		h.set("apos", "'");
 		h.set("apos", "'");
-		h.set("nbsp", String.fromCharCode(160));
 		h;
 		h;
 	}
 	}
 
 
@@ -77,6 +76,9 @@ class Parser
 		var nbrackets = 0;
 		var nbrackets = 0;
 		var c = str.fastCodeAt(p);
 		var c = str.fastCodeAt(p);
 		var buf = new StringBuf();
 		var buf = new StringBuf();
+		// need extra state because next is in use
+		var escapeNext = S.BEGIN;
+		var attrValQuote = -1;
 		while (!StringTools.isEof(c))
 		while (!StringTools.isEof(c))
 		{
 		{
 			switch(state)
 			switch(state)
@@ -107,25 +109,18 @@ class Parser
 				case S.PCDATA:
 				case S.PCDATA:
 					if (c == '<'.code)
 					if (c == '<'.code)
 					{
 					{
-						#if php
-						var child = Xml.createPCDataFromCustomParser(buf.toString() + str.substr(start, p - start));
-						#else
 						var child = Xml.createPCData(buf.toString() + str.substr(start, p - start));
 						var child = Xml.createPCData(buf.toString() + str.substr(start, p - start));
-						#end
 						buf = new StringBuf();
 						buf = new StringBuf();
 						parent.addChild(child);
 						parent.addChild(child);
 						nsubs++;
 						nsubs++;
 						state = S.IGNORE_SPACES;
 						state = S.IGNORE_SPACES;
 						next = S.BEGIN_NODE;
 						next = S.BEGIN_NODE;
-					}
-					#if !flash9
-					else if (c == '&'.code) {
+					} else if (c == '&'.code) {
 						buf.addSub(str, start, p - start);
 						buf.addSub(str, start, p - start);
 						state = S.ESCAPE;
 						state = S.ESCAPE;
-						next = S.PCDATA;
+						escapeNext = S.PCDATA;
 						start = p + 1;
 						start = p + 1;
 					}
 					}
-					#end
 				case S.CDATA:
 				case S.CDATA:
 					if (c == ']'.code && str.fastCodeAt(p + 1) == ']'.code && str.fastCodeAt(p + 2) == '>'.code)
 					if (c == ']'.code && str.fastCodeAt(p + 1) == ']'.code && str.fastCodeAt(p + 2) == '>'.code)
 					{
 					{
@@ -229,19 +224,29 @@ class Parser
 				case S.ATTVAL_BEGIN:
 				case S.ATTVAL_BEGIN:
 					switch(c)
 					switch(c)
 					{
 					{
-						case '"'.code, '\''.code:
+						case '"'.code | '\''.code:
+							buf = new StringBuf();
 							state = S.ATTRIB_VAL;
 							state = S.ATTRIB_VAL;
-							start = p;
+							start = p + 1;
+							attrValQuote = c;
 						default:
 						default:
 							throw("Expected \"");
 							throw("Expected \"");
 					}
 					}
 				case S.ATTRIB_VAL:
 				case S.ATTRIB_VAL:
-					if (c == str.fastCodeAt(start))
-					{
-						var val = str.substr(start+1,p-start-1);
-						xml.set(aname, val);
-						state = S.IGNORE_SPACES;
-						next = S.BODY;
+					switch (c) {
+						case '&'.code:
+							buf.addSub(str, start, p - start);
+							state = S.ESCAPE;
+							escapeNext = S.ATTRIB_VAL;
+							start = p + 1;
+						case '>'.code | '<'.code:
+							throw "Invalid unescaped " + String.fromCharCode(c) + " in attribute value";
+						case _ if (c == attrValQuote):
+							var val = buf.toString() + str.substr(start, p - start);
+							buf = new StringBuf();
+							xml.set(aname, val);
+							state = S.IGNORE_SPACES;
+							next = S.BODY;
 					}
 					}
 				case S.CHILDS:
 				case S.CHILDS:
 					p = doParse(str, p, xml);
 					p = doParse(str, p, xml);
@@ -313,12 +318,19 @@ class Parser
 								? Std.parseInt("0" +s.substr(1, s.length - 1))
 								? Std.parseInt("0" +s.substr(1, s.length - 1))
 								: Std.parseInt(s.substr(1, s.length - 1));
 								: Std.parseInt(s.substr(1, s.length - 1));
 							buf.add(String.fromCharCode(i));
 							buf.add(String.fromCharCode(i));
-						} else if (!escapes.exists(s))
+						} else if (!escapes.exists(s)) {
+							#if xml_strict
+							throw 'Undefined entity: $s';
+							#else
 							buf.add('&$s;');
 							buf.add('&$s;');
-						else
+							#end
+						} else {
 							buf.add(escapes.get(s));
 							buf.add(escapes.get(s));
+						}
 						start = p + 1;
 						start = p + 1;
-						state = next;
+						state = escapeNext;
+					} else if (!isValidChar(c) && c != "#".code) {
+						throw 'Invalid character in entity: ' + String.fromCharCode(c);
 					}
 					}
 			}
 			}
 			c = str.fastCodeAt(++p);
 			c = str.fastCodeAt(++p);

+ 10 - 9
std/haxe/xml/Printer.hx

@@ -46,28 +46,28 @@ class Printer {
 
 
 	function writeNode(value:Xml, tabs:String) {
 	function writeNode(value:Xml, tabs:String) {
 		switch (value.nodeType) {
 		switch (value.nodeType) {
-			case Xml.CData:
+			case CData:
 				write(tabs + "<![CDATA[");
 				write(tabs + "<![CDATA[");
 				write(StringTools.trim(value.nodeValue));
 				write(StringTools.trim(value.nodeValue));
 				write("]]>");
 				write("]]>");
 				newline();
 				newline();
-			case Xml.Comment:
+			case Comment:
 				var commentContent:String = value.nodeValue;
 				var commentContent:String = value.nodeValue;
 				commentContent = ~/[\n\r\t]+/g.replace(commentContent, "");
 				commentContent = ~/[\n\r\t]+/g.replace(commentContent, "");
 				commentContent = "<!--" + commentContent + "-->";
 				commentContent = "<!--" + commentContent + "-->";
 				write(tabs);
 				write(tabs);
 				write(StringTools.trim(commentContent));
 				write(StringTools.trim(commentContent));
 				newline();
 				newline();
-			case Xml.Document:
+			case Document:
 				for (child in value) {
 				for (child in value) {
 					writeNode(child, tabs);
 					writeNode(child, tabs);
 				}
 				}
-			case Xml.Element:
+			case Element:
 				write(tabs + "<");
 				write(tabs + "<");
 				write(value.nodeName);
 				write(value.nodeName);
 				for (attribute in value.attributes()) {
 				for (attribute in value.attributes()) {
 					write(" " + attribute + "=\"");
 					write(" " + attribute + "=\"");
-					write(value.get(attribute));
+					write(StringTools.htmlEscape(value.get(attribute), true));
 					write("\"");
 					write("\"");
 				}
 				}
 				if (hasChildren(value)) {
 				if (hasChildren(value)) {
@@ -84,15 +84,15 @@ class Printer {
 					write("/>");
 					write("/>");
 					newline();
 					newline();
 				}
 				}
-			case Xml.PCData:
+			case PCData:
 				var nodeValue:String = value.nodeValue;
 				var nodeValue:String = value.nodeValue;
 				if (nodeValue.length != 0) {
 				if (nodeValue.length != 0) {
-					write(tabs + nodeValue);
+					write(tabs + StringTools.htmlEscape(nodeValue));
 					newline();
 					newline();
 				}
 				}
-			case Xml.ProcessingInstruction:
+			case ProcessingInstruction:
 				write("<?" + value.nodeValue + "?>");
 				write("<?" + value.nodeValue + "?>");
-			case Xml.DocType:
+			case DocType:
 				write("<!DOCTYPE " + value.nodeValue + ">");
 				write("<!DOCTYPE " + value.nodeValue + ">");
 		}
 		}
 	}
 	}
@@ -116,6 +116,7 @@ class Printer {
 					if (StringTools.ltrim(child.nodeValue).length != 0) {
 					if (StringTools.ltrim(child.nodeValue).length != 0) {
 						return true;
 						return true;
 					}
 					}
+				case _:
 			}
 			}
 		}
 		}
 		return false;
 		return false;

+ 0 - 345
std/java/_std/Xml.hx

@@ -1,345 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-@:native("_Xml.RealXmlType")
-extern enum XmlType {
-}
-
-private enum RealXmlType {
-        Element;
-        PCData;
-        CData;
-        Comment;
-        DocType;
-        ProcessingInstruction;
-        Document;
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-
-	var _nodeName : String;
-	var _nodeValue : String;
-	var _attributes : haxe.ds.StringMap<String>;
-	var _children : Array<Xml>;
-	var _parent : Xml;
-
-	public static function parse( str : String ) : Xml {
-		return haxe.xml.Parser.parse(str);
-	}
-
-	private function new() : Void {
-	}
-
-	public static function createElement( name : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Element;
-		r._children = new Array();
-		r._attributes = new haxe.ds.StringMap();
-		r.set_nodeName( name );
-		return r;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.PCData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.CData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createComment( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Comment;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.DocType;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.ProcessingInstruction;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	private function get_parent() : Xml {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.get( att );
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.set( att, value );
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.remove( att );
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.exists( att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.keys();
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = this._children;
-		return {
-			hasNext : function(){
-				return cur < x.length;
-			},
-			next : function(){
-				return x[cur++];
-			}
-		}
-	}
-
-	public function elements() : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = _children;
-		return untyped {
-			hasNext : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					if( x[k].nodeType == Xml.Element )
-						break;
-					k += 1;
-				}
-				cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					k += 1;
-					if( n.nodeType == Xml.Element ) {
-						cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if ( _children == null ) throw "bad nodetype";
-		var x = _children;
-		var cur = 0;
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					if( n.nodeType == Xml.Element && n._nodeName == name )
-						break;
-					k++;
-				}
-				cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					k++;
-					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function firstChild() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		return _children[0];
-	}
-
-	public function firstElement() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var l = _children.length;
-		while( cur < l ) {
-			var n = _children[cur];
-			if( n.nodeType == Xml.Element )
-				return n;
-			cur++;
-		}
-		return null;
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( _children == null ) throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b )
-			x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-	}
-
-	public function toString() : String {
-		if( nodeType == Xml.PCData )
-			return StringTools.htmlEscape(_nodeValue);
-		if( nodeType == Xml.CData )
-			return "<![CDATA["+_nodeValue+"]]>";
-		if( nodeType == Xml.Comment )
-			return "<!--"+_nodeValue+"-->";
-		if( nodeType == Xml.DocType )
-			return "<!DOCTYPE "+_nodeValue+">";
-		if( nodeType == Xml.ProcessingInstruction )
-			return "<?"+_nodeValue+"?>";
-		var s = new StringBuf();
-
-		if( nodeType == Xml.Element ) {
-			s.add("<");
-			s.add(_nodeName);
-			for( k in _attributes.keys() ){
-				s.add(" ");
-				s.add(k);
-				s.add("=\"");
-				s.add(_attributes.get(k));
-				s.add("\"");
-			}
-			if( _children.length == 0 ) {
-				s.add("/>");
-				return s.toString();
-			}
-			s.add(">");
-		}
-
-		for( x in iterator() )
-			s.add(x.toString());
-
-		if( nodeType == Xml.Element ) {
-			s.add("</");
-			s.add(_nodeName);
-			s.add(">");
-		}
-		return s.toString();
-	}
-
-	static function __init__() : Void untyped {
-		Xml.Element = cast RealXmlType.Element;
-		Xml.PCData = cast RealXmlType.PCData;
-		Xml.CData = cast RealXmlType.CData;
-		Xml.Comment = cast RealXmlType.Comment;
-		Xml.DocType = cast RealXmlType.DocType;
-		Xml.ProcessingInstruction = cast RealXmlType.ProcessingInstruction;
-		Xml.Document = cast RealXmlType.Document;
-	}
-
-}

+ 0 - 332
std/js/_std/Xml.hx

@@ -1,332 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-enum XmlType {
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-
-	var _nodeName : String;
-	var _nodeValue : String;
-	var _attributes : haxe.ds.StringMap<String>;
-	var _children : Array<Xml>;
-	var _parent : Xml;
-
-	public static function parse( str : String ) : Xml {
-		return haxe.xml.Parser.parse(str);
-	}
-
-	private function new() : Void {
-	}
-
-	public static function createElement( name : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Element;
-		r._children = new Array();
-		r._attributes = new haxe.ds.StringMap();
-		r.set_nodeName( name );
-		return r;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.PCData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.CData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createComment( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Comment;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.DocType;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.ProcessingInstruction;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	private function get_parent() : Xml {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.get( att );
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.set( att, value );
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.remove( att );
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.exists( att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.keys();
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function(){
-				return __this__.cur < __this__.x.length;
-			},
-			next : function(){
-				return __this__.x[__this__.cur++];
-			}
-		}
-	}
-
-	public function elements() : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
-				while( k < l ) {
-					if( __this__.x[k].nodeType == Xml.Element )
-						break;
-					k += 1;
-				}
-				__this__.cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
-				while( k < l ) {
-					var n = __this__.x[k];
-					k += 1;
-					if( n.nodeType == Xml.Element ) {
-						__this__.cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
-				while( k < l ) {
-					var n = __this__.x[k];
-					if( n.nodeType == Xml.Element && n._nodeName == name )
-						break;
-					k++;
-				}
-				__this__.cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
-				while( k < l ) {
-					var n = __this__.x[k];
-					k++;
-					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						__this__.cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function firstChild() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		return _children[0];
-	}
-
-	public function firstElement() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var l = _children.length;
-		while( cur < l ) {
-			var n = _children[cur];
-			if( n.nodeType == Xml.Element )
-				return n;
-			cur++;
-		}
-		return null;
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( _children == null ) throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b )
-			x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-	}
-
-	public function toString() : String {
-		if( nodeType == Xml.PCData )
-			return StringTools.htmlEscape(_nodeValue);
-		if( nodeType == Xml.CData )
-			return "<![CDATA["+_nodeValue+"]]>";
-		if( nodeType == Xml.Comment )
-			return "<!--"+_nodeValue+"-->";
-		if( nodeType == Xml.DocType )
-			return "<!DOCTYPE "+_nodeValue+">";
-		if( nodeType == Xml.ProcessingInstruction )
-			return "<?"+_nodeValue+"?>";
-		var s = new StringBuf();
-
-		if( nodeType == Xml.Element ) {
-			s.add("<");
-			s.add(_nodeName);
-			for( k in _attributes.keys() ){
-				s.add(" ");
-				s.add(k);
-				s.add("=\"");
-				s.add(_attributes.get(k));
-				s.add("\"");
-			}
-			if( _children.length == 0 ) {
-				s.add("/>");
-				return s.toString();
-			}
-			s.add(">");
-		}
-
-		for( x in iterator() )
-			s.add(x.toString());
-
-		if( nodeType == Xml.Element ) {
-			s.add("</");
-			s.add(_nodeName);
-			s.add(">");
-		}
-		return s.toString();
-	}
-
-	static function __init__() : Void untyped {
-		Xml.Element = "element";
-		Xml.PCData = "pcdata";
-		Xml.CData = "cdata";
-		Xml.Comment = "comment";
-		Xml.DocType = "doctype";
-		Xml.ProcessingInstruction = "processingInstruction";
-		Xml.Document = "document";
-	}
-
-}

+ 0 - 423
std/neko/_std/Xml.hx

@@ -1,423 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-enum XmlType {
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-	public var nodeType(default,null) : XmlType;
-
-	private var _nodeName : String;
-	private var _nodeValue : String;
-	private var _attributes : Dynamic<String>;
-	private var _children : Array<Xml>;
-	private var _parent : Xml;
-
-	private function new() : Void {
-	}
-
-	private static var _parse = neko.Lib.load("std","parse_xml",2);
-
-	public static function parse( str : String ) : Xml {
-		var x = new Xml();
-		x._children = new Array();
-		var parser = {
-			cur : x,
-			add : function(x:Dynamic) {
-				untyped __this__.cur._children.push(x);
-			},
-			xml : function(name,att) {
-				var x : Dynamic = new Xml();
-				x._parent = untyped __this__.cur;
-				x.nodeType = Xml.Element;
-				x._nodeName = new String(name);
-				x._attributes = att;
-				x._children = new Array();
-				untyped {
-					var f = __dollar__objfields(att);
-					var i = 0;
-					var l = __dollar__asize(f);
-					while( i < l ) {
-						__dollar__objset(att,f[i], new String(__dollar__objget(att,f[i]))) ;
-						i++;
-					}
-					__this__.add(x);
-					__this__.cur = x;
-				}
-			},
-			cdata : function(text) {
-				var x : Dynamic = new Xml();
-				x._parent = untyped __this__.cur;
-				x.nodeType = Xml.CData;
-				x._nodeValue = new String(text);
-				untyped __this__.add(x);
-			},
-			pcdata : function(text) {
-				var x : Dynamic = new Xml();
-				x._parent = untyped __this__.cur;
-				x.nodeType = Xml.PCData;
-				x._nodeValue = new String(text);
-				untyped __this__.add(x);
-			},
-			comment : function(text) {
-				var x : Dynamic = new Xml();
-				x._parent = untyped __this__.cur;
-				if( untyped __dollar__sget(text,0) == 63 ) {
-					x.nodeType = Xml.ProcessingInstruction;
-					text = new String(text);
-					text = text.substr(1,text.length - 2);
-				} else {
-					x.nodeType = Xml.Comment;
-					text = new String(text);
-				}
-				x._nodeValue = text;
-				untyped __this__.add(x);
-			},
-			doctype : function(text) {
-				var x : Dynamic = new Xml();
-				x._parent = untyped __this__.cur;
-				x.nodeType = Xml.DocType;
-				x._nodeValue = new String(text).substr(1);
-				var p : Xml = untyped __this__.cur;
-				p.addChild(x);
-			},
-			done : function() {
-				untyped __this__.cur = __this__.cur._parent;
-			}
-		};
-		untyped _parse(str.__s,parser);
-		x.nodeType = Xml.Document;
-		return x;
-	}
-
-
-	public static function createElement( name : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Element;
-		r._nodeName = name;
-		r._attributes = untyped __dollar__new(null);
-		r._children = new Array();
-		return r;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.PCData;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.CData;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createComment( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Comment;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.DocType;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.ProcessingInstruction;
-		r._nodeValue = data;
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	private function get_parent() : Xml {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.field( _attributes, att );
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		Reflect.setField (_attributes, att, value );
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		Reflect.deleteField( _attributes, att );
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.hasField( _attributes, att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return Reflect.fields( _attributes ).iterator();
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if( _children == null )
-			throw "bad nodetype";
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function(){
-				return __this__.cur < __this__.x.length;
-			},
-			next : function(){
-				return __this__.x[__this__.cur++];
-			}
-		}
-	}
-
-
-	public function elements() : Iterator<Xml> {
-		if( _children == null )
-			throw "bad nodetype";
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
-				while( k < l ) {
-					if( __this__.x[k].nodeType == Xml.Element )
-						break;
-					k += 1;
-				}
-				__this__.cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
-				while( k < l ) {
-					var n = __this__.x[k];
-					k += 1;
-					if( n.nodeType == Xml.Element ) {
-						__this__.cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( _children == null )
-			throw "bad nodetype";
-		return untyped {
-			cur: 0,
-			x: this._children,
-			hasNext : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
-				while( k < l ) {
-					var n = __this__.x[k];
-					if( n.nodeType == Xml.Element && n._nodeName == name )
-						break;
-					k++;
-				}
-				__this__.cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = __this__.cur;
-				var l = __this__.x.length;
-				while( k < l ) {
-					var n = __this__.x[k];
-					k++;
-					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						__this__.cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function firstChild() : Xml {
-		if( _children == null )
-			throw "bad nodetype";
-		return _children[0];
-	}
-
-	public function firstElement() : Xml {
-		if( _children == null )
-			throw "bad nodetype";
-		for( cur in 0..._children.length ) {
-			var n = _children[cur];
-			if( n.nodeType == Xml.Element )
-				return n;
-		}
-		return null;
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( _children == null )
-			throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( _children == null )
-			throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b ) x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( _children == null )
-			throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-	}
-
-	public function toString() : String {
-		var s = new StringBuf();
-		toStringRec(s);
-		return s.toString();
-	}
-
-	function toStringRec(s: StringBuf) : Void {
-		switch( nodeType ) {
-		case Xml.Document:
-			for( x in _children )
-				x.toStringRec(s);
-		case Xml.Element:
-			s.addChar("<".code);
-			s.add(_nodeName);
-			for( k in Reflect.fields(_attributes) ) {
-				s.addChar(" ".code);
-				s.add(k);
-				s.addChar("=".code);
-				s.addChar("\"".code);
-				s.add(Reflect.field(_attributes,k));
-				s.addChar("\"".code);
-			}
-			if( _children.length == 0 ) {
-				s.addChar("/".code);
-				s.addChar(">".code);
-				return;
-			}
-			s.addChar(">".code);
-			for( x in _children )
-				x.toStringRec(s);
-			s.addChar("<".code);
-			s.addChar("/".code);
-			s.add(_nodeName);
-			s.addChar(">".code);
-		case Xml.PCData:
-			s.add(StringTools.htmlEscape(_nodeValue));
-		case Xml.CData:
-			s.add("<![CDATA[");
-			s.add(_nodeValue);
-			s.add("]]>");
-		case Xml.Comment:
-			s.add("<!--");
-			s.add(_nodeValue);
-			s.add("-->");
-		case Xml.DocType:
-			s.add("<!DOCTYPE ");
-			s.add(_nodeValue);
-			s.add(">");
-		case Xml.ProcessingInstruction:
-			s.add("<?");
-			s.add(_nodeValue);
-			s.add("?>");
-		}
-	}
-
-	static function __init__() : Void untyped {
-		Xml.Element = "element";
-		Xml.PCData = "pcdata";
-		Xml.CData = "cdata";
-		Xml.Comment = "comment";
-		Xml.DocType = "doctype";
-		Xml.ProcessingInstruction = "processingInstruction";
-		Xml.Document = "document";
-	}
-
-}

+ 0 - 360
std/php/_std/Xml.hx

@@ -1,360 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-import php.Lib;
-
-enum XmlType {
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-
-	var _nodeName : String;
-	var _nodeValue : String;
-	var _attributes : haxe.ds.StringMap<String>;
-	var _children : Array<Xml>;
-	var _parent : Xml;
-	var _fromCustomParser:Bool;
-
-	private static var build : Xml;
-	private static function __start_element_handler(parser : Dynamic, name : String, attribs : ArrayAccess<String>) : Void {
-		var node = createElement(name);
-		untyped __php__("foreach($attribs as $k => $v) $node->set($k, $v)");
-		build.addChild(node);
-		build = node;
-	}
-
-	private static function __end_element_handler(parser : Dynamic, name : String) : Void {
-		build = build.parent;
-	}
-
-	private static function __decodeattr(value : String) : String
-	{
-		return untyped __call__("str_replace", "'", '&apos;', __call__("htmlspecialchars", value, __php__('ENT_COMPAT'), 'UTF-8'));
-	}
-
-	private static function __decodeent(value : String) : String
-	{
-		return untyped __call__("str_replace", "'", '&apos;', __call__("htmlentities", value, __php__('ENT_COMPAT'), 'UTF-8'));
-	}
-
-	private static function __character_data_handler(parser : Dynamic, data : String) : Void {
-		var d = __decodeent(data);
-		if ((untyped __call__("strlen", data) == 1 && d != data) || d == data) {
-			var last = build._children[build._children.length - 1];
-			if (null != last && last.nodeType == Xml.PCData)
-			{
-				last.nodeValue += d;
-			} else
-				build.addChild(createPCData(d));
-		} else {
-			build.addChild(createCData(data));
-		}
-	}
-
-	private static function __default_handler(parser : Dynamic, data : String) : Void {
-		//On some PHP setups (seems to happen when libexpat is used) we may get called for such "entities" although character_data will correctly be called afterward.
-		if(data == "<![CDATA[")
-			return;
-		if(data == "]]>")
-			return;
-		if ("<!--" == data.substr(0, 4))
-			build.addChild(createComment(data.substr(4, data.length-7)));
-		else
-			build.addChild(createPCData(data));
-	}
-
-	static var reHeader = ~/\s*(?:<\?(.+?)\?>)?(?:<!DOCTYPE ([^>]+)>)?/mi;
-
-	public static function parse( str : String ) : Xml {
-		build = createDocument();
-		var xml_parser = untyped __call__("xml_parser_create");
-		untyped __call__("xml_set_element_handler", xml_parser, __start_element_handler, __end_element_handler);
-		untyped __call__("xml_set_character_data_handler", xml_parser, __character_data_handler);
-		untyped __call__("xml_set_default_handler", xml_parser, __default_handler);
-		untyped __call__("xml_parser_set_option", xml_parser, __php__("XML_OPTION_CASE_FOLDING"), 0);
-		untyped __call__("xml_parser_set_option", xml_parser, __php__("XML_OPTION_SKIP_WHITE"), 0);
-
-		reHeader.match(str);
-
-		str = "<doc>"+reHeader.matchedRight()+"</doc>";
-
-		if(1 != untyped __call__("xml_parse", xml_parser, str, true)) {
-			throw "Xml parse error ("+untyped __call__("xml_error_string", __call__("xml_get_error_code", xml_parser)) + ") line #" + __call__("xml_get_current_line_number", xml_parser);
-		}
-
-		untyped __call__("xml_parser_free", xml_parser);
-
-		build = build._children[0];
-		build._parent = null;
-		build._nodeName = null;
-		build.nodeType = Document;
-
-		var doctype = reHeader.matched(2);
-		if (null != doctype)
-			build.insertChild(createDocType(doctype), 0);
-
-		var ProcessingInstruction = reHeader.matched(1);
-		if (null != ProcessingInstruction)
-			build.insertChild(createProcessingInstruction(ProcessingInstruction), 0);
-
-		return build;
-	}
-
-	private function new(fromCustomParser:Bool = false) : Void {
-		_fromCustomParser = fromCustomParser;
-	}
-
-	@:allow(haxe.xml.Parser)
-	static function createPCDataFromCustomParser( data : String ) : Xml {
-		var r = new Xml(true);
-		r.nodeType = Xml.PCData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createElement( name : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Element;
-		r._children = new Array();
-		r._attributes = new haxe.ds.StringMap();
-		r.set_nodeName( name );
-		return r;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.PCData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.CData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createComment( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Comment;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.DocType;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.ProcessingInstruction;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	private inline function get_parent() : Xml {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.get( att );
-	}
-
-	// TODO: check correct transform function
-	@:ifFeature("Xml.parse")
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.set( att, __decodeattr(value) );
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.remove( att );
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.exists( att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.keys();
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		return _children.iterator();
-	}
-
-	public function elements() : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		return Lambda.filter(_children, function(child) return child.nodeType == Xml.Element).iterator();
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		return Lambda.filter(_children, function(child) return child.nodeType == Xml.Element && child.nodeName == name).iterator();
-	}
-
-	public function firstChild() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		if( _children.length == 0 ) return null;
-		return _children[0];
-	}
-
-	public function firstElement() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		for (child in _children)
-			if (child.nodeType == Xml.Element)
-				return child;
-		return null;
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( _children == null ) throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b )
-			x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-	}
-
-	public function toString() : String {
-		if( nodeType == Xml.PCData )
-			return _fromCustomParser ? StringTools.htmlEscape(_nodeValue) : _nodeValue;
-
-		var s = "";
-
-		if( nodeType == Xml.Element ) {
-			s += "<";
-			s += _nodeName;
-			for( k in _attributes.keys() ){
-				s += " ";
-				s += k;
-				s += "=\""; // \"
-				s += _attributes.get(k);
-				s += "\""; // \"
-			}
-			if( _children.length == 0 ) {
-				s += "/>";
-				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.ProcessingInstruction )
-			return "<?"+_nodeValue+"?>";
-
-
-		for( x in iterator() )
-			s += x.toString();
-
-		if( nodeType == Xml.Element ) {
-			s += "</";
-			s += _nodeName;
-			s += ">";
-		}
-		return s;
-	}
-
-	static function __init__() : Void untyped {
-		Xml.Element = "element";
-		Xml.PCData = "pcdata";
-		Xml.CData = "cdata";
-		Xml.Comment = "comment";
-		Xml.DocType = "doctype";
-		Xml.ProcessingInstruction = "processingInstruction";
-		Xml.Document = "document";
-	}
-
-}

+ 0 - 335
std/python/_std/Xml.hx

@@ -1,335 +0,0 @@
-/*
- * Copyright (C)2005-2012 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-enum XmlType {
-}
-
-@:coreApi class Xml {
-
-	public static var Element(default,null) : XmlType;
-	public static var PCData(default,null) : XmlType;
-	public static var CData(default,null) : XmlType;
-	public static var Comment(default,null) : XmlType;
-	public static var DocType(default,null) : XmlType;
-	public static var ProcessingInstruction(default,null) : XmlType;
-	public static var Document(default,null) : XmlType;
-
-	public var nodeType(default,null) : XmlType;
-	public var nodeName(get,set) : String;
-	public var nodeValue(get,set) : String;
-	public var parent(get,null) : Xml;
-
-	var _nodeName : String;
-	var _nodeValue : String;
-	var _attributes : haxe.ds.StringMap<String>;
-	var _children : Array<Xml>;
-	var _parent : Xml;
-
-	public static function parse( str : String ) : Xml {
-		return haxe.xml.Parser.parse(str);
-	}
-
-	private function new() : Void {
-	}
-
-	public static function createElement( name : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Element;
-		r._children = new Array();
-		r._attributes = new haxe.ds.StringMap();
-		r.set_nodeName( name );
-		return r;
-	}
-
-	public static function createPCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.PCData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createCData( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.CData;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createComment( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Comment;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocType( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.DocType;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createProcessingInstruction( data : String ) : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.ProcessingInstruction;
-		r.set_nodeValue( data );
-		return r;
-	}
-
-	public static function createDocument() : Xml {
-		var r = new Xml();
-		r.nodeType = Xml.Document;
-		r._children = new Array();
-		return r;
-	}
-
-	private function get_nodeName() : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName;
-	}
-
-	private function set_nodeName( n : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _nodeName = n;
-	}
-
-	private function get_nodeValue() : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue;
-	}
-
-	private function set_nodeValue( v : String ) : String {
-		if( nodeType == Xml.Element || nodeType == Xml.Document )
-			throw "bad nodeType";
-		return _nodeValue = v;
-	}
-
-	private function get_parent() : Xml {
-		return _parent;
-	}
-
-	public function get( att : String ) : String {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.get( att );
-	}
-
-	public function set( att : String, value : String ) : Void {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.set( att, value );
-	}
-
-	public function remove( att : String ) : Void{
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		_attributes.remove( att );
-	}
-
-	public function exists( att : String ) : Bool {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.exists( att );
-	}
-
-	public function attributes() : Iterator<String> {
-		if( nodeType != Xml.Element )
-			throw "bad nodeType";
-		return _attributes.keys();
-	}
-
-	public function iterator() : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = this._children;
-		return {
-
-			hasNext : function(){
-				return cur < x.length;
-			},
-			next : function(){
-				return x[cur++];
-			}
-		}
-	}
-
-	public function elements() : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = this._children;
-		return {
-
-			hasNext : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					if( x[k].nodeType == Xml.Element )
-						break;
-					k += 1;
-				}
-				cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					k += 1;
-					if( n.nodeType == Xml.Element ) {
-						cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function elementsNamed( name : String ) : Iterator<Xml> {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var x = this._children;
-		return {
-
-			hasNext : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					if( n.nodeType == Xml.Element && n._nodeName == name )
-						break;
-					k++;
-				}
-				cur = k;
-				return k < l;
-			},
-			next : function() {
-				var k = cur;
-				var l = x.length;
-				while( k < l ) {
-					var n = x[k];
-					k++;
-					if( n.nodeType == Xml.Element && n._nodeName == name ) {
-						cur = k;
-						return n;
-					}
-				}
-				return null;
-			}
-		}
-	}
-
-	public function firstChild() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		return _children[0];
-	}
-
-	public function firstElement() : Xml {
-		if( _children == null ) throw "bad nodetype";
-		var cur = 0;
-		var l = _children.length;
-		while( cur < l ) {
-			var n = _children[cur];
-			if( n.nodeType == Xml.Element )
-				return n;
-			cur++;
-		}
-		return null;
-	}
-
-	public function addChild( x : Xml ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.push( x );
-	}
-
-	public function removeChild( x : Xml ) : Bool {
-		if( _children == null ) throw "bad nodetype";
-		var b = _children.remove( x );
-		if( b )
-			x._parent = null;
-		return b;
-	}
-
-	public function insertChild( x : Xml, pos : Int ) : Void {
-		if( _children == null ) throw "bad nodetype";
-		if( x._parent != null ) x._parent._children.remove(x);
-		x._parent = this;
-		_children.insert( pos, x );
-	}
-
-	public function toString() : String {
-		if( nodeType == Xml.PCData )
-			return StringTools.htmlEscape(_nodeValue);
-		if( nodeType == Xml.CData )
-			return "<![CDATA["+_nodeValue+"]]>";
-		if( nodeType == Xml.Comment )
-			return "<!--"+_nodeValue+"-->";
-		if( nodeType == Xml.DocType )
-			return "<!DOCTYPE "+_nodeValue+">";
-		if( nodeType == Xml.ProcessingInstruction )
-			return "<?"+_nodeValue+"?>";
-		var s = new StringBuf();
-
-		if( nodeType == Xml.Element ) {
-			s.add("<");
-			s.add(_nodeName);
-			for( k in _attributes.keys() ){
-				s.add(" ");
-				s.add(k);
-				s.add("=\"");
-				s.add(_attributes.get(k));
-				s.add("\"");
-			}
-			if( _children.length == 0 ) {
-				s.add("/>");
-				return s.toString();
-			}
-			s.add(">");
-		}
-
-		for( x in iterator() )
-			s.add(x.toString());
-
-		if( nodeType == Xml.Element ) {
-			s.add("</");
-			s.add(_nodeName);
-			s.add(">");
-		}
-		return s.toString();
-	}
-
-	static function __init__() : Void {
-		Xml.Element = cast "element";
-		Xml.PCData = cast "pcdata";
-		Xml.CData = cast "cdata";
-		Xml.Comment = cast "comment";
-		Xml.DocType = cast "doctype";
-		Xml.ProcessingInstruction = cast "processingInstruction";
-		Xml.Document = cast "document";
-	}
-
-}

+ 40 - 57
tests/unit/src/unit/TestXML.hx

@@ -47,22 +47,9 @@ class TestXML extends Test {
 	}
 	}
 
 
 	function testFormat() {
 	function testFormat() {
-		#if flash8
-		// flash8 does not parse CDATA sections as PCDATA...
-		eq( Xml.parse("<a><b><c/> <d/> \n <e/><![CDATA[<x>]]></b></a>").toString(), "<a><b><c/> <d/> \n <e/>&lt;x&gt;</b></a>" );
-		#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>" );
 		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 || php)
-		eq( Xml.parse('"').toString(), '&quot;' ); // flash8 has bad habits of escaping entities
-		#else
 		eq( Xml.parse('"').toString(), '"' );
 		eq( Xml.parse('"').toString(), '"' );
-		#end
-/*		#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;' );
-		#end*/
+		//eq( Xml.parse('&quot; &lt; &gt;').toString(), '&quot; &lt; &gt;' );
 	}
 	}
 
 
 	function testComplex() {
 	function testComplex() {
@@ -73,19 +60,10 @@ class TestXML extends Test {
 		var comment = '<!--Comment-->';
 		var comment = '<!--Comment-->';
 		var xml = '<html><body><![CDATA[<a href="CDATA"/>&lt;]]></body></html>';
 		var xml = '<html><body><![CDATA[<a href="CDATA"/>&lt;]]></body></html>';
 
 
-		#if !flash8
-
 		var x = Xml.parse(header + doctype + comment + xml);
 		var x = Xml.parse(header + doctype + comment + xml);
-
-		#if flash
-		// doctype is well parsed but is not present in the parsed Xml (f8 and f9)
-		doctype = '';
-		#end
-
 		eq( x.toString(), header + doctype + comment + xml);
 		eq( x.toString(), header + doctype + comment + xml);
 
 
 		return; // too hard for him
 		return; // too hard for him
-		#end
 	}
 	}
 
 
 	function testWhitespaces() {
 	function testWhitespaces() {
@@ -104,13 +82,8 @@ class TestXML extends Test {
 		var a = el.next();
 		var a = el.next();
 		eq( a.firstChild().nodeValue, " ");
 		eq( a.firstChild().nodeValue, " ");
 		var b = el.next();
 		var b = el.next();
-		#if (flash || php)
-		eq( b.firstChild(), null);
-		eq( x.toString().split("\n").join("\\n"), '<a> </a><b/> \\n <c/>' );
-		#else
 		eq( b.firstChild().nodeValue, "");
 		eq( b.firstChild().nodeValue, "");
 		eq( x.toString().split("\n").join("\\n"), '<a> </a><b></b> \\n <c/>' );
 		eq( x.toString().split("\n").join("\\n"), '<a> </a><b></b> \\n <c/>' );
-		#end
 		var c = el.next();
 		var c = el.next();
 		eq( c.firstChild(), null);
 		eq( c.firstChild(), null);
 	}
 	}
@@ -118,20 +91,12 @@ class TestXML extends Test {
 	function testCreate() {
 	function testCreate() {
 		eq( Xml.createDocument().toString(), "");
 		eq( Xml.createDocument().toString(), "");
 		eq( Xml.createPCData("Hello").toString(), "Hello" );
 		eq( Xml.createPCData("Hello").toString(), "Hello" );
-		#if !flash8
-		// too hard for him
 
 
 		eq( Xml.createCData("<x>").toString(), "<![CDATA[<x>]]>" );
 		eq( Xml.createCData("<x>").toString(), "<![CDATA[<x>]]>" );
 		eq( Xml.createComment("Hello").toString(), "<!--Hello-->" );
 		eq( Xml.createComment("Hello").toString(), "<!--Hello-->" );
 
 
-		#if flash9
-		eq( Xml.createProcessingInstruction("XHTML").toString(), "<?XHTML ?>");
-		// doctype is parsed but not printed
-		eq( Xml.createDocType("XHTML").toString(), "" );
-		#else
 		eq( Xml.createProcessingInstruction("XHTML").toString(), "<?XHTML?>");
 		eq( Xml.createProcessingInstruction("XHTML").toString(), "<?XHTML?>");
 		eq( Xml.createDocType("XHTML").toString(), "<!DOCTYPE XHTML>" );
 		eq( Xml.createDocType("XHTML").toString(), "<!DOCTYPE XHTML>" );
-		#end
 
 
 		eq( Xml.parse("<!--Hello-->").firstChild().nodeValue, "Hello" );
 		eq( Xml.parse("<!--Hello-->").firstChild().nodeValue, "Hello" );
 		var c = Xml.createComment("Hello");
 		var c = Xml.createComment("Hello");
@@ -148,7 +113,6 @@ class TestXML extends Test {
 		eq( Xml.createPCData("Hello").nodeValue, "Hello" );
 		eq( Xml.createPCData("Hello").nodeValue, "Hello" );
 
 
 		return;
 		return;
-		#end
 	}
 	}
 
 
 	function testNS() {
 	function testNS() {
@@ -179,7 +143,7 @@ class TestXML extends Test {
 	function testNodetype() {
 	function testNodetype() {
 		var element = Xml.createElement("x");
 		var element = Xml.createElement("x");
 
 
-		var l = [Xml.createPCData("x"), Xml.createCData("x"), Xml.createDocType("x"), Xml.createProcessingInstruction("x") #if !flash8, Xml.createComment("x") #end];
+		var l = [Xml.createPCData("x"), Xml.createCData("x"), Xml.createDocType("x"), Xml.createProcessingInstruction("x")];
 		for (xml in l)
 		for (xml in l)
 		{
 		{
 			exc(function() xml.firstChild());
 			exc(function() xml.firstChild());
@@ -195,25 +159,7 @@ class TestXML extends Test {
 
 
 	function testEntities() {
 	function testEntities() {
 		var entities = ["&lt;", "&gt;", "&quot;", "&amp;", "&apos;", "&nbsp;", "&euro;", "&#64;", "&#244;", "&#x3F;", "&#xFF;"];
 		var entities = ["&lt;", "&gt;", "&quot;", "&amp;", "&apos;", "&nbsp;", "&euro;", "&#64;", "&#244;", "&#x3F;", "&#xFF;"];
-		var values = entities.copy();
-		#if (flash || js || cs || java || python)
-		// flash parser does support XML + some HTML entities (nbsp only ?) + character codes entities
-		values = ['<', '>', '"', '&', "'", String.fromCharCode(160), '&euro;', '@', 'ô', '?', 'ÿ'];
-		#end
-
-		#if flash9
-		// for a very strange reason, flash9 uses a non standard charcode for non breaking space
-		values[5] = String.fromCharCode(65440);
-		#end
-
-		#if php
-		// &nbsp; and &euro; creates an invalid entity error (first time I see PHP being strict !)
-		entities[5] = "x";
-		entities[6] = "x";
-		// character codes entities are supported
-		values = ["&lt;", "&gt;", "&quot;", "&amp;", "&apos;", "x", "x", '@', 'ô', '?', 'ÿ'];
-		#end
-
+		var values = ['<', '>', '"', '&', "'", "&nbsp;", '&euro;', '@', String.fromCharCode(244), '?', String.fromCharCode(0xFF)];
 		for( i in 0...entities.length ) {
 		for( i in 0...entities.length ) {
 			infos(entities[i]);
 			infos(entities[i]);
 			eq( Xml.parse(entities[i]).firstChild().nodeValue, values[i] );
 			eq( Xml.parse(entities[i]).firstChild().nodeValue, values[i] );
@@ -242,4 +188,41 @@ class TestXML extends Test {
 
 
 		eq(doc.toString(), "<i>I<a>A</a></i>");
 		eq(doc.toString(), "<i>I<a>A</a></i>");
 	}
 	}
+
+	function testIssue2299() {
+		var xml = Xml.parse("<xml>Hä?</xml>");
+		eq('<xml>Hä?</xml>', xml.firstElement().toString());
+		eq('Hä?', xml.firstElement().firstChild().nodeValue);
+	}
+
+	function testIssue2739() {
+		var simpleContent = "My &amp; &lt;You&gt;";
+		var node1 = Xml.parse(simpleContent).firstChild();
+		eq( node1.toString(), simpleContent );
+
+		// TODO?
+		//var content2 = "&laquo;&#64;&raquo;";
+		//var node3 = Xml.parse(content2).firstChild();
+		//eq( node3.toString(), content2 );
+	}
+
+	function testIssue3058() {
+        var xml = Xml.createElement("node");
+        xml.set("key", 'a"b\'&c>d<e');
+        eq('a"b\'&c>d<e', xml.get("key"));
+        eq('<node key="a&quot;b&#039;&amp;c&gt;d&lt;e"/>', xml.toString());
+	}
+
+	function testIssue3630() {
+		exc(function() Xml.parse("<node attribute='<'/>"));
+		exc(function() Xml.parse("<node attribute='>'/>"));
+
+		var a = Xml.parse('<node attribute="something with &lt; &amp; &quot; &apos; special characters &gt;"/>');
+		var c = a.firstChild();
+		eq('something with < & " \' special characters >', c.get("attribute"));
+
+		var a = Xml.parse('<div e="event=Hit.Eject&#x0D;&#x0A;&quot;onHit"></div>');
+		var c = a.firstChild();
+		eq('event=Hit.Eject\r\n"onHit', c.get("e"));
+	}
 }
 }

+ 4 - 8
tests/unit/src/unit/issues/Issue3725.hx

@@ -5,8 +5,6 @@ class Issue3725 extends Test {
 
 
 	static function myStaticArgs(stringValue = "foo", intValue = 12, intHexValue = 0xFFFFFF, floatValue = 12.2223, boolValue = true) { }
 	static function myStaticArgs(stringValue = "foo", intValue = 12, intHexValue = 0xFFFFFF, floatValue = 12.2223, boolValue = true) { }
 
 
-	#if !php
-
 	function testStaticArgs() {
 	function testStaticArgs() {
 		var rtti = haxe.rtti.Rtti.getRtti(Issue3725);
 		var rtti = haxe.rtti.Rtti.getRtti(Issue3725);
 		var valueMap = new Map();
 		var valueMap = new Map();
@@ -21,7 +19,7 @@ class Issue3725 extends Test {
 				}
 				}
 			}
 			}
 		}
 		}
-		eq("'foo'", valueMap["stringValue"]);
+		eq('"foo"', valueMap["stringValue"]);
 		eq("12", valueMap["intValue"]);
 		eq("12", valueMap["intValue"]);
 		eq("0xFFFFFF", valueMap["intHexValue"]);
 		eq("0xFFFFFF", valueMap["intHexValue"]);
 		eq("12.2223", valueMap["floatValue"]);
 		eq("12.2223", valueMap["floatValue"]);
@@ -40,7 +38,7 @@ class Issue3725 extends Test {
 		for (cf in rtti.statics) {
 		for (cf in rtti.statics) {
 			valueMap[cf.name] = cf.expr;
 			valueMap[cf.name] = cf.expr;
 		}
 		}
-		eq("'foo'", valueMap["stringValue"]);
+		eq('"foo"', valueMap["stringValue"]);
 		eq("12", valueMap["intValue"]);
 		eq("12", valueMap["intValue"]);
 		eq("0xFFFFFF", valueMap["intHexValue"]);
 		eq("0xFFFFFF", valueMap["intHexValue"]);
 		eq("12.2223", valueMap["floatValue"]);
 		eq("12.2223", valueMap["floatValue"]);
@@ -63,7 +61,7 @@ class Issue3725 extends Test {
 				}
 				}
 			}
 			}
 		}
 		}
-		eq("'foo'", valueMap["stringValue"]);
+		eq('"foo"', valueMap["stringValue"]);
 		eq("12", valueMap["intValue"]);
 		eq("12", valueMap["intValue"]);
 		eq("0xFFFFFF", valueMap["intHexValue"]);
 		eq("0xFFFFFF", valueMap["intHexValue"]);
 		eq("12.2223", valueMap["floatValue"]);
 		eq("12.2223", valueMap["floatValue"]);
@@ -82,12 +80,10 @@ class Issue3725 extends Test {
 		for (cf in rtti.fields) {
 		for (cf in rtti.fields) {
 			valueMap[cf.name] = cf.expr;
 			valueMap[cf.name] = cf.expr;
 		}
 		}
-		eq("'foo'", valueMap["stringValueM"]);
+		eq('"foo"', valueMap["stringValueM"]);
 		eq("12", valueMap["intValueM"]);
 		eq("12", valueMap["intValueM"]);
 		eq("0xFFFFFF", valueMap["intHexValueM"]);
 		eq("0xFFFFFF", valueMap["intHexValueM"]);
 		eq("12.2223", valueMap["floatValueM"]);
 		eq("12.2223", valueMap["floatValueM"]);
 		eq("true", valueMap["boolValueM"]);
 		eq("true", valueMap["boolValueM"]);
 	}
 	}
-
-	#end
 }
 }