26 #ifndef d4_parser_sax2_h 27 #define d4_parser_sax2_h 38 #include <libxml/parserInternals.h> 41 #define D4_PARSE_BUFF_SIZE 1048576 48 class D4BaseTypeFactory;
91 inside_attribute_container,
93 inside_attribute_value,
94 inside_other_xml_attribute,
120 char d_parse_buffer[D4_PARSE_BUFF_SIZE+1];
122 xmlSAXHandler d_dmr_sax_parser;
127 DMR *dmr()
const {
return d_dmr; }
131 void push_state(D4ParserSax2::ParseState state) { s.push(state); }
132 D4ParserSax2::ParseState get_state()
const {
return s.top(); }
133 void pop_state() { s.pop(); }
134 bool empty_state()
const {
return s.empty(); }
136 stack<BaseType*> btp_stack;
137 void push_basetype(
BaseType *btp) { btp_stack.push(btp); }
138 BaseType *top_basetype()
const {
return btp_stack.top(); }
139 void pop_basetype() { btp_stack.pop(); }
140 bool empty_basetype()
const {
return btp_stack.empty(); }
142 stack<D4Group*> grp_stack;
143 void push_group(
D4Group *grp) { grp_stack.push(grp); }
144 D4Group *top_group()
const {
return grp_stack.top(); }
145 void pop_group() { grp_stack.pop(); }
146 bool empty_group()
const {
return grp_stack.empty(); }
148 stack<D4Attributes*> d_attrs_stack;
149 void push_attributes(
D4Attributes *attr) { d_attrs_stack.push(attr); }
150 D4Attributes *top_attributes()
const {
return d_attrs_stack.top(); }
151 void pop_attributes() { d_attrs_stack.pop(); }
152 bool empty_attributes()
const {
return d_attrs_stack.empty(); }
156 void clear_enum_def() { d_enum_def = 0; }
160 void clear_dim_def() { d_dim_def = 0; }
167 unsigned int other_xml_depth;
168 unsigned int unknown_depth;
172 xmlParserCtxtPtr d_context;
175 string dods_attr_name;
176 string dods_attr_type;
181 bool debug()
const {
return d_debug; }
191 void clone(
const XMLAttribute &src) {
197 XMLAttribute() : prefix(
""), nsURI(
""), value(
"") {}
198 XMLAttribute(
const string &p,
const string &ns,
const string &v)
199 : prefix(p), nsURI(ns), value(v) {}
202 XMLAttribute(
const xmlChar **attributes) {
203 prefix = attributes[0] != 0 ? (
const char *)attributes[0]:
"";
204 nsURI = attributes[1] != 0 ? (
const char *)attributes[1]:
"";
205 value = string((
const char *)attributes[2], (
const char *)attributes[3]);
207 XMLAttribute(
const XMLAttribute &rhs) {
212 XMLAttribute &operator=(
const XMLAttribute &rhs) {
220 typedef map<string, XMLAttribute> XMLAttrMap;
221 XMLAttrMap xml_attrs;
223 XMLAttrMap::iterator xml_attr_begin() {
return xml_attrs.begin(); }
225 XMLAttrMap::iterator xml_attr_end() {
return xml_attrs.end(); }
227 map<string, string> namespace_table;
229 void cleanup_parse();
237 void transfer_xml_attrs(
const xmlChar **attrs,
int nb_attributes);
238 void transfer_xml_ns(
const xmlChar **namespaces,
int nb_namespaces);
239 bool check_required_attribute(
const string &attr);
240 bool check_attribute(
const string & attr);
241 void process_variable_helper(
Type t, ParseState s,
const xmlChar **attrs,
int nb_attributes);
243 void process_enum_const_helper(
const xmlChar **attrs,
int nb_attributes);
244 void process_enum_def_helper(
const xmlChar **attrs,
int nb_attributes);
246 bool process_dimension(
const char *name,
const xmlChar **attrs,
int nb_attrs);
247 bool process_dimension_def(
const char *name,
const xmlChar **attrs,
int nb_attrs);
248 bool process_map(
const char *name,
const xmlChar **attrs,
int nb_attributes);
249 bool process_attribute(
const char *name,
const xmlChar **attrs,
int nb_attributes);
250 bool process_variable(
const char *name,
const xmlChar **attrs,
int nb_attributes);
251 bool process_group(
const char *name,
const xmlChar **attrs,
int nb_attributes);
252 bool process_enum_def(
const char *name,
const xmlChar **attrs,
int nb_attributes);
253 bool process_enum_const(
const char *name,
const xmlChar **attrs,
int nb_attributes);
255 void finish_variable(
const char *tag,
Type t,
const char *expected);
258 friend class D4ParserSax2Test;
262 d_dmr(0), d_enum_def(0), d_dim_def(0),
263 other_xml(
""), other_xml_depth(0), unknown_depth(0),
264 d_error_msg(
""), d_context(0),
265 dods_attr_name(
""), dods_attr_type(
""),
266 char_data(
""), root_ns(
""), d_debug(
false), d_strict(
true)
269 memset(&d_dmr_sax_parser, 0,
sizeof(xmlSAXHandler));
277 d_dmr_sax_parser.warning = &D4ParserSax2::dmr_error;
278 d_dmr_sax_parser.error = &D4ParserSax2::dmr_error;
280 d_dmr_sax_parser.initialized = XML_SAX2_MAGIC;
282 d_dmr_sax_parser.endElementNs = &D4ParserSax2::dmr_end_element;
285 void intern(istream &f,
DMR *dest_dmr,
bool debug =
false);
287 void intern(
const string &document,
DMR *dest_dmr,
bool debug =
false);
288 void intern(
const char *buffer,
int size,
DMR *dest_dmr,
bool debug =
false);
313 const xmlChar *localname,
const xmlChar *prefix,
const xmlChar *URI,
314 int nb_namespaces,
const xmlChar **namespaces,
int nb_attributes,
315 int nb_defaulted,
const xmlChar **attributes);
316 static void dmr_end_element(
void *parser,
const xmlChar *localname,
317 const xmlChar *prefix,
const xmlChar *URI);
321 const xmlChar * ch,
int len);
322 static void dmr_get_cdata(
void *parser,
const xmlChar *value,
int len);
324 static xmlEntityPtr
dmr_get_entity(
void *parser,
const xmlChar *name);
326 static void dmr_error(
void *parser,
const char *msg, ...);
331 #endif // d4_parser_sax2_h static void dmr_end_document(void *parser)
static void dmr_start_document(void *parser)
static xmlEntityPtr dmr_get_entity(void *parser, const xmlChar *name)
void set_strict(bool s)
Set the 'strict' mode to true or false.
Type
Identifies the data type.
top level DAP object to house generic methods
static void dmr_start_element(void *parser, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI, int nb_namespaces, const xmlChar **namespaces, int nb_attributes, int nb_defaulted, const xmlChar **attributes)
static void dmr_ignoreable_whitespace(void *parser, const xmlChar *ch, int len)
static void dmr_get_cdata(void *parser, const xmlChar *value, int len)
static void dmr_get_characters(void *parser, const xmlChar *ch, int len)
bool get_strict() const
Get the setting of the 'strict' mode.
The basic data type for the DODS DAP types.
static void dmr_fatal_error(void *parser, const char *msg,...)