36 #include <libxml/parserInternals.h> 43 #include "D4Attributes.h" 47 #include "D4BaseTypeFactory.h" 49 #include "D4ParserSax2.h" 56 static const char *states[] = {
65 "inside_attribute_container",
67 "inside_attribute_value",
68 "inside_other_xml_attribute",
91 static bool is_not(
const char *name,
const char *tag)
93 return strcmp(name, tag) != 0;
105 D4ParserSax2::enum_def()
107 if (!d_enum_def) d_enum_def =
new D4EnumDef;
119 D4ParserSax2::dim_def() {
120 if (!d_dim_def) d_dim_def =
new D4Dimension;
130 void D4ParserSax2::transfer_xml_attrs(
const xmlChar **attributes,
int nb_attributes)
132 if (!xml_attrs.empty())
137 unsigned int index = 0;
138 for (
int i = 0; i < nb_attributes; ++i, index += 5) {
139 xml_attrs.insert(map<string, XMLAttribute>::value_type(
string((
const char *)attributes[index]),
140 XMLAttribute(attributes + index + 1)));
142 DBG(cerr <<
"XML Attribute '" << (
const char *)attributes[index] <<
"': " 143 << xml_attrs[(
const char *)attributes[index]].value << endl);
153 void D4ParserSax2::transfer_xml_ns(
const xmlChar **namespaces,
int nb_namespaces)
156 for (
int i = 0; i < nb_namespaces; ++i) {
157 namespace_table.insert(map<string, string>::value_type(namespaces[i * 2] != 0 ? (
const char *)namespaces[i * 2] :
"",
158 (
const char *)namespaces[i * 2 + 1]));
168 bool D4ParserSax2::check_required_attribute(
const string & attr)
170 if (xml_attrs.find(attr) == xml_attrs.end()) {
171 dmr_error(
this,
"Required attribute '%s' not found.", attr.c_str());
184 bool D4ParserSax2::check_attribute(
const string & attr)
186 return (xml_attrs.find(attr) != xml_attrs.end());
189 bool D4ParserSax2::process_dimension_def(
const char *name,
const xmlChar **attrs,
int nb_attributes)
191 if (is_not(name,
"Dimension"))
194 transfer_xml_attrs(attrs, nb_attributes);
196 if (!(check_required_attribute(
"name") && check_required_attribute(
"size"))) {
197 dmr_error(
this,
"The required attribute 'name' or 'size' was missing from a Dimension element.");
202 dim_def()->set_name(xml_attrs[
"name"].value);
204 dim_def()->set_size(xml_attrs[
"size"].value);
207 dmr_error(
this, e.get_error_message().c_str());
231 bool D4ParserSax2::process_dimension(
const char *name,
const xmlChar **attrs,
int nb_attributes)
233 if (is_not(name,
"Dim"))
236 transfer_xml_attrs(attrs, nb_attributes);
238 if (check_attribute(
"size") && check_attribute(
"name")) {
239 dmr_error(
this,
"Only one of 'size' and 'name' are allowed in a Dim element, but both were used.");
242 if (!(check_attribute(
"size") || check_attribute(
"name"))) {
243 dmr_error(
this,
"Either 'size' or 'name' must be used in a Dim element.");
249 BaseType *b = top_basetype();
252 Array *a =
static_cast<Array*
>(dmr()->
factory()->
NewVariable(dods_array_c, b->name()));
253 a->set_is_dap4(
true);
254 a->add_var_nocopy(b);
255 a->set_attributes_nocopy(b->attributes());
259 b->set_attributes_nocopy(0);
266 Array *a =
static_cast<Array*
>(top_basetype());
267 if (check_attribute(
"size")) {
268 a->append_dim(atoi(xml_attrs[
"size"].value.c_str()));
271 else if (check_attribute(
"name")) {
272 string name = xml_attrs[
"name"].value;
274 D4Dimension *dim = 0;
281 throw Error(
"The dimension '" + name +
"' was not found while parsing the variable '" + a->name() +
"'.");
289 bool D4ParserSax2::process_map(
const char *name,
const xmlChar **attrs,
int nb_attributes)
291 if (is_not(name,
"Map"))
294 transfer_xml_attrs(attrs, nb_attributes);
296 if (!check_attribute(
"name")) {
297 dmr_error(
this,
"The 'name' attribute must be used in a Map element.");
303 BaseType *b = top_basetype();
306 Array *a =
static_cast<Array*
>(dmr()->
factory()->
NewVariable(dods_array_c, b->name()));
307 a->set_is_dap4(
true);
308 a->add_var_nocopy(b);
309 a->set_attributes_nocopy(b->attributes());
313 b->set_attributes_nocopy(0);
320 Array *a =
static_cast<Array*
>(top_basetype());
322 string map_name = xml_attrs[
"name"].value;
323 if (xml_attrs[
"name"].value[0] !=
'/')
324 map_name = top_group()->
FQN() + map_name;
326 Array *map_source = 0;
328 if (map_name[0] ==
'/')
329 map_source = dmr()->
root()->find_map_source(map_name);
331 map_source = top_group()->find_map_source(map_name);
334 throw Error(
"The Map '" + map_name +
"' was not found while parsing the variable '" + a->name() +
"'.");
336 a->maps()->add_map(
new D4Map(map_name, map_source));
341 bool D4ParserSax2::process_group(
const char *name,
const xmlChar **attrs,
int nb_attributes)
343 if (is_not(name,
"Group"))
346 transfer_xml_attrs(attrs, nb_attributes);
348 if (!check_required_attribute(
"name")) {
349 dmr_error(
this,
"The required attribute 'name' was missing from a Group element.");
355 dmr_fatal_error(
this,
"Could not instantiate the Group '%s'.", xml_attrs[
"name"].value.c_str());
359 D4Group *grp =
static_cast<D4Group*
>(btp);
363 grp->set_is_dap4(
true);
366 D4Group *parent = top_group();
372 grp->set_parent(parent);
373 parent->add_group_nocopy(grp);
376 push_attributes(grp->attributes());
386 inline bool D4ParserSax2::process_attribute(
const char *name,
const xmlChar **attrs,
int nb_attributes)
388 if (is_not(name,
"Attribute"))
392 transfer_xml_attrs(attrs, nb_attributes);
395 if (!(check_required_attribute(
string(
"name")) && check_required_attribute(
string(
"type")))) {
396 dmr_error(
this,
"The required attribute 'name' or 'type' was missing from an Attribute element.");
400 if (xml_attrs[
"type"].value ==
"Container") {
401 push_state(inside_attribute_container);
403 DBG(cerr <<
"Pushing attribute container " << xml_attrs[
"name"].value << endl);
404 D4Attribute *child =
new D4Attribute(xml_attrs[
"name"].value, attr_container_c);
406 D4Attributes *tos = top_attributes();
410 dmr_fatal_error(
this,
"Expected an Attribute container on the top of the attribute stack.");
414 tos->add_attribute_nocopy(child);
415 push_attributes(child->attributes());
417 else if (xml_attrs[
"type"].value ==
"OtherXML") {
418 push_state(inside_other_xml_attribute);
420 dods_attr_name = xml_attrs[
"name"].value;
421 dods_attr_type = xml_attrs[
"type"].value;
424 push_state(inside_attribute);
426 dods_attr_name = xml_attrs[
"name"].value;
427 dods_attr_type = xml_attrs[
"type"].value;
438 inline bool D4ParserSax2::process_enum_def(
const char *name,
const xmlChar **attrs,
int nb_attributes)
440 if (is_not(name,
"Enumeration"))
443 transfer_xml_attrs(attrs, nb_attributes);
445 if (!(check_required_attribute(
"name") && check_required_attribute(
"basetype"))) {
446 dmr_error(
this,
"The required attribute 'name' or 'basetype' was missing from an Enumeration element.");
452 dmr_error(
this,
"The Enumeration '%s' must have an integer type, instead the type '%s' was used.",
453 xml_attrs[
"name"].value.c_str(), xml_attrs[
"basetype"].value.c_str());
458 string enum_def_path = xml_attrs[
"name"].value;
461 if (xml_attrs[
"name"].value[0] !=
'/')
462 enum_def_path = top_group()->
FQN() + enum_def_path;
464 enum_def()->set_name(enum_def_path);
465 enum_def()->set_type(t);
470 inline bool D4ParserSax2::process_enum_const(
const char *name,
const xmlChar **attrs,
int nb_attributes)
472 if (is_not(name,
"EnumConst"))
476 transfer_xml_attrs(attrs, nb_attributes);
478 if (!(check_required_attribute(
"name") && check_required_attribute(
"value"))) {
479 dmr_error(
this,
"The required attribute 'name' or 'value' was missing from an EnumConst element.");
483 istringstream iss(xml_attrs[
"value"].value);
485 iss >> skipws >> value;
486 if (iss.fail() || iss.bad()) {
487 dmr_error(
this,
"Expected an integer value for an Enumeration constant, got '%s' instead.",
488 xml_attrs[
"value"].value.c_str());
491 dmr_error(
this,
"In an Enumeration constant, the value '%s' cannot fit in a variable of type '%s'.",
492 xml_attrs[
"value"].value.c_str(),
D4type_name(d_enum_def->type()).c_str());
496 enum_def()->add_value(xml_attrs[
"name"].value, value);
507 inline bool D4ParserSax2::process_variable(
const char *name,
const xmlChar **attrs,
int nb_attributes)
511 process_variable_helper(t, inside_simple_type, attrs, nb_attributes);
516 case dods_structure_c:
517 process_variable_helper(t, inside_constructor, attrs, nb_attributes);
520 case dods_sequence_c:
521 process_variable_helper(t, inside_constructor, attrs, nb_attributes);
537 void D4ParserSax2::process_variable_helper(
Type t, ParseState s,
const xmlChar **attrs,
int nb_attributes)
539 transfer_xml_attrs(attrs, nb_attributes);
541 if (check_required_attribute(
"name")) {
544 dmr_fatal_error(
this,
"Could not instantiate the variable '%s'.", xml_attrs[
"name"].value.c_str());
548 if ((t == dods_enum_c) && check_required_attribute(
"enum")) {
549 D4EnumDef *enum_def = 0;
550 string enum_path = xml_attrs[
"enum"].value;
551 if (enum_path[0] ==
'/')
552 enum_def = dmr()->
root()->find_enum_def(enum_path);
554 enum_def = top_group()->find_enum_def(enum_path);
557 dmr_fatal_error(
this,
"Could not find the Enumeration definition '%s'.", enum_path.c_str());
559 static_cast<D4Enum*
>(btp)->set_enumeration(enum_def);
562 btp->set_is_dap4(
true);
565 push_attributes(btp->attributes());
585 parser->error_msg =
"";
586 parser->char_data =
"";
595 if (parser->debug()) cerr <<
"Parser start state: " << states[parser->get_state()] << endl;
604 if (parser->debug()) cerr <<
"Parser end state: " << states[parser->get_state()] << endl;
606 if (parser->get_state() != parser_end)
607 D4ParserSax2::dmr_error(parser,
"The document contained unbalanced tags.");
611 if (parser->get_state() == parser_error || parser->get_state() == parser_fatal_error)
614 if (!parser->empty_basetype() || parser->empty_group())
615 D4ParserSax2::dmr_error(parser,
"The document did not contain a valid root Group or contained unbalanced tags.");
618 parser->pop_attributes();
621 void D4ParserSax2::dmr_start_element(
void *p,
const xmlChar *l,
const xmlChar *prefix,
const xmlChar *URI,
622 int nb_namespaces,
const xmlChar **namespaces,
int nb_attributes,
int ,
623 const xmlChar **attributes)
626 const char *localname = (
const char *) l;
628 if (parser->debug()) cerr <<
"Start element " << localname <<
" (state " << states[parser->get_state()] <<
")" << endl;
630 switch (parser->get_state()) {
632 if (is_not(localname,
"Dataset"))
633 D4ParserSax2::dmr_error(parser,
"Expected DMR to start with a Dataset element; found '%s' instead.", localname);
635 parser->root_ns = URI ? (
const char *) URI :
"";
636 parser->transfer_xml_attrs(attributes, nb_attributes);
638 if (parser->check_required_attribute(
string(
"name")))
639 parser->dmr()->set_name(parser->xml_attrs[
"name"].value);
641 if (parser->check_attribute(
"dapVersion"))
644 if (parser->check_attribute(
"dmrVersion"))
645 parser->dmr()->set_dmr_version(parser->xml_attrs[
"dmrVersion"].value);
647 if (parser->check_attribute(
"base"))
650 if (!parser->root_ns.empty())
654 parser->push_group(parser->dmr()->
root());
656 parser->push_state(inside_dataset);
665 if (parser->process_enum_def(localname, attributes, nb_attributes))
666 parser->push_state(inside_enum_def);
667 else if (parser->process_dimension_def(localname, attributes, nb_attributes))
668 parser->push_state(inside_dim_def);
669 else if (parser->process_group(localname, attributes, nb_attributes))
670 parser->push_state(inside_group);
671 else if (parser->process_variable(localname, attributes, nb_attributes))
675 else if (parser->process_attribute(localname, attributes, nb_attributes))
680 D4ParserSax2::dmr_error(parser,
"Expected an Attribute, Enumeration, Dimension, Group or variable element; found '%s' instead.", localname);
683 case inside_attribute_container:
684 if (parser->process_attribute(localname, attributes, nb_attributes))
687 D4ParserSax2::dmr_error(parser,
"Expected an Attribute element; found '%s' instead.", localname);
690 case inside_attribute:
691 if (parser->process_attribute(localname, attributes, nb_attributes))
693 else if (strcmp(localname,
"Value") == 0)
694 parser->push_state(inside_attribute_value);
696 dmr_error(parser,
"Expected an 'Attribute' or 'Value' element; found '%s' instead.", localname);
699 case inside_attribute_value:
703 case inside_other_xml_attribute:
704 parser->other_xml_depth++;
707 parser->other_xml.append(
"<");
709 parser->other_xml.append((
const char *) prefix);
710 parser->other_xml.append(
":");
712 parser->other_xml.append(localname);
714 if (nb_namespaces != 0) {
715 parser->transfer_xml_ns(namespaces, nb_namespaces);
717 for (map<string, string>::iterator i = parser->namespace_table.begin();
718 i != parser->namespace_table.end(); ++i) {
719 parser->other_xml.append(
" xmlns");
720 if (!i->first.empty()) {
721 parser->other_xml.append(
":");
722 parser->other_xml.append(i->first);
724 parser->other_xml.append(
"=\"");
725 parser->other_xml.append(i->second);
726 parser->other_xml.append(
"\"");
730 if (nb_attributes != 0) {
731 parser->transfer_xml_attrs(attributes, nb_attributes);
732 for (XMLAttrMap::iterator i = parser->xml_attr_begin(); i != parser->xml_attr_end(); ++i) {
733 parser->other_xml.append(
" ");
734 if (!i->second.prefix.empty()) {
735 parser->other_xml.append(i->second.prefix);
736 parser->other_xml.append(
":");
738 parser->other_xml.append(i->first);
739 parser->other_xml.append(
"=\"");
740 parser->other_xml.append(i->second.value);
741 parser->other_xml.append(
"\"");
745 parser->other_xml.append(
">");
748 case inside_enum_def:
750 if (parser->process_enum_const(localname, attributes, nb_attributes))
751 parser->push_state(inside_enum_const);
753 dmr_error(parser,
"Expected an 'EnumConst' element; found '%s' instead.", localname);
756 case inside_enum_const:
764 case inside_dimension:
776 case inside_simple_type:
777 if (parser->process_attribute(localname, attributes, nb_attributes))
779 else if (parser->process_dimension(localname, attributes, nb_attributes))
780 parser->push_state(inside_dim);
781 else if (parser->process_map(localname, attributes, nb_attributes))
782 parser->push_state(inside_map);
784 dmr_error(parser,
"Expected an 'Attribute', 'Dim' or 'Map' element; found '%s' instead.", localname);
787 case inside_constructor:
788 if (parser->process_variable(localname, attributes, nb_attributes))
792 else if (parser->process_attribute(localname, attributes, nb_attributes))
794 else if (parser->process_dimension(localname, attributes, nb_attributes))
795 parser->push_state(inside_dim);
796 else if (parser->process_map(localname, attributes, nb_attributes))
797 parser->push_state(inside_map);
799 D4ParserSax2::dmr_error(parser,
"Expected an Attribute, Dim, Map or variable element; found '%s' instead.", localname);
805 parser->push_state(parser_unknown);
809 case parser_fatal_error:
817 if (parser->debug()) cerr <<
"Start element exit state: " << states[parser->get_state()] << endl;
820 void D4ParserSax2::dmr_end_element(
void *p,
const xmlChar *l,
const xmlChar *prefix,
const xmlChar *URI)
823 const char *localname = (
const char *) l;
826 cerr <<
"End element " << localname <<
" (state " << states[parser->get_state()] <<
")" << endl;
828 switch (parser->get_state()) {
830 dmr_fatal_error(parser,
"Unexpected state, inside start state while processing element '%s'.", localname);
834 if (is_not(localname,
"Dataset"))
835 D4ParserSax2::dmr_error(parser,
"Expected an end Dataset tag; found '%s' instead.", localname);
838 if (parser->get_state() != parser_start)
842 parser->push_state(parser_end);
847 if (is_not(localname,
"Group"))
848 D4ParserSax2::dmr_error(parser,
"Expected an end tag for a Group; found '%s' instead.", localname);
850 if (!parser->empty_basetype() || parser->empty_group())
851 D4ParserSax2::dmr_error(parser,
852 "The document did not contain a valid root Group or contained unbalanced tags.");
859 case inside_attribute_container:
860 if (is_not(localname,
"Attribute"))
861 D4ParserSax2::dmr_error(parser,
"Expected an end Attribute tag; found '%s' instead.", localname);
864 parser->pop_attributes();
867 case inside_attribute:
868 if (is_not(localname,
"Attribute"))
869 D4ParserSax2::dmr_error(parser,
"Expected an end Attribute tag; found '%s' instead.", localname);
874 case inside_attribute_value: {
875 if (is_not(localname,
"Value"))
876 D4ParserSax2::dmr_error(parser,
"Expected an end value tag; found '%s' instead.", localname);
886 attr =
new D4Attribute(parser->dods_attr_name, StringToD4AttributeType(parser->dods_attr_type));
887 attrs->add_attribute_nocopy(attr);
889 attr->add_value(parser->char_data);
891 parser->char_data =
"";
895 case inside_other_xml_attribute: {
896 if (strcmp(localname,
"Attribute") == 0 && parser->root_ns == (
const char *) URI) {
905 attr =
new D4Attribute(parser->dods_attr_name, StringToD4AttributeType(parser->dods_attr_type));
906 attrs->add_attribute_nocopy(attr);
908 attr->add_value(parser->other_xml);
910 parser->other_xml =
"";
913 if (parser->other_xml_depth == 0) {
914 D4ParserSax2::dmr_error(parser,
"Expected an OtherXML attribute to end! Instead I found '%s'",
918 parser->other_xml_depth--;
920 parser->other_xml.append(
"</");
922 parser->other_xml.append((
const char *) prefix);
923 parser->other_xml.append(
":");
925 parser->other_xml.append(localname);
926 parser->other_xml.append(
">");
931 case inside_enum_def:
932 if (is_not(localname,
"Enumeration"))
933 D4ParserSax2::dmr_error(parser,
"Expected an end Enumeration tag; found '%s' instead.", localname);
934 if (!parser->top_group())
936 "Expected a Group to be the current item, while finishing up an Enumeration.");
939 parser->top_group()->
enum_defs()->add_enum_nocopy(parser->enum_def());
942 parser->clear_enum_def();
947 case inside_enum_const:
948 if (is_not(localname,
"EnumConst"))
949 D4ParserSax2::dmr_error(parser,
"Expected an end EnumConst tag; found '%s' instead.", localname);
954 case inside_dim_def: {
955 if (is_not(localname,
"Dimension"))
956 D4ParserSax2::dmr_error(parser,
"Expected an end Dimension tag; found '%s' instead.", localname);
958 if (!parser->top_group())
959 D4ParserSax2::dmr_error(parser,
960 "Expected a Group to be the current item, while finishing up an Dimension.");
971 parser->clear_dim_def();
976 case inside_simple_type:
978 BaseType *btp = parser->top_basetype();
979 parser->pop_basetype();
980 parser->pop_attributes();
983 if (!parser->empty_basetype())
984 parent = parser->top_basetype();
985 else if (!parser->empty_group())
986 parent = parser->top_group();
988 dmr_fatal_error(parser,
"Both the Variable and Groups stacks are empty while closing a %s element.",
995 if (parent->
type() == dods_array_c)
996 static_cast<Array*>(parent)->prototype()->add_var_nocopy(btp);
998 parent->add_var_nocopy(btp);
1001 D4ParserSax2::dmr_error(parser,
"Expected an end tag for a simple type; found '%s' instead.", localname);
1003 parser->pop_state();
1007 if (is_not(localname,
"Dim"))
1010 parser->pop_state();
1014 if (is_not(localname,
"Map"))
1017 parser->pop_state();
1020 case inside_constructor: {
1021 if (strcmp(localname,
"Structure") != 0 && strcmp(localname,
"Sequence") != 0) {
1022 D4ParserSax2::dmr_error(parser,
"Expected an end tag for a constructor; found '%s' instead.", localname);
1026 BaseType *btp = parser->top_basetype();
1027 parser->pop_basetype();
1028 parser->pop_attributes();
1031 if (!parser->empty_basetype())
1032 parent = parser->top_basetype();
1033 else if (!parser->empty_group())
1034 parent = parser->top_group();
1036 dmr_fatal_error(parser,
"Both the Variable and Groups stacks are empty while closing a %s element.",
1039 parser->pop_state();
1045 parent->add_var_nocopy(btp);
1046 parser->pop_state();
1050 case parser_unknown:
1051 parser->pop_state();
1055 case parser_fatal_error:
1063 if (parser->debug()) cerr <<
"End element exit state: " << states[parser->get_state()] << endl;
1073 switch (parser->get_state()) {
1074 case inside_attribute_value:
1075 parser->char_data.append((
const char *) (ch), len);
1076 DBG(cerr <<
"Characters: '" << parser->char_data <<
"'" << endl);
1079 case inside_other_xml_attribute:
1080 parser->other_xml.append((
const char *) (ch), len);
1081 DBG(cerr <<
"Other XML Characters: '" << parser->other_xml <<
"'" << endl);
1097 switch (parser->get_state()) {
1098 case inside_other_xml_attribute:
1099 parser->other_xml.append((
const char *) (ch), len);
1116 switch (parser->get_state()) {
1117 case inside_other_xml_attribute:
1118 parser->other_xml.append((
const char *) (value), len);
1121 case parser_unknown:
1125 D4ParserSax2::dmr_error(parser,
"Found a CData block but none are allowed by DAP4.");
1137 return xmlGetPredefinedEntity(name);
1155 parser->push_state(parser_fatal_error);
1157 va_start(args, msg);
1159 vsnprintf(str, 1024, msg, args);
1162 int line = xmlSAX2GetLineNumber(parser->context);
1164 if (!parser->error_msg.empty()) parser->error_msg +=
"\n";
1165 parser->error_msg +=
"At line " + long_to_string(line) +
": " + string(str);
1168 void D4ParserSax2::dmr_error(
void *p,
const char *msg, ...)
1173 parser->push_state(parser_error);
1175 va_start(args, msg);
1177 vsnprintf(str, 1024, msg, args);
1180 int line = xmlSAX2GetLineNumber(parser->context);
1182 if (!parser->error_msg.empty()) parser->error_msg +=
"\n";
1183 parser->error_msg +=
"At line " + long_to_string(line) +
": " + string(str);
1190 void D4ParserSax2::cleanup_parse()
1192 bool wellFormed = context->wellFormed;
1193 bool valid = context->valid;
1195 context->sax = NULL;
1196 xmlFreeParserCtxt(context);
1206 while (!btp_stack.empty()) {
1207 delete top_basetype();
1212 throw Error(
"The DMR was not well formed. " + error_msg);
1214 throw Error(
"The DMR was not valid." + error_msg);
1215 else if (get_state() == parser_error)
1216 throw Error(error_msg);
1217 else if (get_state() == parser_fatal_error)
1235 void D4ParserSax2::intern(istream &f,
DMR *dest_dmr,
bool debug)
1242 throw Error(
"Input stream not open or read error");
1244 throw InternalErr(__FILE__, __LINE__,
"DMR object is null");
1248 const int size = 1024;
1252 f.getline(chars, size);
1253 int res = f.gcount();
1254 if (res == 0)
throw Error(
"No input found while parsing the DMR.");
1256 if (debug) cerr <<
"line: (" << line++ <<
"): " << chars << endl;
1258 context = xmlCreatePushParserCtxt(&ddx_sax_parser,
this, chars, res - 1,
"stream");
1259 context->validate =
true;
1260 push_state(parser_start);
1262 f.getline(chars, size);
1263 while ((f.gcount() > 0) && (get_state() != parser_end)) {
1264 if (debug) cerr <<
"line: (" << line++ <<
"): " << chars << endl;
1265 xmlParseChunk(context, chars, f.gcount() - 1, 0);
1266 f.getline(chars, size);
1270 xmlParseChunk(context, chars, 0, 1);
1287 void D4ParserSax2::intern(
const string &document,
DMR *dest_dmr,
bool debug)
1289 intern(document.c_str(), document.length(), dest_dmr, debug);
1302 void D4ParserSax2::intern(
const char *buffer,
int size,
DMR *dest_dmr,
bool debug)
1304 if (!(size > 0))
return;
1310 if (!dest_dmr)
throw InternalErr(__FILE__, __LINE__,
"DMR object is null");
1313 push_state(parser_start);
1314 context = xmlCreatePushParserCtxt(&ddx_sax_parser,
this, buffer, size,
"stream");
1315 context->validate =
true;
1320 xmlParseChunk(context, buffer, 0, 1);
static void dmr_end_document(void *parser)
void set_namespace(const string &ns)
Set the namespace for this DDS/DDX object/response.
bool is_valid_enum_value(long long value)
D4Dimension * find_dim(const string &path)
Find the dimension using a path. Using the DAP4 name syntax, lookup a dimension. The dimension must b...
static void dmr_start_document(void *parser)
static xmlEntityPtr dmr_get_entity(void *parser, const xmlChar *name)
bool is_vector_type(Type t)
Returns true if the instance is a vector (i.e., array) type variable.
void set_request_xml_base(const string &xb)
Type
Identifies the data type.
virtual Type type() const
Returns the type of the class instance.
A class for software fault reporting.
static void dmr_ignoreable_whitespace(void *parser, const xmlChar *ch, int len)
void add_dim_nocopy(D4Dimension *dim)
virtual D4BaseTypeFactory * factory()
static void dmr_get_cdata(void *parser, const xmlChar *value, int len)
ObjectType get_type(const string &value)
string D4type_name(Type t)
Returns the type of the class instance as a string. Supports all DAP4 types and not the DAP2-only typ...
bool is_simple_type(Type t)
Returns true if the instance is a numeric, string or URL type variable.
virtual D4Attributes * attributes()
static void dmr_get_characters(void *parser, const xmlChar *ch, int len)
The basic data type for the DODS DAP types.
void set_dap_version(const string &version_string)
D4Attribute * get(const string &fqn)
A class for error processing.
virtual std::string FQN() const
D4EnumDefs * enum_defs()
Get the enumerations defined for this Group.
static void dmr_fatal_error(void *parser, const char *msg,...)
bool is_integer_type(Type t)
D4Dimensions * dims()
Get the dimensions defined for this Group.
virtual BaseType * NewVariable(Type t, const string &name) const