2
0

Xml.hx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (C)2005-2012 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. /**
  23. An abstract type representing the type of the Xml
  24. Node. You can compare it to [Xml] statics and can
  25. use [Std.string(t)] to get a string reprensation
  26. of the type.
  27. **/
  28. enum XmlType {
  29. }
  30. /**
  31. The standard Xml class and parsing.
  32. More API to manipulate XML are available in the [haxe.xml] package.
  33. **/
  34. extern class Xml {
  35. /**
  36. A type of Xml node.
  37. **/
  38. static var Element(default,null) : XmlType;
  39. /**
  40. A type of Xml node.
  41. **/
  42. static var PCData(default,null) : XmlType;
  43. /**
  44. A type of Xml node.
  45. **/
  46. static var CData(default,null) : XmlType;
  47. /**
  48. A type of Xml node.
  49. **/
  50. static var Comment(default,null) : XmlType;
  51. /**
  52. A type of Xml node.
  53. **/
  54. static var DocType(default,null) : XmlType;
  55. /**
  56. A type of Xml node.
  57. **/
  58. static var ProcessingInstruction(default,null) : XmlType;
  59. /**
  60. A type of Xml node.
  61. **/
  62. static var Document(default,null) : XmlType;
  63. /**
  64. Parse a String into an Xml object.
  65. **/
  66. static function parse( str : String ) : Xml;
  67. /**
  68. Creates a node of the given type.
  69. **/
  70. static function createElement( name : String ) : Xml;
  71. /**
  72. Creates a node of the given type.
  73. **/
  74. static function createPCData( data : String ) : Xml;
  75. /**
  76. Creates a node of the given type.
  77. **/
  78. static function createCData( data : String ) : Xml;
  79. /**
  80. Creates a node of the given type.
  81. **/
  82. static function createComment( data : String ) : Xml;
  83. /**
  84. Creates a node of the given type.
  85. **/
  86. static function createDocType( data : String ) : Xml;
  87. /**
  88. Creates a node of the given type.
  89. **/
  90. static function createProcessingInstruction( data : String ) : Xml;
  91. /**
  92. Creates a node of the given type.
  93. **/
  94. static function createDocument() : Xml;
  95. /**
  96. Returns the type of the Xml Node. This should be used before
  97. accessing other functions since some might raise an exception
  98. if the node type is not correct.
  99. **/
  100. var nodeType(default,null) : XmlType;
  101. /**
  102. Returns the node name of an Element.
  103. **/
  104. var nodeName(get,set) : String;
  105. /**
  106. Returns the node value. Only works if the Xml node is not an Element or a Document.
  107. **/
  108. var nodeValue(get,set) : String;
  109. /**
  110. Get the given attribute of an Element node. Returns [null] if not found.
  111. Attributes are case-sensitive.
  112. **/
  113. function get( att : String ) : String; // check case insensitivy
  114. /**
  115. Set the given attribute value for an Element node.
  116. Attributes are case-sensitive.
  117. **/
  118. function set( att : String, value : String ) : Void;
  119. /**
  120. Removes an attribute for an Element node.
  121. Attributes are case-sensitive.
  122. **/
  123. function remove( att : String ) : Void;
  124. /**
  125. Tells if the Element node has a given attribute.
  126. Attributes are case-sensitive.
  127. **/
  128. function exists( att : String ) : Bool;
  129. /**
  130. Returns an [Iterator] on all the attribute names.
  131. **/
  132. function attributes() : Iterator<String>;
  133. /**
  134. Returns the parent object in the Xml hierarchy.
  135. The parent can be [null], an Element or a Document.
  136. **/
  137. var parent(get,null) : Xml;
  138. /**
  139. Returns an iterator of all child nodes.
  140. Only works if the current node is an Element or a Document.
  141. **/
  142. function iterator() : Iterator<Xml>;
  143. /**
  144. Returns an iterator of all child nodes which are Elements.
  145. Only works if the current node is an Element or a Document.
  146. **/
  147. function elements() : Iterator<Xml>;
  148. /**
  149. Returns an iterator of all child nodes which are Elements with the given nodeName.
  150. Only works if the current node is an Element or a Document.
  151. **/
  152. function elementsNamed( name : String ) : Iterator<Xml>;
  153. /**
  154. Returns the first child node.
  155. **/
  156. function firstChild() : Xml;
  157. /**
  158. Returns the first child node which is an Element.
  159. **/
  160. function firstElement() : Xml;
  161. /**
  162. Adds a child node to the Document or Element.
  163. One node can only be inside one given node which is indicated by the [parent] property.
  164. **/
  165. function addChild( x : Xml ) : Void;
  166. /**
  167. Removes a child from the Document or Element.
  168. Returns true if the child was successfuly removed.
  169. **/
  170. function removeChild( x : Xml ) : Bool;
  171. /**
  172. Inserts a child at the given position among the other childs.
  173. **/
  174. function insertChild( x : Xml, pos : Int ) : Void;
  175. /**
  176. Returns a String representation of the Xml node.
  177. **/
  178. function toString() : String;
  179. }