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