XMLReader.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // XMLReader.h
  3. //
  4. // Library: XML
  5. // Package: SAX
  6. // Module: SAX
  7. //
  8. // SAX2 XMLReader Interface.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef SAX_XMLReader_INCLUDED
  16. #define SAX_XMLReader_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/XML/XMLString.h"
  19. namespace Poco {
  20. namespace XML {
  21. class EntityResolver;
  22. class DTDHandler;
  23. class ContentHandler;
  24. class ErrorHandler;
  25. class InputSource;
  26. class LexicalHandler;
  27. class NamespaceHandler;
  28. class XML_API XMLReader
  29. /// Interface for reading an XML document using callbacks.
  30. /// XMLReader is the interface that an XML parser's SAX2 driver must
  31. /// implement. This interface allows an application to set and
  32. /// query features and properties in the parser, to register event handlers
  33. /// for document processing, and to initiate a document parse.
  34. /// All SAX interfaces are assumed to be synchronous: the parse methods must not
  35. /// return until parsing is complete, and readers
  36. /// must wait for an event-handler callback to return before reporting the next event.
  37. {
  38. public:
  39. virtual void setEntityResolver(EntityResolver* pResolver) = 0;
  40. /// Allow an application to register an entity resolver.
  41. ///
  42. /// If the application does not register an entity resolver, the
  43. /// XMLReader will perform its own default resolution.
  44. ///
  45. /// Applications may register a new or different resolver in the middle of a
  46. /// parse, and the SAX parser must begin using the new resolver immediately.
  47. virtual EntityResolver* getEntityResolver() const = 0;
  48. /// Return the current entity resolver.
  49. virtual void setDTDHandler(DTDHandler* pDTDHandler) = 0;
  50. /// Allow an application to register a DTD event handler.
  51. ///
  52. /// If the application does not register a DTD handler, all DTD events reported by
  53. /// the SAX parser will be silently ignored.
  54. ///
  55. /// Applications may register a new or different handler in the middle of a parse,
  56. /// and the SAX parser must begin using the new handler immediately.
  57. virtual DTDHandler* getDTDHandler() const = 0;
  58. /// Return the current DTD handler.
  59. virtual void setContentHandler(ContentHandler* pContentHandler) = 0;
  60. /// Allow an application to register a content event handler.
  61. ///
  62. /// If the application does not register a content handler, all content events
  63. /// reported by the SAX parser will be silently ignored.
  64. ///
  65. /// Applications may register a new or different handler in the middle of a parse,
  66. /// and the SAX parser must begin using the new handler immediately.
  67. virtual ContentHandler* getContentHandler() const = 0;
  68. /// Return the current content handler.
  69. virtual void setErrorHandler(ErrorHandler* pErrorHandler) = 0;
  70. /// Allow an application to register an error event handler.
  71. ///
  72. /// If the application does not register an error handler, all error events reported by
  73. /// the SAX parser will be silently ignored; however, normal processing may not continue.
  74. /// It is highly recommended that all SAX applications implement an error handler to avoid
  75. /// unexpected bugs.
  76. ///
  77. /// Applications may register a new or different handler in the middle of a parse, and the
  78. /// SAX parser must begin using the new handler immediately.
  79. virtual ErrorHandler* getErrorHandler() const = 0;
  80. /// Return the current error handler.
  81. virtual void setFeature(const XMLString& featureId, bool state) = 0;
  82. /// Set the state of a feature.
  83. ///
  84. /// The feature name is any fully-qualified URI. It is possible for an XMLReader to
  85. /// expose a feature value but to be unable to change the current value. Some feature
  86. /// values may be immutable or mutable only in specific contexts, such as before, during,
  87. /// or after a parse.
  88. ///
  89. /// All XMLReaders are required to support setting http://xml.org/sax/features/namespaces
  90. /// to true and http://xml.org/sax/features/namespace-prefixes to false.
  91. virtual bool getFeature(const XMLString& featureId) const = 0;
  92. /// Look up the value of a feature.
  93. ///
  94. /// The feature name is any fully-qualified URI. It is possible for an XMLReader
  95. /// to recognize a feature name but temporarily be unable to return its value.
  96. /// Some feature values may be available only in specific contexts, such as before,
  97. /// during, or after a parse. Also, some feature values may not be programmatically
  98. /// accessible. (In the case of an adapter for SAX1 Parser, there is no
  99. /// implementation-independent way to expose whether the underlying parser is performing
  100. /// validation, expanding external entities, and so forth.)
  101. ///
  102. /// All XMLReaders are required to recognize the
  103. /// http://xml.org/sax/features/namespaces and the
  104. /// http://xml.org/sax/features/namespace-prefixes feature names.
  105. /// Implementors are free (and encouraged) to invent their own features,
  106. /// using names built on their own URIs.
  107. virtual void setProperty(const XMLString& propertyId, const XMLString& value) = 0;
  108. /// Set the value of a property.
  109. ///
  110. /// The property name is any fully-qualified URI. It is possible for an XMLReader
  111. /// to recognize a property name but to be unable to change the current value.
  112. /// Some property values may be immutable or mutable only in specific contexts,
  113. /// such as before, during, or after a parse.
  114. ///
  115. /// XMLReaders are not required to recognize setting any specific property names, though a
  116. /// core set is defined by SAX2.
  117. ///
  118. /// This method is also the standard mechanism for setting extended handlers.
  119. virtual void setProperty(const XMLString& propertyId, void* value) = 0;
  120. /// Set the value of a property.
  121. /// See also setProperty(const XMLString&, const XMLString&).
  122. virtual void* getProperty(const XMLString& propertyId) const = 0;
  123. /// Look up the value of a property.
  124. /// String values are returned as XMLChar*
  125. /// The property name is any fully-qualified URI. It is possible for an XMLReader to
  126. /// recognize a property name but temporarily be unable to return its value. Some property
  127. /// values may be available only in specific contexts, such as before, during, or after a parse.
  128. ///
  129. /// XMLReaders are not required to recognize any specific property names, though an initial
  130. /// core set is documented for SAX2.
  131. ///
  132. /// Implementors are free (and encouraged) to invent their own properties, using names
  133. /// built on their own URIs.
  134. virtual void parse(InputSource* pSource) = 0;
  135. /// Parse an XML document.
  136. ///
  137. /// The application can use this method to instruct the XML reader to begin parsing an
  138. /// XML document from any valid input source (a character stream, a byte stream, or a URI).
  139. ///
  140. /// Applications may not invoke this method while a parse is in progress (they should create
  141. /// a new XMLReader instead for each nested XML document). Once a parse is complete, an
  142. /// application may reuse the same XMLReader object, possibly with a different input source.
  143. /// Configuration of the XMLReader object (such as handler bindings and values established for
  144. /// feature flags and properties) is unchanged by completion of a parse, unless the definition of that
  145. /// aspect of the configuration explicitly specifies other behavior. (For example, feature flags or
  146. /// properties exposing characteristics of the document being parsed.)
  147. ///
  148. /// During the parse, the XMLReader will provide information about the XML document through the registered
  149. /// event handlers.
  150. ///
  151. /// This method is synchronous: it will not return until parsing has ended. If a client application
  152. /// wants to terminate parsing early, it should throw an exception.
  153. virtual void parse(const XMLString& systemId) = 0;
  154. /// Parse an XML document from a system identifier.
  155. /// See also parse(InputSource*).
  156. virtual void parseMemoryNP(const char* xml, std::size_t size) = 0;
  157. /// Parse an XML document from memory.
  158. /// See also parse(InputSource*).
  159. // SAX Features
  160. static const XMLString FEATURE_VALIDATION;
  161. static const XMLString FEATURE_NAMESPACES;
  162. static const XMLString FEATURE_NAMESPACE_PREFIXES;
  163. static const XMLString FEATURE_EXTERNAL_GENERAL_ENTITIES;
  164. static const XMLString FEATURE_EXTERNAL_PARAMETER_ENTITIES;
  165. static const XMLString FEATURE_STRING_INTERNING;
  166. // SAX Properties
  167. static const XMLString PROPERTY_DECLARATION_HANDLER;
  168. static const XMLString PROPERTY_LEXICAL_HANDLER;
  169. protected:
  170. virtual ~XMLReader();
  171. };
  172. } } // namespace Poco::XML
  173. #endif // SAX_XMLReader_INCLUDED