Xml.hx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright (c) 2005, The haXe Project Contributors
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * - Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * - Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  20. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  23. * DAMAGE.
  24. */
  25. /**
  26. An abstract type representing the type of the Xml
  27. Node. You can compare it to [Xml] statics and can
  28. use [Std.string(t)] to get a string reprensation
  29. of the type.
  30. **/
  31. enum XmlType {
  32. }
  33. /**
  34. The standard Xml class and parsing.
  35. More API to manipulate XML are available in the [haxe.xml] package.
  36. **/
  37. extern class Xml {
  38. /**
  39. A type of Xml node.
  40. **/
  41. static var Element(default,null) : XmlType;
  42. /**
  43. A type of Xml node.
  44. **/
  45. static var PCData(default,null) : XmlType;
  46. /**
  47. A type of Xml node.
  48. **/
  49. static var CData(default,null) : XmlType;
  50. /**
  51. A type of Xml node.
  52. **/
  53. static var Comment(default,null) : XmlType;
  54. /**
  55. A type of Xml node.
  56. **/
  57. static var DocType(default,null) : XmlType;
  58. /**
  59. A type of Xml node.
  60. **/
  61. static var Prolog(default,null) : XmlType;
  62. /**
  63. A type of Xml node.
  64. **/
  65. static var Document(default,null) : XmlType;
  66. /**
  67. Parse a String into an Xml object.
  68. **/
  69. static function parse( str : String ) : Xml;
  70. /**
  71. Creates a node of the given type.
  72. **/
  73. static function createElement( name : String ) : Xml;
  74. /**
  75. Creates a node of the given type.
  76. **/
  77. static function createPCData( data : String ) : Xml;
  78. /**
  79. Creates a node of the given type.
  80. **/
  81. static function createCData( data : String ) : Xml;
  82. /**
  83. Creates a node of the given type.
  84. **/
  85. static function createComment( data : String ) : Xml;
  86. /**
  87. Creates a node of the given type.
  88. **/
  89. static function createDocType( data : String ) : Xml;
  90. /**
  91. Creates a node of the given type.
  92. **/
  93. static function createProlog( data : String ) : Xml;
  94. /**
  95. Creates a node of the given type.
  96. **/
  97. static function createDocument() : Xml;
  98. /**
  99. Returns the type of the Xml Node. This should be used before
  100. accessing other functions since some might raise an exception
  101. if the node type is not correct.
  102. **/
  103. var nodeType(default,null) : XmlType;
  104. /**
  105. Returns the node name of an Element.
  106. **/
  107. var nodeName(getNodeName,setNodeName) : String;
  108. private function getNodeName() : String;
  109. private function setNodeName( name : String ) : String;
  110. /**
  111. Returns the node value. Only works if the Xml node is not an Element or a Document.
  112. **/
  113. var nodeValue(getNodeValue,setNodeValue) : String;
  114. private function getNodeValue() : String;
  115. private function setNodeValue( name : String ) : String;
  116. /**
  117. Get the given attribute of an Element node. Returns [null] if not found.
  118. Attributes are case-sensitive.
  119. **/
  120. function get( att : String ) : String; // check case insensitivy
  121. /**
  122. Set the given attribute value for an Element node.
  123. Attributes are case-sensitive.
  124. **/
  125. function set( att : String, value : String ) : Void;
  126. /**
  127. Removes an attribute for an Element node.
  128. Attributes are case-sensitive.
  129. **/
  130. function remove( att : String ) : Void;
  131. /**
  132. Tells if the Element node has a given attribute.
  133. Attributes are case-sensitive.
  134. **/
  135. function exists( att : String ) : Bool;
  136. /**
  137. Returns an [Iterator] on all the attributes values.
  138. **/
  139. function attributes() : Iterator<String>;
  140. /**
  141. Returns the parent object in the Xml hierarchy.
  142. The parent can be [null], an Element or a Document.
  143. **/
  144. var parent(getParent,null) : Xml;
  145. private function getParent() : Xml;
  146. /**
  147. Returns an iterator of all child nodes.
  148. Only works if the current node is an Element or a Document.
  149. **/
  150. function iterator() : Iterator<Xml>;
  151. /**
  152. Returns an iterator of all child nodes which are Elements.
  153. Only works if the current node is an Element or a Document.
  154. **/
  155. function elements() : Iterator<Xml>;
  156. /**
  157. Returns an iterator of all child nodes which are Elements with the given nodeName.
  158. Only works if the current node is an Element or a Document.
  159. **/
  160. function elementsNamed( name : String ) : Iterator<Xml>;
  161. /**
  162. Returns the first child node.
  163. **/
  164. function firstChild() : Xml;
  165. /**
  166. Returns the first child node which is an Element.
  167. **/
  168. function firstElement() : Xml;
  169. /**
  170. Adds a child node to the Document or Element.
  171. One node can only be inside one given node which is indicated by the [parent] property.
  172. **/
  173. function addChild( x : Xml ) : Void;
  174. /**
  175. Removes a child from the Document or Element.
  176. Returns true if the child was successfuly removed.
  177. **/
  178. function removeChild( x : Xml ) : Bool;
  179. /**
  180. Inserts a child at the given position among the other childs.
  181. **/
  182. function insertChild( x : Xml, pos : Int ) : Void;
  183. /**
  184. Returns a String representation of the Xml node.
  185. **/
  186. function toString() : String;
  187. }