root / CCV-HAND / libs / poco / include / Poco / DOM / DOMBuilder.h @ 59

View | Annotate | Download (4.6 KB)

1
//
2
// DOMBuilder.h
3
//
4
// $Id: //poco/1.3/XML/include/Poco/DOM/DOMBuilder.h#2 $
5
//
6
// Library: XML
7
// Package: DOM
8
// Module:  DOMBuilder
9
//
10
// Definition of the DOMBuilder class.
11
//
12
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13
// and Contributors.
14
//
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
21
// 
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
28
// 
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
36
//
37
38
39
#ifndef DOM_DOMBuilder_INCLUDED
40
#define DOM_DOMBuilder_INCLUDED
41
42
43
#include "Poco/XML/XML.h"
44
#include "Poco/SAX/ContentHandler.h"
45
#include "Poco/SAX/LexicalHandler.h"
46
#include "Poco/SAX/DTDHandler.h"
47
#include "Poco/XML/XMLString.h"
48
49
50
namespace Poco {
51
namespace XML {
52
53
54
class XMLReader;
55
class Document;
56
class InputSource;
57
class AbstractNode;
58
class AbstractContainerNode;
59
class NamePool;
60
61
62
class XML_API DOMBuilder: protected DTDHandler, protected ContentHandler, protected LexicalHandler
63
        /// This class builds a tree representation of an
64
        /// XML document, according to the W3C Document Object Model, Level 1 and 2
65
        /// specifications.
66
        ///
67
        /// The actual XML parsing is done by an XMLReader, which
68
        /// must be supplied to the DOMBuilder.
69
{
70
public:
71
        DOMBuilder(XMLReader& xmlReader, NamePool* pNamePool = 0);
72
                /// Creates a DOMBuilder using the given XMLReader. 
73
                /// If a NamePool is given, it becomes the Document's NamePool.
74
75
        virtual ~DOMBuilder();
76
                /// Destroys the DOMBuilder.
77
78
        virtual Document* parse(const XMLString& uri);
79
                /// Parse an XML document from a location identified by an URI.
80
81
        virtual Document* parse(InputSource* pInputSource);
82
                /// Parse an XML document from a location identified by an InputSource.
83
84
        virtual Document* parseMemoryNP(const char* xml, std::size_t size);
85
                /// Parses an XML document from memory.
86
87
protected:
88
        // DTDHandler
89
        void notationDecl(const XMLString& name, const XMLString* publicId, const XMLString* systemId);
90
        void unparsedEntityDecl(const XMLString& name, const XMLString* publicId, const XMLString& systemId, const XMLString& notationName);
91
92
        // ContentHandler
93
        void setDocumentLocator(const Locator* loc);
94
        void startDocument();
95
        void endDocument();
96
        void startElement(const XMLString& uri, const XMLString& localName, const XMLString& qname, const Attributes& attributes);
97
        void endElement(const XMLString& uri, const XMLString& localName, const XMLString& qname);
98
        void characters(const XMLChar ch[], int start, int length);
99
        void ignorableWhitespace(const XMLChar ch[], int start, int length);
100
        void processingInstruction(const XMLString& target, const XMLString& data);
101
        void startPrefixMapping(const XMLString& prefix, const XMLString& uri);
102
        void endPrefixMapping(const XMLString& prefix);
103
        void skippedEntity(const XMLString& name);
104
105
        // LexicalHandler
106
        void startDTD(const XMLString& name, const XMLString& publicId, const XMLString& systemId);
107
        void endDTD();
108
        void startEntity(const XMLString& name);
109
        void endEntity(const XMLString& name);
110
        void startCDATA();
111
        void endCDATA();
112
        void comment(const XMLChar ch[], int start, int length); 
113
114
        void appendNode(AbstractNode* pNode);
115
        
116
        void setupParse();
117
118
private:
119
        static const XMLString EMPTY_STRING;
120
121
        XMLReader&             _xmlReader;
122
        NamePool*              _pNamePool;
123
        Document*              _pDocument;
124
        AbstractContainerNode* _pParent;
125
        AbstractNode*          _pPrevious;
126
        bool                   _inCDATA;
127
        bool                   _namespaces;
128
};
129
130
131
} } // namespace Poco::XML
132
133
134
#endif // DOM_DOMBuilder_INCLUDED