31 for ( node = parent->xmlChildrenNode; node; node=node->next )
32 if ( !xmlStrcmp(node->name, BAD_CAST tag) )
54 for ( node = parent->xmlChildrenNode; node && result==0; node=node->next ) {
55 if ( !xmlStrcmp(node->name, BAD_CAST tag) )
76 xmlNodePtr node = NULL;
78 for ( node = parent->xmlChildrenNode; node; node = node->next )
79 if ( !xmlStrcmp(node->name, BAD_CAST tag) )
83 cerr <<
"Node " << tag <<
" of parent " << parent->name <<
" not found!" << endl;
105 if ( !node )
return -1;
107 xmlChar* content = xmlNodeGetContent(node);
109 if ( !content )
return 0;
111 strcpy(
string, (
char *)content);
116 cout <<
"DEBUG xml_copy_string: tag=" << tag <<
" string=" <<
string <<
" (" << strlen(
string) <<
")" << endl;
133 xmlChar* content = xmlGetProp(parent, BAD_CAST tag);
137 if ( !content )
return value;
139 value = (
char *)content;
144 cout <<
"DEBUG xml_get_string_attribute: tag=" << tag <<
" value=" << value << endl;
161 xmlChar* content = xmlGetProp(parent, BAD_CAST tag);
163 if ( !content )
return 0;
165 long value = atol((
char *)content);
170 cout <<
"DEBUG xml_get_integer_attribute: tag=" << tag <<
" value=" << value << endl;
187 xmlChar* content = xmlGetProp(parent, BAD_CAST tag);
189 if ( !content )
return 0;
191 double value = atof((
char *)content);
196 cout <<
"DEBUG xml_get_real_attribute: tag=" << tag <<
" value=" << value << endl;
218 if ( !node )
return s;
220 xmlChar* content = xmlNodeGetContent(node);
222 if ( !content )
return s;
224 s = (
char *) content;
229 cout <<
"DEBUG xml_get_string: tag=" << tag <<
" s=" << s <<
" (" << s.length() <<
")" << endl;
250 if ( !node )
return value;
252 xmlChar* content = xmlNodeGetContent(node);
254 if ( !content )
return value;
256 value = atol((
char *)content);
261 cout <<
"DEBUG xml_get_integer: tag=" << tag <<
" value=" << value << endl;
282 if ( !node )
return value;
284 xmlChar* content = xmlNodeGetContent(node);
286 if ( !content )
return value;
288 value = atof((
char *)content);
293 cout <<
"DEBUG xml_get_real: tag=" << tag <<
" value=" << value << endl;
314 xmlStrPrintf(s, 256, (
xmlFormat) format, value);
316 xmlAttrPtr attr = xmlNewProp(parent, BAD_CAST tag, BAD_CAST s);
319 cout <<
"DEBUG xml_set_integer_attribute: tag=" << tag <<
" string=" << s <<
" (" << xmlStrlen(s) <<
")" << endl;
340 xmlStrPrintf(s, 256, (
xmlFormat) format, value);
342 xmlAttrPtr attr = xmlNewProp(parent, BAD_CAST tag, BAD_CAST s);
345 cout <<
"DEBUG xml_set_real_attribute: tag=" << tag <<
" string=" << s <<
" (" << xmlStrlen(s) <<
")" << endl;
362 xmlNodePtr
xml_set_integer(xmlNodePtr parent,
const char* tag,
long value,
const char* format)
366 xmlStrPrintf(s, 256, (
xmlFormat) format, value);
368 xmlNodePtr node = xmlNewChild(parent, NULL, BAD_CAST tag, BAD_CAST s);
371 cout <<
"DEBUG xml_set_integer: tag=" << tag <<
" string=" << s <<
" (" << xmlStrlen(s) <<
")" << endl;
388 xmlNodePtr
xml_set_real(xmlNodePtr parent,
const char* tag,
double value,
const char* format)
392 xmlStrPrintf(s, 256, (
xmlFormat) format, value);
394 xmlNodePtr node = xmlNewChild(parent, NULL, BAD_CAST tag, BAD_CAST s);
397 cout <<
"DEBUG xml_set_real: tag=" << tag <<
" string=" << s <<
" (" << xmlStrlen(s) <<
")" << endl;
414 if ( xsdfile.
length() < 1 )
return 0;
416 xmlDocPtr schema_doc = xmlParseFile(xsdfile.
c_str());
419 cerr <<
"Error: the schema cannot be loaded or is not well-formed" << endl;
423 xmlSchemaParserCtxtPtr parser_ctxt = xmlSchemaNewDocParserCtxt(schema_doc);
424 if ( !parser_ctxt ) {
425 cerr <<
"Error: unable to create a parser context for the schema" << endl;
426 xmlFreeDoc(schema_doc);
430 xmlSchemaPtr schema = xmlSchemaParse(parser_ctxt);
432 cerr <<
"Error: the schema is not valid" << endl;
433 xmlSchemaFreeParserCtxt(parser_ctxt);
434 xmlFreeDoc(schema_doc);
438 xmlSchemaValidCtxtPtr valid_ctxt = xmlSchemaNewValidCtxt(schema);
440 cerr <<
"Error: unable to create a validation context for the schema" << endl;
441 xmlSchemaFree(schema);
442 xmlSchemaFreeParserCtxt(parser_ctxt);
443 xmlFreeDoc(schema_doc);
448 cout <<
"DEBUG xml_validate: file=" << xsdfile << endl;
450 int is_valid = (xmlSchemaValidateDoc(valid_ctxt, doc) == 0);
454 if ( is_valid ) cout <<
"valid";
455 else cout <<
"not valid";
456 cout <<
" (" << xsdfile <<
")" << endl;
459 xmlSchemaFreeValidCtxt(valid_ctxt);
460 xmlSchemaFree(schema);
461 xmlSchemaFreeParserCtxt(parser_ctxt);
462 xmlFreeDoc(schema_doc);
465 return is_valid ? 1 : 0;