Commit d11ee071 authored by Kenneth Leiter's avatar Kenneth Leiter

BUG: Fix infinite loop in XdmfCoreReader.cpp

XdmfCoreReader.cpp had a bug that resulted in an infinite loop when
resolving xincludes. This bug was fixed. Added ability for xincludes
to resolve href links (links to other files).

Fixed formatting in XdmfWriter.cpp
parent f73576ec
......@@ -21,6 +21,7 @@
/* */
/*****************************************************************************/
#include <libxml/uri.h>
#include <libxml/xpointer.h>
#include <libxml/xmlreader.h>
#include <map>
......@@ -32,6 +33,8 @@
#include "XdmfSystemUtils.hpp"
#include "XdmfError.hpp"
#include <fstream>
/**
* PIMPL
*/
......@@ -107,27 +110,47 @@ public:
while(currNode != NULL) {
if(currNode->type == XML_ELEMENT_NODE) {
xmlChar * xpointer = NULL;
if(xmlStrcmp(currNode->name, (xmlChar*)"include") == 0) {
// Deal with proper reading of XIncludes
xmlChar * xpointer = NULL;
xmlChar * href = NULL;
xmlAttrPtr currAttribute = currNode->properties;
while(currAttribute != NULL) {
if(xmlStrcmp(currAttribute->name, (xmlChar*)"xpointer") == 0) {
xpointer = currAttribute->children->content;
break;
}
if(xmlStrcmp(currAttribute->name, (xmlChar*)"href") == 0) {
href = currAttribute->children->content;
}
currAttribute = currAttribute->next;
}
xmlDocPtr document = NULL;
xmlXPathContextPtr context = mXPathContext;
if(href) {
xmlChar * filePath = xmlBuildURI(href, mDocument->URL);
document = xmlReadFile((char*)filePath, NULL, 0);
context = xmlXPtrNewContext(document, NULL, NULL);
}
if(xpointer) {
xmlXPathObjectPtr xPathObject =
xmlXPtrEval(xpointer, mXPathContext);
if(xPathObject && xPathObject->nodesetval) {
for(int i=0; i<xPathObject->nodesetval->nodeNr; ++i) {
this->readSingleNode(xPathObject->nodesetval->nodeTab[i],
xmlXPathObjectPtr result = xmlXPtrEval(xpointer, context);
if(result && !xmlXPathNodeSetIsEmpty(result->nodesetval)) {
for(int i=0; i<result->nodesetval->nodeNr; ++i) {
this->readSingleNode(result->nodesetval->nodeTab[i],
myItems);
}
}
xmlXPathFreeObject(xPathObject);
xmlXPathFreeObject(result);
}
if(href) {
xmlXPathFreeContext(context);
xmlFreeDoc(document);
}
}
else {
// Normal reading
......@@ -136,6 +159,7 @@ public:
}
currNode = currNode->next;
}
return myItems;
}
......
......@@ -77,7 +77,7 @@ public:
xmlBufferPtr buffer = xmlBufferCreate();
xmlOutputBuffer * outputBuffer = xmlOutputBufferCreateBuffer(buffer,
NULL);
NULL);
xmlSaveFormatFileTo(outputBuffer,
mXMLDocument,
"utf-8",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment