Simon Krajewski před 10 roky
rodič
revize
e4a1fb51e8

+ 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 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 =
 	DynArray.add ctx.code op;
 	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)
 	in
 	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
 	match op with
 	| OpAssign ->
@@ -1721,8 +1708,8 @@ and jump_expr_gen ctx e jif jfun =
 			jfun (if jif then t else f)
 		in
 		(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
 		| OpGte -> j J3Gte J3NotGte
 		| OpLt -> j J3Lt J3NotLt

+ 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
  * 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
  * 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(String) {
+	var Element = "element";
+	var PCData = "pcdata";
+	var CData = "cdata";
+	var Comment = "comment";
+	var DocType = "doctype";
+	var ProcessingInstruction = "processinginstruction";
+	var Document = "document";
 }
 
-/**
-	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.
 	**/
-	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.
 	**/
-	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.
 	**/
-	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.
 	**/
-	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.
 	**/
-	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.
 		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.
 		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.
 		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.
 		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.
 	**/
-	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.
 		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.
 		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.
 		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.
 	**/
-	function firstChild() : Xml;
+	public inline function firstChild() : Xml {
+		ensureElementType();
+		return children[0];
+	}
 
 	/**
 		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.
 		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.
 		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.
 	**/
-	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.
 	**/
-	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
-	}
-
-}

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

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

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

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