import php.Lib; /* * Copyright (c) 2005, The haXe Project Contributors * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */ enum XmlType { } @:core_api 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 Prolog(default,null) : XmlType; public static var Document(default,null) : XmlType; public var nodeType(default,null) : XmlType; public var nodeName(getNodeName,setNodeName) : String; public var nodeValue(getNodeValue,setNodeValue) : String; public var parent(getParent,null) : Xml; var _nodeName : String; var _nodeValue : String; var _attributes : Hash; var _children : Array; var _parent : Xml; private static var build : Xml; private static function __start_element_handler(parser : Dynamic, name : String, attribs : ArrayAccess) : 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.getParent(); } private static function __decodeattr(value : String) : String { return untyped __call__("str_replace", "'", ''', __call__("htmlspecialchars", value, __php__('ENT_COMPAT'), 'UTF-8')); } private static function __decodeent(value : String) : String { return untyped __call__("str_replace", "'", ''', __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 == "") return; if (""; else if( nodeType == Xml.DocType ) return ""; else if ( nodeType == Xml.Prolog ) return ""; for( x in iterator() ) s += x.toString(); if( nodeType == Xml.Element ) { s += ""; } return s; } static function __init__() : Void untyped { Xml.Element = "element"; Xml.PCData = "pcdata"; Xml.CData = "cdata"; Xml.Comment = "comment"; Xml.DocType = "doctype"; Xml.Prolog = "prolog"; Xml.Document = "document"; } }