XMLStreamReader.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* XMLStreamReader.java --
  2. Copyright (C) 2005,2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.xml.stream;
  32. import javax.xml.namespace.NamespaceContext;
  33. import javax.xml.namespace.QName;
  34. /**
  35. * Interface implemented by an XML parser.
  36. */
  37. public interface XMLStreamReader
  38. extends XMLStreamConstants
  39. {
  40. /**
  41. * Returns the implementation-specific feature or property of the given
  42. * name.
  43. */
  44. Object getProperty(String name)
  45. throws IllegalArgumentException;
  46. /**
  47. * Returns the next parsing event.
  48. */
  49. int next()
  50. throws XMLStreamException;
  51. /**
  52. * Tests whether the current event is of the given type and namespace.
  53. * @exception XMLStreamException if the test fails
  54. */
  55. void require(int type, String namespaceURI, String localName)
  56. throws XMLStreamException;
  57. /**
  58. * Returns the text content of a text-only element.
  59. * When invoked, the current event must be START_ELEMENT.
  60. * On completion, the current event will be END_ELEMENT.
  61. */
  62. String getElementText()
  63. throws XMLStreamException;
  64. /**
  65. * Skips any ignorable whitespace, comments, and processing instructions
  66. * until a START_ELEMENT or END_ELEMENT event is encountered.
  67. * @exception XMLStreamException if an event of any other type is
  68. * encountered
  69. */
  70. int nextTag()
  71. throws XMLStreamException;
  72. /**
  73. * Indicates whether there are any remaining events to be read.
  74. */
  75. boolean hasNext()
  76. throws XMLStreamException;
  77. /**
  78. * Frees any resources used by this parser.
  79. * This method will not close the underlying input source.
  80. */
  81. void close()
  82. throws XMLStreamException;
  83. /**
  84. * Returns the namespace URI for the given prefix.
  85. */
  86. String getNamespaceURI(String prefix);
  87. /**
  88. * Indicates whether the current event is START_ELEMENT.
  89. */
  90. boolean isStartElement();
  91. /**
  92. * Indicates whether the current event is END_ELEMENT.
  93. */
  94. boolean isEndElement();
  95. /**
  96. * Indicates whether the current event is character data.
  97. */
  98. boolean isCharacters();
  99. /**
  100. * Indicates whether the current event is ignorable whitespace.
  101. */
  102. boolean isWhiteSpace();
  103. /**
  104. * Returns the normalized attribute value for the given attribute.
  105. */
  106. String getAttributeValue(String namespaceURI, String localName);
  107. /**
  108. * Returns the number of attributes on this element.
  109. * This method can only be invoked on a START_ELEMENT event.
  110. */
  111. int getAttributeCount();
  112. /**
  113. * Returns the QName of the attribute at the given index.
  114. */
  115. QName getAttributeName(int index);
  116. /**
  117. * Returns the namespace URI of the attribute at the given index.
  118. */
  119. String getAttributeNamespace(int index);
  120. /**
  121. * Returns the local-name of the attribute at the given index.
  122. */
  123. String getAttributeLocalName(int index);
  124. /**
  125. * Returns the namespace prefix of the attribute at the given index.
  126. */
  127. String getAttributePrefix(int index);
  128. /**
  129. * Returns the type of the attribute at the specified index.
  130. */
  131. String getAttributeType(int index);
  132. /**
  133. * Returns the normalized value of the attribute at the given index.
  134. */
  135. String getAttributeValue(int index);
  136. /**
  137. * Indicates whether the attribute at the given index was specified in the
  138. * underlying XML source or created by default.
  139. */
  140. boolean isAttributeSpecified(int index);
  141. /**
  142. * Returns the number of namespaces declared on this event.
  143. * This method is only valid on a START_ELEMENT, END_ELEMENT, or NAMESPACE
  144. * event.
  145. */
  146. int getNamespaceCount();
  147. /**
  148. * Returns the prefix of the namespace at the given index, or null if this
  149. * is the default namespace declaration.
  150. */
  151. String getNamespacePrefix(int index);
  152. /**
  153. * Returns the URI of the namespace at the given index.
  154. */
  155. String getNamespaceURI(int index);
  156. /**
  157. * Returns the namespace context for the current position.
  158. */
  159. NamespaceContext getNamespaceContext();
  160. /**
  161. * Returns the type of the current event.
  162. */
  163. int getEventType();
  164. /**
  165. * Returns the string value of the current event.
  166. */
  167. String getText();
  168. /**
  169. * Returns the string value of the current event as a character array.
  170. */
  171. char[] getTextCharacters();
  172. /**
  173. * Copies the string value of the current event into the specified
  174. * character array.
  175. */
  176. int getTextCharacters(int sourceStart, char[] target,
  177. int targetStart, int length)
  178. throws XMLStreamException;
  179. /**
  180. * Returns the offset of the first character in the text character array.
  181. */
  182. int getTextStart();
  183. /**
  184. * Returns the length of the characters in the text character array.
  185. */
  186. int getTextLength();
  187. /**
  188. * Returns the input encoding.
  189. */
  190. String getEncoding();
  191. /**
  192. * Indicates whether the current event has text.
  193. */
  194. boolean hasText();
  195. /**
  196. * Returns the current location of the parser cursor in the underlying
  197. * input source.
  198. */
  199. Location getLocation();
  200. /**
  201. * Returns the QName of the current element.
  202. * This method is only valid on a START_ELEMENT or END_ELEMENT event.
  203. */
  204. QName getName();
  205. /**
  206. * Returns the local-name of the current element.
  207. */
  208. String getLocalName();
  209. /**
  210. * Indicates whether the current event has a name.
  211. */
  212. boolean hasName();
  213. /**
  214. * Returns the namespace URI of the current element.
  215. */
  216. String getNamespaceURI();
  217. /**
  218. * Returns the namespace prefix of the current element.
  219. */
  220. String getPrefix();
  221. /**
  222. * Returns the XML version declared in the XML declaration.
  223. */
  224. String getVersion();
  225. /**
  226. * Returns the standalone flag declared in the XML declaration.
  227. */
  228. boolean isStandalone();
  229. /**
  230. * Indicates whether the standalone flag was set in the document.
  231. */
  232. boolean standaloneSet();
  233. /**
  234. * Returns the encoding declared in the XML declaration.
  235. */
  236. String getCharacterEncodingScheme();
  237. /**
  238. * Returns the target of the current processing instruction event.
  239. */
  240. String getPITarget();
  241. /**
  242. * Returns the data of the current processing instruction event.
  243. */
  244. String getPIData();
  245. }