DOMParser.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // DOMParser.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: DOMParser
  7. //
  8. // Definition of the DOMParser class.
  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 DOM_DOMParser_INCLUDED
  16. #define DOM_DOMParser_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/SAX/SAXParser.h"
  19. namespace Poco {
  20. namespace XML {
  21. class NamePool;
  22. class Document;
  23. class InputSource;
  24. class EntityResolver;
  25. class XML_API DOMParser
  26. /// This is a convenience class that combines a
  27. /// DOMBuilder with a SAXParser, with the optional
  28. /// support of a WhitespaceFilter.
  29. {
  30. public:
  31. explicit DOMParser(NamePool* pNamePool = 0);
  32. /// Creates a new DOMParser.
  33. /// If a NamePool is given, it becomes the Document's NamePool.
  34. explicit DOMParser(unsigned long namePoolSize);
  35. /// Creates a new DOMParser, using the given NamePool size.
  36. ///
  37. /// The given namePoolSize should be a suitable prime number,
  38. /// e.g. 251, 509, 1021 or 4093, depending on the expected
  39. /// size of the document.
  40. ~DOMParser();
  41. /// Destroys the DOMParser.
  42. void setEncoding(const XMLString& encoding);
  43. /// Sets the encoding used by the parser if no
  44. /// encoding is specified in the XML document.
  45. const XMLString& getEncoding() const;
  46. /// Returns the name of the encoding used by
  47. /// the parser if no encoding is specified in
  48. /// the XML document.
  49. void addEncoding(const XMLString& name, Poco::TextEncoding* pEncoding);
  50. /// Adds an encoding to the parser.
  51. void setFeature(const XMLString& name, bool state);
  52. /// Set the state of a feature.
  53. ///
  54. /// If a feature is not recognized by the DOMParser, it is
  55. /// passed on to the underlying XMLReader.
  56. ///
  57. /// The only currently supported feature is
  58. /// http://www.appinf.com/features/no-whitespace-in-element-content
  59. /// which, when activated, causes the WhitespaceFilter to
  60. /// be used.
  61. bool getFeature(const XMLString& name) const;
  62. /// Look up the value of a feature.
  63. ///
  64. /// If a feature is not recognized by the DOMParser, the
  65. /// DOMParser queries the underlying SAXParser for the feature.
  66. Document* parse(const XMLString& uri);
  67. /// Parse an XML document from a location identified by an URI.
  68. Document* parse(InputSource* pInputSource);
  69. /// Parse an XML document from a location identified by an InputSource.
  70. Document* parseString(const std::string& xml);
  71. /// Parse an XML document from a string.
  72. Document* parseMemory(const char* xml, std::size_t size);
  73. /// Parse an XML document from memory.
  74. EntityResolver* getEntityResolver() const;
  75. /// Returns the entity resolver used by the underlying SAXParser.
  76. void setEntityResolver(EntityResolver* pEntityResolver);
  77. /// Sets the entity resolver on the underlying SAXParser.
  78. static const XMLString FEATURE_FILTER_WHITESPACE;
  79. private:
  80. SAXParser _saxParser;
  81. NamePool* _pNamePool;
  82. bool _filterWhitespace;
  83. };
  84. } } // namespace Poco::XML
  85. #endif // DOM_DOMParser_INCLUDED