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);
339 if (!map_source && d_strict)
340 throw Error(
"The Map '" + map_name +
"' was not found while parsing the variable '" + a->name() +
"'.");
342 a->maps()->
add_map(
new D4Map(map_name, map_source));
347 bool D4ParserSax2::process_group(
const char *name,
const xmlChar **attrs,
int nb_attributes)
349 if (is_not(name,
"Group"))
352 transfer_xml_attrs(attrs, nb_attributes);
354 if (!check_required_attribute(
"name")) {
355 dmr_error(
this,
"The required attribute 'name' was missing from a Group element.");
361 dmr_fatal_error(
this,
"Could not instantiate the Group '%s'.", xml_attrs[
"name"].value.c_str());
365 D4Group *grp =
static_cast<D4Group*
>(btp);
369 grp->set_is_dap4(
true);
372 D4Group *parent = top_group();
378 grp->set_parent(parent);
379 parent->add_group_nocopy(grp);
382 push_attributes(grp->attributes());
392 inline bool D4ParserSax2::process_attribute(
const char *name,
const xmlChar **attrs,
int nb_attributes)
394 if (is_not(name,
"Attribute"))
398 transfer_xml_attrs(attrs, nb_attributes);
401 if (!(check_required_attribute(
string(
"name")) && check_required_attribute(
string(
"type")))) {
402 dmr_error(
this,
"The required attribute 'name' or 'type' was missing from an Attribute element.");
406 if (xml_attrs[
"type"].value ==
"Container") {
407 push_state(inside_attribute_container);
409 DBG(cerr <<
"Pushing attribute container " << xml_attrs[
"name"].value << endl);
410 D4Attribute *child =
new D4Attribute(xml_attrs[
"name"].value, attr_container_c);
412 D4Attributes *tos = top_attributes();
416 dmr_fatal_error(
this,
"Expected an Attribute container on the top of the attribute stack.");
420 tos->add_attribute_nocopy(child);
421 push_attributes(child->attributes());
423 else if (xml_attrs[
"type"].value ==
"OtherXML") {
424 push_state(inside_other_xml_attribute);
426 dods_attr_name = xml_attrs[
"name"].value;
427 dods_attr_type = xml_attrs[
"type"].value;
430 push_state(inside_attribute);
432 dods_attr_name = xml_attrs[
"name"].value;
433 dods_attr_type = xml_attrs[
"type"].value;
444 inline bool D4ParserSax2::process_enum_def(
const char *name,
const xmlChar **attrs,
int nb_attributes)
446 if (is_not(name,
"Enumeration"))
449 transfer_xml_attrs(attrs, nb_attributes);
451 if (!(check_required_attribute(
"name") && check_required_attribute(
"basetype"))) {
452 dmr_error(
this,
"The required attribute 'name' or 'basetype' was missing from an Enumeration element.");
458 dmr_error(
this,
"The Enumeration '%s' must have an integer type, instead the type '%s' was used.",
459 xml_attrs[
"name"].value.c_str(), xml_attrs[
"basetype"].value.c_str());
464 string enum_def_path = xml_attrs[
"name"].value;
467 if (xml_attrs[
"name"].value[0] !=
'/')
468 enum_def_path = top_group()->
FQN() + enum_def_path;
470 enum_def()->set_name(enum_def_path);
471 enum_def()->set_type(t);
476 inline bool D4ParserSax2::process_enum_const(
const char *name,
const xmlChar **attrs,
int nb_attributes)
478 if (is_not(name,
"EnumConst"))
482 transfer_xml_attrs(attrs, nb_attributes);
484 if (!(check_required_attribute(
"name") && check_required_attribute(
"value"))) {
485 dmr_error(
this,
"The required attribute 'name' or 'value' was missing from an EnumConst element.");
489 istringstream iss(xml_attrs[
"value"].value);
491 iss >> skipws >> value;
492 if (iss.fail() || iss.bad()) {
493 dmr_error(
this,
"Expected an integer value for an Enumeration constant, got '%s' instead.",
494 xml_attrs[
"value"].value.c_str());
497 dmr_error(
this,
"In an Enumeration constant, the value '%s' cannot fit in a variable of type '%s'.",
498 xml_attrs[
"value"].value.c_str(),
D4type_name(d_enum_def->type()).c_str());
502 enum_def()->add_value(xml_attrs[
"name"].value, value);
513 inline bool D4ParserSax2::process_variable(
const char *name,
const xmlChar **attrs,
int nb_attributes)
517 process_variable_helper(t, inside_simple_type, attrs, nb_attributes);
522 case dods_structure_c:
523 process_variable_helper(t, inside_constructor, attrs, nb_attributes);
526 case dods_sequence_c:
527 process_variable_helper(t, inside_constructor, attrs, nb_attributes);
543 void D4ParserSax2::process_variable_helper(
Type t, ParseState s,
const xmlChar **attrs,
int nb_attributes)
545 transfer_xml_attrs(attrs, nb_attributes);
547 if (check_required_attribute(
"name")) {
550 dmr_fatal_error(
this,
"Could not instantiate the variable '%s'.", xml_attrs[
"name"].value.c_str());
554 if ((t == dods_enum_c) && check_required_attribute(
"enum")) {
555 D4EnumDef *enum_def = 0;
556 string enum_path = xml_attrs[
"enum"].value;
557 if (enum_path[0] ==
'/')
558 enum_def = dmr()->
root()->find_enum_def(enum_path);
560 enum_def = top_group()->find_enum_def(enum_path);
563 dmr_fatal_error(
this,
"Could not find the Enumeration definition '%s'.", enum_path.c_str());
565 static_cast<D4Enum*
>(btp)->set_enumeration(enum_def);
568 btp->set_is_dap4(
true);
571 push_attributes(btp->attributes());
591 parser->error_msg =
"";
592 parser->char_data =
"";
601 if (parser->debug()) cerr <<
"Parser start state: " << states[parser->get_state()] << endl;
610 if (parser->debug()) cerr <<
"Parser end state: " << states[parser->get_state()] << endl;
612 if (parser->get_state() != parser_end)
613 D4ParserSax2::dmr_error(parser,
"The document contained unbalanced tags.");
617 if (parser->get_state() == parser_error || parser->get_state() == parser_fatal_error)
620 if (!parser->empty_basetype() || parser->empty_group())
621 D4ParserSax2::dmr_error(parser,
"The document did not contain a valid root Group or contained unbalanced tags.");
624 parser->pop_attributes();
627 void D4ParserSax2::dmr_start_element(
void *p,
const xmlChar *l,
const xmlChar *prefix,
const xmlChar *URI,
628 int nb_namespaces,
const xmlChar **namespaces,
int nb_attributes,
int ,
629 const xmlChar **attributes)
632 const char *localname = (
const char *) l;
634 if (parser->debug()) cerr <<
"Start element " << localname <<
" (state " << states[parser->get_state()] <<
")" << endl;
636 switch (parser->get_state()) {
638 if (is_not(localname,
"Dataset"))
639 D4ParserSax2::dmr_error(parser,
"Expected DMR to start with a Dataset element; found '%s' instead.", localname);
641 parser->root_ns = URI ? (
const char *) URI :
"";
642 parser->transfer_xml_attrs(attributes, nb_attributes);
644 if (parser->check_required_attribute(
string(
"name")))
645 parser->dmr()->set_name(parser->xml_attrs[
"name"].value);
647 if (parser->check_attribute(
"dapVersion"))
650 if (parser->check_attribute(
"dmrVersion"))
651 parser->dmr()->set_dmr_version(parser->xml_attrs[
"dmrVersion"].value);
653 if (parser->check_attribute(
"base"))
656 if (!parser->root_ns.empty())
660 parser->push_group(parser->dmr()->
root());
662 parser->push_state(inside_dataset);
671 if (parser->process_enum_def(localname, attributes, nb_attributes))
672 parser->push_state(inside_enum_def);
673 else if (parser->process_dimension_def(localname, attributes, nb_attributes))
674 parser->push_state(inside_dim_def);
675 else if (parser->process_group(localname, attributes, nb_attributes))
676 parser->push_state(inside_group);
677 else if (parser->process_variable(localname, attributes, nb_attributes))
681 else if (parser->process_attribute(localname, attributes, nb_attributes))
686 D4ParserSax2::dmr_error(parser,
"Expected an Attribute, Enumeration, Dimension, Group or variable element; found '%s' instead.", localname);
689 case inside_attribute_container:
690 if (parser->process_attribute(localname, attributes, nb_attributes))
693 D4ParserSax2::dmr_error(parser,
"Expected an Attribute element; found '%s' instead.", localname);
696 case inside_attribute:
697 if (parser->process_attribute(localname, attributes, nb_attributes))
699 else if (strcmp(localname,
"Value") == 0)
700 parser->push_state(inside_attribute_value);
702 dmr_error(parser,
"Expected an 'Attribute' or 'Value' element; found '%s' instead.", localname);
705 case inside_attribute_value:
709 case inside_other_xml_attribute:
710 parser->other_xml_depth++;
713 parser->other_xml.append(
"<");
715 parser->other_xml.append((
const char *) prefix);
716 parser->other_xml.append(
":");
718 parser->other_xml.append(localname);
720 if (nb_namespaces != 0) {
721 parser->transfer_xml_ns(namespaces, nb_namespaces);
723 for (map<string, string>::iterator i = parser->namespace_table.begin();
724 i != parser->namespace_table.end(); ++i) {
725 parser->other_xml.append(
" xmlns");
726 if (!i->first.empty()) {
727 parser->other_xml.append(
":");
728 parser->other_xml.append(i->first);
730 parser->other_xml.append(
"=\"");
731 parser->other_xml.append(i->second);
732 parser->other_xml.append(
"\"");
736 if (nb_attributes != 0) {
737 parser->transfer_xml_attrs(attributes, nb_attributes);
738 for (XMLAttrMap::iterator i = parser->xml_attr_begin(); i != parser->xml_attr_end(); ++i) {
739 parser->other_xml.append(
" ");
740 if (!i->second.prefix.empty()) {
741 parser->other_xml.append(i->second.prefix);
742 parser->other_xml.append(
":");
744 parser->other_xml.append(i->first);
745 parser->other_xml.append(
"=\"");
746 parser->other_xml.append(i->second.value);
747 parser->other_xml.append(
"\"");
751 parser->other_xml.append(
">");
754 case inside_enum_def:
756 if (parser->process_enum_const(localname, attributes, nb_attributes))
757 parser->push_state(inside_enum_const);
759 dmr_error(parser,
"Expected an 'EnumConst' element; found '%s' instead.", localname);
762 case inside_enum_const:
770 case inside_dimension:
782 case inside_simple_type:
783 if (parser->process_attribute(localname, attributes, nb_attributes))
785 else if (parser->process_dimension(localname, attributes, nb_attributes))
786 parser->push_state(inside_dim);
787 else if (parser->process_map(localname, attributes, nb_attributes))
788 parser->push_state(inside_map);
790 dmr_error(parser,
"Expected an 'Attribute', 'Dim' or 'Map' element; found '%s' instead.", localname);
793 case inside_constructor:
794 if (parser->process_variable(localname, attributes, nb_attributes))
798 else if (parser->process_attribute(localname, attributes, nb_attributes))
800 else if (parser->process_dimension(localname, attributes, nb_attributes))
801 parser->push_state(inside_dim);
802 else if (parser->process_map(localname, attributes, nb_attributes))
803 parser->push_state(inside_map);
805 D4ParserSax2::dmr_error(parser,
"Expected an Attribute, Dim, Map or variable element; found '%s' instead.", localname);
811 parser->push_state(parser_unknown);
815 case parser_fatal_error:
823 if (parser->debug()) cerr <<
"Start element exit state: " << states[parser->get_state()] << endl;
826 void D4ParserSax2::dmr_end_element(
void *p,
const xmlChar *l,
const xmlChar *prefix,
const xmlChar *URI)
829 const char *localname = (
const char *) l;
832 cerr <<
"End element " << localname <<
" (state " << states[parser->get_state()] <<
")" << endl;
834 switch (parser->get_state()) {
836 dmr_fatal_error(parser,
"Unexpected state, inside start state while processing element '%s'.", localname);
840 if (is_not(localname,
"Dataset"))
841 D4ParserSax2::dmr_error(parser,
"Expected an end Dataset tag; found '%s' instead.", localname);
844 if (parser->get_state() != parser_start)
848 parser->push_state(parser_end);
853 if (is_not(localname,
"Group"))
854 D4ParserSax2::dmr_error(parser,
"Expected an end tag for a Group; found '%s' instead.", localname);
856 if (!parser->empty_basetype() || parser->empty_group())
857 D4ParserSax2::dmr_error(parser,
858 "The document did not contain a valid root Group or contained unbalanced tags.");
865 case inside_attribute_container:
866 if (is_not(localname,
"Attribute"))
867 D4ParserSax2::dmr_error(parser,
"Expected an end Attribute tag; found '%s' instead.", localname);
870 parser->pop_attributes();
873 case inside_attribute:
874 if (is_not(localname,
"Attribute"))
875 D4ParserSax2::dmr_error(parser,
"Expected an end Attribute tag; found '%s' instead.", localname);
880 case inside_attribute_value: {
881 if (is_not(localname,
"Value"))
882 D4ParserSax2::dmr_error(parser,
"Expected an end value tag; found '%s' instead.", localname);
892 attr =
new D4Attribute(parser->dods_attr_name, StringToD4AttributeType(parser->dods_attr_type));
893 attrs->add_attribute_nocopy(attr);
895 attr->add_value(parser->char_data);
897 parser->char_data =
"";
901 case inside_other_xml_attribute: {
902 if (strcmp(localname,
"Attribute") == 0 && parser->root_ns == (
const char *) URI) {
911 attr =
new D4Attribute(parser->dods_attr_name, StringToD4AttributeType(parser->dods_attr_type));
912 attrs->add_attribute_nocopy(attr);
914 attr->add_value(parser->other_xml);
916 parser->other_xml =
"";
919 if (parser->other_xml_depth == 0) {
920 D4ParserSax2::dmr_error(parser,
"Expected an OtherXML attribute to end! Instead I found '%s'",
924 parser->other_xml_depth--;
926 parser->other_xml.append(
"</");
928 parser->other_xml.append((
const char *) prefix);
929 parser->other_xml.append(
":");
931 parser->other_xml.append(localname);
932 parser->other_xml.append(
">");
937 case inside_enum_def:
938 if (is_not(localname,
"Enumeration"))
939 D4ParserSax2::dmr_error(parser,
"Expected an end Enumeration tag; found '%s' instead.", localname);
940 if (!parser->top_group())
942 "Expected a Group to be the current item, while finishing up an Enumeration.");
945 parser->top_group()->
enum_defs()->add_enum_nocopy(parser->enum_def());
948 parser->clear_enum_def();
953 case inside_enum_const:
954 if (is_not(localname,
"EnumConst"))
955 D4ParserSax2::dmr_error(parser,
"Expected an end EnumConst tag; found '%s' instead.", localname);
960 case inside_dim_def: {
961 if (is_not(localname,
"Dimension"))
962 D4ParserSax2::dmr_error(parser,
"Expected an end Dimension tag; found '%s' instead.", localname);
964 if (!parser->top_group())
965 D4ParserSax2::dmr_error(parser,
966 "Expected a Group to be the current item, while finishing up an Dimension.");
977 parser->clear_dim_def();
982 case inside_simple_type:
984 BaseType *btp = parser->top_basetype();
985 parser->pop_basetype();
986 parser->pop_attributes();
989 if (!parser->empty_basetype())
990 parent = parser->top_basetype();
991 else if (!parser->empty_group())
992 parent = parser->top_group();
994 dmr_fatal_error(parser,
"Both the Variable and Groups stacks are empty while closing a %s element.",
1001 if (parent->
type() == dods_array_c)
1002 static_cast<Array*>(parent)->prototype()->add_var_nocopy(btp);
1004 parent->add_var_nocopy(btp);
1007 D4ParserSax2::dmr_error(parser,
"Expected an end tag for a simple type; found '%s' instead.", localname);
1009 parser->pop_state();
1013 if (is_not(localname,
"Dim"))
1016 parser->pop_state();
1020 if (is_not(localname,
"Map"))
1023 parser->pop_state();
1026 case inside_constructor: {
1027 if (strcmp(localname,
"Structure") != 0 && strcmp(localname,
"Sequence") != 0) {
1028 D4ParserSax2::dmr_error(parser,
"Expected an end tag for a constructor; found '%s' instead.", localname);
1032 BaseType *btp = parser->top_basetype();
1033 parser->pop_basetype();
1034 parser->pop_attributes();
1037 if (!parser->empty_basetype())
1038 parent = parser->top_basetype();
1039 else if (!parser->empty_group())
1040 parent = parser->top_group();
1042 dmr_fatal_error(parser,
"Both the Variable and Groups stacks are empty while closing a %s element.",
1045 parser->pop_state();
1051 parent->add_var_nocopy(btp);
1052 parser->pop_state();
1056 case parser_unknown:
1057 parser->pop_state();
1061 case parser_fatal_error:
1069 if (parser->debug()) cerr <<
"End element exit state: " << states[parser->get_state()] << endl;
1079 switch (parser->get_state()) {
1080 case inside_attribute_value:
1081 parser->char_data.append((
const char *) (ch), len);
1082 DBG(cerr <<
"Characters: '" << parser->char_data <<
"'" << endl);
1085 case inside_other_xml_attribute:
1086 parser->other_xml.append((
const char *) (ch), len);
1087 DBG(cerr <<
"Other XML Characters: '" << parser->other_xml <<
"'" << endl);
1103 switch (parser->get_state()) {
1104 case inside_other_xml_attribute:
1105 parser->other_xml.append((
const char *) (ch), len);
1122 switch (parser->get_state()) {
1123 case inside_other_xml_attribute:
1124 parser->other_xml.append((
const char *) (value), len);
1127 case parser_unknown:
1131 D4ParserSax2::dmr_error(parser,
"Found a CData block but none are allowed by DAP4.");
1143 return xmlGetPredefinedEntity(name);
1161 parser->push_state(parser_fatal_error);
1163 va_start(args, msg);
1165 vsnprintf(str, 1024, msg, args);
1168 int line = xmlSAX2GetLineNumber(parser->context);
1170 if (!parser->error_msg.empty()) parser->error_msg +=
"\n";
1171 parser->error_msg +=
"At line " + long_to_string(line) +
": " + string(str);
1174 void D4ParserSax2::dmr_error(
void *p,
const char *msg, ...)
1179 parser->push_state(parser_error);
1181 va_start(args, msg);
1183 vsnprintf(str, 1024, msg, args);
1186 int line = xmlSAX2GetLineNumber(parser->context);
1188 if (!parser->error_msg.empty()) parser->error_msg +=
"\n";
1189 parser->error_msg +=
"At line " + long_to_string(line) +
": " + string(str);
1196 void D4ParserSax2::cleanup_parse()
1198 bool wellFormed = context->wellFormed;
1199 bool valid = context->valid;
1201 context->sax = NULL;
1202 xmlFreeParserCtxt(context);
1212 while (!btp_stack.empty()) {
1213 delete top_basetype();
1218 throw Error(
"The DMR was not well formed. " + error_msg);
1220 throw Error(
"The DMR was not valid." + error_msg);
1221 else if (get_state() == parser_error)
1222 throw Error(error_msg);
1223 else if (get_state() == parser_fatal_error)
1241 void D4ParserSax2::intern(istream &f,
DMR *dest_dmr,
bool debug)
1248 throw Error(
"Input stream not open or read error");
1250 throw InternalErr(__FILE__, __LINE__,
"DMR object is null");
1254 const int size = 1024;
1258 f.getline(chars, size);
1259 int res = f.gcount();
1260 if (res == 0)
throw Error(
"No input found while parsing the DMR.");
1262 if (debug) cerr <<
"line: (" << line++ <<
"): " << chars << endl;
1264 context = xmlCreatePushParserCtxt(&ddx_sax_parser,
this, chars, res - 1,
"stream");
1265 context->validate =
true;
1266 push_state(parser_start);
1268 f.getline(chars, size);
1269 while ((f.gcount() > 0) && (get_state() != parser_end)) {
1270 if (debug) cerr <<
"line: (" << line++ <<
"): " << chars << endl;
1271 xmlParseChunk(context, chars, f.gcount() - 1, 0);
1272 f.getline(chars, size);
1276 xmlParseChunk(context, chars, 0, 1);
1293 void D4ParserSax2::intern(
const string &document,
DMR *dest_dmr,
bool debug)
1295 intern(document.c_str(), document.length(), dest_dmr, debug);
1308 void D4ParserSax2::intern(
const char *buffer,
int size,
DMR *dest_dmr,
bool debug)
1310 if (!(size > 0))
return;
1316 if (!dest_dmr)
throw InternalErr(__FILE__, __LINE__,
"DMR object is null");
1319 push_state(parser_start);
1320 context = xmlCreatePushParserCtxt(&ddx_sax_parser,
this, buffer, size,
"stream");
1321 context->validate =
true;
1326 xmlParseChunk(context, buffer, 0, 1);
virtual BaseType * NewVariable(Type t, const string &name) const
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.
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)
virtual Type type() const
Returns the type of the class instance.
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)
virtual std::string FQN() const
D4Attribute * get(const string &fqn)
A class for error processing.
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.