From 24f1a9a269a86a0c11c666e51223ed97f8d0d571 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sat, 26 Sep 2009 21:50:55 +0000 Subject: Minor cleanup, added error checking. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@819223 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/sca/runtime/core/test/tuscany/xml-test.cpp | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'cpp/sca/runtime/core/test/tuscany/xml-test.cpp') 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; -- cgit v1.2.3