summaryrefslogtreecommitdiffstats
path: root/cpp/sca/runtime/core/test/tuscany/xml-test.cpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-09-26 21:50:55 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-09-26 21:50:55 +0000
commit24f1a9a269a86a0c11c666e51223ed97f8d0d571 (patch)
treeada8ee99dbb46df2baaeeabad11a6c2ae96c13db /cpp/sca/runtime/core/test/tuscany/xml-test.cpp
parent9ccef7bf93087dca915384e99dc1a51d312432d7 (diff)
Minor cleanup, added error checking.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@819223 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/sca/runtime/core/test/tuscany/xml-test.cpp')
-rw-r--r--cpp/sca/runtime/core/test/tuscany/xml-test.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/cpp/sca/runtime/core/test/tuscany/xml-test.cpp b/cpp/sca/runtime/core/test/tuscany/xml-test.cpp
index af2308a321..818c03ba68 100644
--- a/cpp/sca/runtime/core/test/tuscany/xml-test.cpp
+++ b/cpp/sca/runtime/core/test/tuscany/xml-test.cpp
@@ -54,30 +54,33 @@ int xmlClose(void *context) {
}
bool readFile(const char*xsdfilename, const char *filename) {
- std::cout << "Loading schemas\n";
+ std::cout << "Loading schemas...\n";
const xmlDocPtr xsddoc = xmlReadFile(xsdfilename, NULL, XML_PARSE_NONET);
const xmlSchemaParserCtxtPtr xsdctx = xmlSchemaNewDocParserCtxt(xsddoc);
const xmlSchemaPtr xsd = xmlSchemaParse(xsdctx);
const xmlSchemaValidCtxtPtr validctx = xmlSchemaNewValidCtxt(xsd);
- std::cout << "Loaded schemas\n";
+ std::cout << "Reading file...\n";
FILE* file = fopen(filename, "r");
- const xmlTextReaderPtr reader = xmlReaderForIO(xmlRead, xmlClose, file, filename, NULL, XML_PARSE_NONET);
- xmlTextReaderSetParserProp(reader, XML_PARSER_DEFAULTATTRS, 1);
- xmlTextReaderSetParserProp(reader, XML_PARSER_SUBST_ENTITIES, 1);
-
- if(reader != NULL) {
- xmlTextReaderSchemaValidateCtxt(reader, validctx, 0);
-
- int rc;
- while((rc = xmlTextReaderRead(reader)) == 0) {
- printNode(reader);
- }
- if(xmlTextReaderIsValid(reader) != 1)
- std::cout << "Could not validate document" << std::endl;
- xmlFreeTextReader(reader);
- if(rc != 0)
- std::cout << "Could not parse document" << std::endl;
+ if (file != NULL) {
+ const xmlTextReaderPtr reader = xmlReaderForIO(xmlRead, xmlClose, file, filename, NULL, XML_PARSE_NONET);
+ xmlTextReaderSetParserProp(reader, XML_PARSER_DEFAULTATTRS, 1);
+ xmlTextReaderSetParserProp(reader, XML_PARSER_SUBST_ENTITIES, 1);
+
+ if(reader != NULL) {
+ xmlTextReaderSchemaValidateCtxt(reader, validctx, 0);
+
+ int rc;
+ while((rc = xmlTextReaderRead(reader)) == 1) {
+ printNode(reader);
+ }
+ if(xmlTextReaderIsValid(reader) != 1)
+ std::cout << "Could not validate document" << std::endl;
+ xmlFreeTextReader(reader);
+ if(rc != 0)
+ std::cout << "Could not parse document" << std::endl;
+ } else
+ std::cout << "Could not create parser" << std::endl;
} else
std::cout << "Could not open document" << std::endl;