79 inside_attribute_container,
81 inside_attribute_value,
82 inside_other_xml_attribute,
100 inside_dmrpp_chunkDimensionSizes_element,
101 inside_dmrpp_compact_element,
110 char d_parse_buffer[D4_PARSE_BUFF_SIZE+1];
112 xmlSAXHandler dmrpp_sax_parser;
117 libdap::DMR *dmr()
const {
return d_dmr; }
120 std::stack<ParseState> s;
121 void push_state(DmrppParserSax2::ParseState state) { s.push(state); }
122 DmrppParserSax2::ParseState get_state()
const {
return s.top(); }
123 void pop_state() { s.pop(); }
124 bool empty_state()
const {
return s.empty(); }
126 std::stack<libdap::BaseType*> btp_stack;
127 void push_basetype(libdap::BaseType *btp) { btp_stack.push(btp); }
128 libdap::BaseType *top_basetype()
const {
return btp_stack.top(); }
129 void pop_basetype() { btp_stack.pop(); }
130 bool empty_basetype()
const {
return btp_stack.empty(); }
132 std::stack<libdap::D4Group*> grp_stack;
133 void push_group(libdap::D4Group *grp) { grp_stack.push(grp); }
134 libdap::D4Group *top_group()
const {
return grp_stack.top(); }
135 void pop_group() { grp_stack.pop(); }
136 bool empty_group()
const {
return grp_stack.empty(); }
138 std::stack<libdap::D4Attributes*> d_attrs_stack;
139 void push_attributes(libdap::D4Attributes *attr) { d_attrs_stack.push(attr); }
140 libdap::D4Attributes *top_attributes()
const {
return d_attrs_stack.top(); }
141 void pop_attributes() { d_attrs_stack.pop(); }
142 bool empty_attributes()
const {
return d_attrs_stack.empty(); }
144 libdap::D4EnumDef *d_enum_def;
145 libdap::D4EnumDef *enum_def();
146 void clear_enum_def() { d_enum_def = 0; }
148 libdap::D4Dimension *d_dim_def;
149 libdap::D4Dimension *dim_def();
150 void clear_dim_def() { d_dim_def = 0; }
153 std::string other_xml;
157 unsigned int other_xml_depth;
158 unsigned int unknown_depth;
161 std::string error_msg;
162 xmlParserCtxtPtr context;
165 std::string dods_attr_name;
166 std::string dods_attr_type;
167 std::string char_data;
172 std::shared_ptr<http::url> dmrpp_dataset_href;
180 void clone(
const XMLAttribute &src) {
186 XMLAttribute() : prefix(
""), nsURI(
""), value(
"") {}
187 XMLAttribute(
const std::string &p,
const std::string &ns,
const std::string &v)
188 : prefix(p), nsURI(ns), value(v) {}
191 XMLAttribute(
const xmlChar **attributes) {
192 prefix = attributes[0] != 0 ? (
const char *)attributes[0]:
"";
193 nsURI = attributes[1] != 0 ? (
const char *)attributes[1]:
"";
194 value = std::string((
const char *)attributes[2], (
const char *)attributes[3]);
196 XMLAttribute(
const XMLAttribute &rhs) {
199 XMLAttribute &operator=(
const XMLAttribute &rhs) {
207 typedef std::unordered_map<std::string, XMLAttribute> XMLAttrMap;
208 XMLAttrMap xml_attrs;
210 XMLAttrMap::iterator xml_attr_begin() {
return xml_attrs.begin(); }
212 XMLAttrMap::iterator xml_attr_end() {
return xml_attrs.end(); }
214 std::map<std::string, std::string> namespace_table;
216 void cleanup_parse();
225 void transfer_xml_attrs(
const xmlChar **attrs,
int nb_attributes);
227 std::string get_attribute_val(
const std::string &name,
const xmlChar **attributes,
int num_attributes);
228 void transfer_xml_ns(
const xmlChar **namespaces,
int nb_namespaces);
229 bool check_required_attribute(
const std::string &attr);
230 bool check_required_attribute(
const std::string &attr,
const xmlChar **attributes,
int num_attributes);
231 bool check_attribute(
const std::string & attr);
232 bool check_attribute(
const std::string &name,
const xmlChar **attributes,
int num_attributes);
233 void process_variable_helper(libdap::Type t, ParseState s,
const xmlChar **attrs,
int nb_attributes);
235 void process_enum_const_helper(
const xmlChar **attrs,
int nb_attributes);
236 void process_enum_def_helper(
const xmlChar **attrs,
int nb_attributes);
238 bool process_dmrpp_compact_start(
const char *name);
239 void process_dmrpp_compact_end(
const char *localname);
240 bool process_dimension(
const char *name,
const xmlChar **attrs,
int nb_attrs);
241 bool process_dimension_def(
const char *name,
const xmlChar **attrs,
int nb_attrs);
242 bool process_map(
const char *name,
const xmlChar **attrs,
int nb_attributes);
243 bool process_attribute(
const char *name,
const xmlChar **attrs,
int nb_attributes);
244 bool process_variable(
const char *name,
const xmlChar **attrs,
int nb_attributes);
245 bool process_group(
const char *name,
const xmlChar **attrs,
int nb_attributes);
246 bool process_enum_def(
const char *name,
const xmlChar **attrs,
int nb_attributes);
247 bool process_enum_const(
const char *name,
const xmlChar **attrs,
int nb_attributes);
248 bool process_dmrpp_object(
const char *name,
const xmlChar **attrs,
int nb_attributes);
250 void finish_variable(
const char *tag, libdap::Type t,
const char *expected);
253 friend class DmrppParserSax2Test;
257 d_dmr(0), d_enum_def(0), d_dim_def(0),
258 other_xml(
""), other_xml_depth(0), unknown_depth(0),
259 error_msg(
""), context(0),
260 dods_attr_name(
""), dods_attr_type(
""),
261 char_data(
""), root_ns(
""), d_strict(
true),
262 dmrpp_dataset_href(
nullptr)
265 memset(&dmrpp_sax_parser, 0,
sizeof(xmlSAXHandler));
273 dmrpp_sax_parser.warning = &DmrppParserSax2::dmr_error;
274 dmrpp_sax_parser.error = &DmrppParserSax2::dmr_error;
276 dmrpp_sax_parser.initialized = XML_SAX2_MAGIC;
277 dmrpp_sax_parser.startElementNs = &DmrppParserSax2::dmr_start_element;
278 dmrpp_sax_parser.endElementNs = &DmrppParserSax2::dmr_end_element;
283 void intern(std::istream &f, libdap::DMR *dest_dmr);
284 void intern(
const std::string &document, libdap::DMR *dest_dmr);
285 void intern(
const char *buffer,
int size, libdap::DMR *dest_dmr);
309 static void dmr_start_element(
void *parser,
310 const xmlChar *localname,
const xmlChar *prefix,
const xmlChar *URI,
311 int nb_namespaces,
const xmlChar **namespaces,
int nb_attributes,
312 int nb_defaulted,
const xmlChar **attributes);
313 static void dmr_end_element(
void *parser,
const xmlChar *localname,
314 const xmlChar *prefix,
const xmlChar *URI);
318 const xmlChar * ch,
int len);
319 static void dmr_get_cdata(
void *parser,
const xmlChar *value,
int len);
321 static xmlEntityPtr
dmr_get_entity(
void *parser,
const xmlChar *name);
323 static void dmr_error(
void *parser,
const char *msg, ...);