LexicalHandler.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // LexicalHandler.h
  3. //
  4. // Library: XML
  5. // Package: SAX
  6. // Module: SAX
  7. //
  8. // SAX2-ext LexicalHandler 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_LexicalHandler_INCLUDED
  16. #define SAX_LexicalHandler_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/XML/XMLString.h"
  19. namespace Poco {
  20. namespace XML {
  21. class XML_API LexicalHandler
  22. /// This is an optional extension handler for SAX2 to provide lexical information
  23. /// about an XML document, such as comments and CDATA section boundaries.
  24. /// XML readers are not required to recognize this handler, and it is not part of
  25. /// core-only SAX2 distributions.
  26. ///
  27. /// The events in the lexical handler apply to the entire document, not just to the
  28. /// document element, and all lexical handler events must appear between the content
  29. /// handler's startDocument and endDocument events.
  30. ///
  31. /// To set the LexicalHandler for an XML reader, use the setProperty method with the
  32. /// property name http://xml.org/sax/properties/lexical-handler and an object implementing
  33. /// this interface (or null) as the value. If the reader does not report lexical events,
  34. /// it will throw a SAXNotRecognizedException when you attempt to register the handler.
  35. {
  36. public:
  37. virtual void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId) = 0;
  38. /// Report the start of DTD declarations, if any.
  39. ///
  40. /// This method is intended to report the beginning of the DOCTYPE declaration;
  41. /// if the document has no DOCTYPE declaration, this method will not be invoked.
  42. ///
  43. /// All declarations reported through DTDHandler or DeclHandler events must appear
  44. /// between the startDTD and endDTD events. Declarations are assumed to belong to
  45. /// the internal DTD subset unless they appear between startEntity and endEntity
  46. /// events. Comments and processing instructions from the DTD should also be reported
  47. /// between the startDTD and endDTD events, in their original order of (logical) occurrence;
  48. /// they are not required to appear in their correct locations relative to DTDHandler or
  49. /// DeclHandler events, however.
  50. ///
  51. /// Note that the start/endDTD events will appear within the start/endDocument events from
  52. /// ContentHandler and before the first startElement event.
  53. virtual void endDTD() = 0;
  54. /// Report the end of DTD declarations.
  55. ///
  56. /// This method is intended to report the end of the DOCTYPE declaration; if the document
  57. /// has no DOCTYPE declaration, this method will not be invoked.
  58. virtual void startEntity(const XMLString& name) = 0;
  59. /// Report the beginning of some internal and external XML entities.
  60. ///
  61. /// The reporting of parameter entities (including the external DTD subset) is optional,
  62. /// and SAX2 drivers that report LexicalHandler events may not implement it; you can use the
  63. /// http://xml.org/sax/features/lexical-handler/parameter-entities feature to query or control
  64. /// the reporting of parameter entities.
  65. ///
  66. /// General entities are reported with their regular names, parameter entities have '%'
  67. /// prepended to their names, and the external DTD subset has the pseudo-entity name "[dtd]".
  68. ///
  69. /// When a SAX2 driver is providing these events, all other events must be properly nested
  70. /// within start/end entity events. There is no additional requirement that events from
  71. /// DeclHandler or DTDHandler be properly ordered.
  72. ///
  73. /// Note that skipped entities will be reported through the skippedEntity event, which is part of
  74. /// the ContentHandler interface.
  75. ///
  76. /// Because of the streaming event model that SAX uses, some entity boundaries cannot be reported under
  77. /// any circumstances:
  78. ///
  79. /// * general entities within attribute values
  80. /// * parameter entities within declarations
  81. ///
  82. /// These will be silently expanded, with no indication of where the original entity boundaries were.
  83. ///
  84. /// Note also that the boundaries of character references (which are not really entities anyway) are not reported.
  85. ///
  86. /// All start/endEntity events must be properly nested.
  87. virtual void endEntity(const XMLString& name) = 0;
  88. /// Report the end of an entity.
  89. virtual void startCDATA() = 0;
  90. /// Report the start of a CDATA section.
  91. ///
  92. /// The contents of the CDATA section will be reported through the regular characters event;
  93. /// this event is intended only to report the boundary.
  94. virtual void endCDATA() = 0;
  95. /// Report the end of a CDATA section.
  96. virtual void comment(const XMLChar ch[], int start, int length) = 0;
  97. /// Report an XML comment anywhere in the document.
  98. ///
  99. /// This callback will be used for comments inside or outside the document element,
  100. /// including comments in the external DTD subset (if read). Comments in the DTD must
  101. /// be properly nested inside start/endDTD and start/endEntity events (if used).
  102. protected:
  103. virtual ~LexicalHandler();
  104. };
  105. } } // namespace Poco::XML
  106. #endif // SAX_LexicalHandler_INCLUDED