Skip to content

Commit 19a61c1

Browse files
committed
Force FieldML validate function to use a custom external entity loader to get around the internet requirement.
1 parent 23acfc3 commit 19a61c1

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

core/src/FieldmlDOM.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <libxml/parser.h>
5050
#include <libxml/xmlmemory.h>
5151
#include <libxml/xmlschemas.h>
52+
#include <libxml/parserInternals.h>
5253

5354
#include "ErrorContextAutostack.h"
5455
#include "Util.h"
@@ -113,6 +114,24 @@ static void addContextError( void *context, const char *msg, ... )
113114

114115
//========================================================================
115116

117+
xmlExternalEntityLoader defaultLoader = 0;
118+
119+
120+
xmlParserInputPtr
121+
xmlMyExternalEntityLoader(const char *URL, const char *ID,
122+
xmlParserCtxtPtr ctxt) {
123+
xmlParserInputPtr ret = 0;
124+
125+
if (0 == strcmp(URL, "http://www.cellml.org/tools/cellml_1_1_schema/common/xlink-href.xsd"))
126+
ret = xmlNewStringInputStream(ctxt, (const xmlChar *)HREF_STRING_XSD);
127+
if (ret != NULL)
128+
return(ret);
129+
if (defaultLoader != NULL)
130+
ret = defaultLoader(URL, ID, ctxt);
131+
return(ret);
132+
}
133+
134+
116135
static int validate( FieldmlErrorHandler *errorHandler, xmlParserInputBufferPtr buffer, const char *resourceName )
117136
{
118137
xmlSchemaPtr schemas = NULL;
@@ -123,6 +142,11 @@ static int validate( FieldmlErrorHandler *errorHandler, xmlParserInputBufferPtr
123142

124143
xmlSubstituteEntitiesDefault( 1 );
125144

145+
if (!defaultLoader)
146+
defaultLoader = xmlGetExternalEntityLoader();
147+
148+
xmlSetExternalEntityLoader(xmlMyExternalEntityLoader);
149+
126150
if( buffer == NULL )
127151
{
128152
return 1;

core/src/String_InternalXSD.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@
4141

4242
#include "String_InternalXSD.h"
4343

44+
const char * const HREF_STRING_XSD = "<schema targetNamespace=\"http://www.w3.org/1999/xlink\" \
45+
xmlns:xlink=\"http://www.w3.org/1999/xlink\" \
46+
xmlns=\"http://www.w3.org/2001/XMLSchema\"> \
47+
<annotation> \
48+
<documentation xml:lang=\"en\"> \
49+
This schema provides the XLink href attribute for use in the MathML2 \
50+
schema. Written by Max Froumentin, W3C. \
51+
</documentation> \
52+
</annotation> \
53+
\
54+
<attribute name=\"href\" type=\"anyURI\"/>\
55+
</schema> \
56+
";
57+
58+
4459
const char * const FML_STRING_FIELDML_XSD_LOCATION = "http://www.fieldml.org/resources/xml/0.5/FieldML_0.5.xsd";
4560

4661
const char * const FML_STRING_FIELDML_XSD = "<?xml version=\"1.0\" encoding=\"utf-8\"?> \
@@ -49,8 +64,8 @@ const char * const FML_STRING_FIELDML_XSD = "<?xml version=\"1.0\" encoding=\"ut
4964
xmlns:xlink=\"http://www.w3.org/1999/xlink\" \
5065
> \
5166
\
52-
<xs:import namespace=\"http://www.w3.org/1999/xlink\" \
53-
schemaLocation=\"http://www.cellml.org/tools/cellml_1_1_schema/common/xlink-href.xsd\" /> \
67+
<xs:import namespace=\"http://www.w3.org/1999/xlink\" \
68+
schemaLocation=\"http://www.cellml.org/tools/cellml_1_1_schema/common/xlink-href.xsd\" /> \
5469
\
5570
<xs:complexType name=\"FieldmlRdfTargetType\"> \
5671
<xs:attribute name=\"id\" type=\"xs:string\" form=\"qualified\" use=\"optional\"/> \

core/src/String_InternalXSD.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#ifndef H_STRING_INTERNAL_XSD_H
4343
#define H_STRING_INTERNAL_XSD_H
4444

45+
extern const char * const HREF_STRING_XSD;
46+
4547
extern const char * const FML_STRING_FIELDML_XSD_LOCATION;
4648

4749
extern const char * const FML_STRING_FIELDML_XSD;

0 commit comments

Comments
 (0)