1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/* $Rev$ $Date$ */
#ifndef _SAX2PARSER_H_
#define _SAX2PARSER_H_
#include "commonj/sdo/disable_warn.h"
#include "commonj/sdo/SDOXMLString.h"
#include "commonj/sdo/SAX2Namespaces.h"
#include "commonj/sdo/SAX2Attributes.h"
#include "commonj/sdo/ParserErrorSetter.h"
#include "sstream"
namespace commonj
{
namespace sdo
{
class parse_buf_element
{
public:
char buf[1000];
int len;
};
/**
* SAX2Parser holds the methods which will be called back.
* The implementation uses libxml, which provides callbacks for
* errors, warnings , elements etc. These methods correspond to thos
* callbacks.
* Callbacks from libxml to these C methods are converted into calls
* to the C++ equivalent (with some parameter manipulation
* In the callback methods the void* ctx is a pointer to 'this' SAX2Parser
*/
class SAX2Parser
{
public:
SAX2Parser();
SAX2Parser(ParserErrorSetter* insetter);
virtual ~SAX2Parser();
virtual int parse (const char* filename);
virtual int parse_twice (const char* filename);
virtual void startDocument();
virtual void endDocument();
virtual void startElementNs(
const SDOXMLString& localname,
const SDOXMLString& prefix,
const SDOXMLString& URI,
const SAX2Namespaces& namespaces,
const SAX2Attributes& attributes);
virtual void endElementNs(
const SDOXMLString& localname,
const SDOXMLString& prefix,
const SDOXMLString& URI);
virtual void characters(const SDOXMLString& chars);
virtual void warning(const char* msg, va_list args);
virtual void fatalError(const char* msg, va_list args);
virtual void error(const char* msg, va_list args);
virtual void stream(std::istream& input);
virtual void stream_twice(std::istream& input);
friend std::istream& operator>>(std::istream& input, SAX2Parser& parser);
ParserErrorSetter* setter;
bool parserError;
char messageBuffer[1024];
virtual const char* getCurrentFile() const;
virtual void setCurrentFile(const char* filename);
private:
char* currentFile;
};
} // End - namespace sdo
} // End - namespace commonj
#endif //_SAX2PARSER_H_
|