1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-28 07:21:26 +03:00

applied patch from Robert Stepanek to start import os schemas support,

* xmlschemas.c: applied patch from Robert Stepanek to start
  import os schemas support, cleaned up stuff and the patch.
* test/schemas/import0_0.* result/schemas/import0_0_0*: added test
  to regression, fixed a few regressions too.
Daniel
This commit is contained in:
Daniel Veillard 2003-11-21 00:28:39 +00:00
parent c59d826ef9
commit 1d91386313
10 changed files with 222 additions and 32 deletions

View File

@ -1,3 +1,10 @@
Fri Nov 21 01:26:00 CET 2003 Daniel Veillard <daniel@veillard.com>
* xmlschemas.c: applied patch from Robert Stepanek to start
import os schemas support, cleaned up stuff and the patch.
* test/schemas/import0_0.* result/schemas/import0_0_0*: added test
to regression, fixed a few regressions too.
Thu Nov 20 22:58:00 CET 2003 Daniel Veillard <daniel@veillard.com>
* HTMLparser.c: applied two parsing fixes from James Bursa

View File

@ -31,9 +31,11 @@ EXTRA_DIST=xmlcatalog_man.xml tutorial/*.html tutorial/*.c tutorial/*.pdf \
man_MANS = xmllint.1 xmlcatalog.1
all: api web $(top_srcdir)/NEWS libxml2.xsa $(man_MANS)
all: web $(top_srcdir)/NEWS libxml2.xsa $(man_MANS)
web: $(PAGES) $(APIPAGES) $(srcdir)/html/index.html
api: libxml2-api.xml libxml2-refs.xml $(APIPAGES) $(srcdir)/html/index.html $(WIN32_DIR)/libxml2.def.src
web: $(PAGES)
$(PAGES): xml.html site.xsl
-@(if [ -x $(bindir)/xsltproc ] ; then \
@ -69,8 +71,6 @@ $(srcdir)/html/index.html: libxml2-api.xml $(srcdir)/newapi.xsl
echo "Validating the resulting XHTML pages" ; \
$(bindir)/xmllint --nonet --valid --noout html/*.html ; fi );
api: libxml2-api.xml libxml2-refs.xml $(WIN32_DIR)/libxml2.def.src
$(WIN32_DIR)/libxml2.def.src: libxml2-api.xml
-@(if [ -x $(bindir)/xsltproc ] ; then \
$(bindir)/xsltproc -o $(WIN32_DIR)/libxml2.def.src \
@ -91,7 +91,7 @@ clean-local:
maintainer-clean-local: clean
rm -rf libxml-decl-list.txt libxml-decl.txt
rebuild: api web
rebuild: api all
install-data-local:
$(mkinstalldirs) $(DESTDIR)$(TARGET_DIR)

View File

@ -0,0 +1 @@
./test/schemas/import0_0.xml validates

View File

View File

@ -1,2 +1 @@
compilation error
Schemas: element size type non-positive-integer not found
./test/schemas/length3_0.xsd:5: element element: Schemas parser error : Schemas: element size type non-positive-integer not found

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://example.net/xmlschema2"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example.net/xmlschema2"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:simpleType name="tfoo">
<xs:restriction base="xs:NMTOKEN">
<xs:maxLength value="2"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<bar xmlns="http://example.net/xmlschema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.net/xmlschema testImportTypes.xsd">
<foo1>
xy
</foo1>
</bar>

View File

@ -1,17 +1,21 @@
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:my="uri:mywork" targetNamespace="uri:mywork">
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://example.net/xmlschema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://example.net/xmlschema"
xmlns:ns2="http://example.net/xmlschema2"
xmlns="http://example.net/xmlschema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<import namespace="http://www.w3.org/1999/xhtml"/>
<xs:import namespace="http://example.net/xmlschema2"
schemaLocation="import0_0.imp"/>
<annotation>
<documentation>
<html:p>[Some documentation for my schema]</html:p>
</documentation>
</annotation>
<complexType name="myType">
<sequence>
<element ref="html:p" minOccurs="0"/>
</sequence>
</complexType>
<element name="myElt" type="my:myType"/>
</schema>
<xs:element name="bar">
<xs:complexType>
<xs:sequence>
<xs:element name="foo1" type="ns2:tfoo"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@ -133,6 +133,15 @@ struct _xmlSchemaValidCtxt {
xmlSchemaAttrStatePtr attr;
};
/*
* These are the entries in the schemas importSchemas hash table
*/
typedef struct _xmlSchemaImport xmlSchemaImport;
typedef xmlSchemaImport *xmlSchemaImportPtr;
struct _xmlSchemaImport {
const xmlChar *schemaLocation;
xmlSchemaPtr schema;
};
/************************************************************************
* *
@ -397,6 +406,23 @@ xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot)
xmlFree(annot);
}
/**
* xmlSchemaFreeImport:
* @import: a schema import structure
*
* Deallocate an import structure
*/
static void
xmlSchemaFreeImport(xmlSchemaImportPtr import)
{
if (import == NULL)
return;
xmlSchemaFree(import->schema);
xmlFree((xmlChar *) import->schemaLocation);
xmlFree(import);
}
/**
* xmlSchemaFreeNotation:
* @schema: a schema notation structure
@ -522,6 +548,8 @@ xmlSchemaFreeType(xmlSchemaTypePtr type)
return;
if (type->name != NULL)
xmlFree((xmlChar *) type->name);
if (type->ref != NULL)
xmlFree((xmlChar *) type->ref);
if (type->base != NULL)
xmlFree((xmlChar *) type->base);
if (type->baseNs != NULL)
@ -577,6 +605,9 @@ xmlSchemaFree(xmlSchemaPtr schema)
if (schema->groupDecl != NULL)
xmlHashFree(schema->groupDecl,
(xmlHashDeallocator) xmlSchemaFreeType);
if (schema->schemasImports != NULL)
xmlHashFree(schema->schemasImports,
(xmlHashDeallocator) xmlSchemaFreeImport);
if (schema->annot != NULL)
xmlSchemaFreeAnnot(schema->annot);
if (schema->doc != NULL)
@ -845,6 +876,7 @@ xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name,
const xmlChar * namespace)
{
xmlSchemaTypePtr ret;
xmlSchemaImportPtr import;
if (name == NULL)
return (NULL);
@ -854,6 +886,11 @@ xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name,
return (ret);
}
ret = xmlSchemaGetPredefinedType(name, namespace);
if (ret != NULL)
return (ret);
import = xmlHashLookup(schema->schemasImports, namespace);
if (import != NULL)
ret = xmlSchemaGetType(import->schema, name, namespace);
#ifdef DEBUG
if (ret == NULL) {
if (namespace == NULL)
@ -2216,8 +2253,10 @@ xmlSchemaParseGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
name = xmlStrdup((xmlChar *) buf);
}
type = xmlSchemaAddGroup(ctxt, schema, name);
xmlFree(name);
if (type == NULL)
return (NULL);
type->node = node;
type->type = XML_SCHEMA_TYPE_GROUP;
type->id = xmlGetProp(node, BAD_CAST "id");
@ -2318,6 +2357,63 @@ xmlSchemaParseAll(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
return (type);
}
/**
* xmlSchemaImportSchema
*
* @ctxt: a schema validation context
* @schemaLocation: an URI defining where to find the imported schema
*
* import a XML schema
* *WARNING* this interface is highly subject to change
*
* Returns -1 in case of error and 1 in case of success.
*/
static xmlSchemaImportPtr
xmlSchemaImportSchema(xmlSchemaParserCtxtPtr ctxt,
const xmlChar *schemaLocation)
{
xmlSchemaImportPtr import;
xmlSchemaParserCtxtPtr newctxt;
newctxt = xmlSchemaNewParserCtxt((const char *) schemaLocation);
if (newctxt == NULL) {
xmlSchemaPErrMemory(NULL, "allocating parser context",
NULL);
return (NULL);
}
xmlSchemaSetParserErrors(newctxt, ctxt->error, ctxt->warning,
ctxt->userData);
import = (xmlSchemaImport*) xmlMalloc(sizeof(xmlSchemaImport));
if (import == NULL) {
xmlSchemaPErrMemory(NULL, "allocating imported schema",
NULL);
xmlSchemaFreeParserCtxt(newctxt);
return (NULL);
}
memset(import, 0, sizeof(xmlSchemaImport));
import->schemaLocation = xmlStrdup(schemaLocation);
import->schema = xmlSchemaParse(newctxt);
if (import->schema == NULL) {
/* FIXME use another error enum here ? */
xmlSchemaPErr(ctxt, NULL, XML_SCHEMAS_ERR_INTERNAL,
"failed to import schema at location %s\n",
schemaLocation, NULL);
xmlSchemaFreeParserCtxt(newctxt);
if (import->schemaLocation != NULL)
xmlFree((xmlChar *)import->schemaLocation);
xmlFree(import);
return NULL;
}
xmlSchemaFreeParserCtxt(newctxt);
return import;
}
/**
* xmlSchemaParseImport:
* @ctxt: a schema validation context
@ -2335,11 +2431,13 @@ xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
xmlNodePtr node)
{
xmlNodePtr child = NULL;
xmlSchemaImportPtr import = NULL;
xmlChar *namespace;
xmlChar *schemaLocation;
xmlChar *previous;
const xmlChar *previous;
xmlURIPtr check;
if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
return (-1);
@ -2359,6 +2457,8 @@ xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
}
schemaLocation = xmlGetProp(node, BAD_CAST "schemaLocation");
if (schemaLocation != NULL) {
xmlChar *base = NULL;
xmlChar *URI = NULL;
check = xmlParseURI((const char *) schemaLocation);
if (check == NULL) {
xmlSchemaPErr2(ctxt, node, child,
@ -2372,6 +2472,17 @@ xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
} else {
xmlFreeURI(check);
}
base = xmlNodeGetBase(node->doc, node);
if (base == NULL) {
URI = xmlBuildURI(schemaLocation, node->doc->URL);
} else {
URI = xmlBuildURI(schemaLocation, base);
}
if (base != NULL) xmlFree(base);
if (URI != NULL) {
xmlFree(schemaLocation);
schemaLocation = URI;
}
}
if (schema->schemasImports == NULL) {
schema->schemasImports = xmlHashCreate(10);
@ -2388,8 +2499,13 @@ xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
}
}
if (namespace == NULL) {
previous = xmlHashLookup(schema->schemasImports,
XML_SCHEMAS_DEFAULT_NAMESPACE);
import = xmlHashLookup(schema->schemasImports,
XML_SCHEMAS_DEFAULT_NAMESPACE);
if (import != NULL)
previous = import->schemaLocation;
else
previous = NULL;
if (schemaLocation != NULL) {
if (previous != NULL) {
if (!xmlStrEqual(schemaLocation, previous)) {
@ -2399,13 +2515,27 @@ xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
schemaLocation, NULL);
}
} else {
import = xmlSchemaImportSchema(ctxt, schemaLocation);
if (import == NULL) {
if (schemaLocation != NULL)
xmlFree(schemaLocation);
if (namespace != NULL)
xmlFree(namespace);
return (-1);
}
xmlHashAddEntry(schema->schemasImports,
XML_SCHEMAS_DEFAULT_NAMESPACE,
schemaLocation);
import);
}
xmlFree(schemaLocation);
}
} else {
previous = xmlHashLookup(schema->schemasImports, namespace);
import = xmlHashLookup(schema->schemasImports, namespace);
if (import != NULL)
previous = import->schemaLocation;
else
previous = NULL;
if (schemaLocation != NULL) {
if (previous != NULL) {
if (!xmlStrEqual(schemaLocation, previous)) {
@ -2415,11 +2545,22 @@ xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
namespace, schemaLocation);
}
} else {
import = xmlSchemaImportSchema(ctxt, schemaLocation);
if (import == NULL) {
if (schemaLocation != NULL)
xmlFree(schemaLocation);
if (namespace != NULL)
xmlFree(namespace);
return (-1);
}
xmlHashAddEntry(schema->schemasImports,
namespace, schemaLocation);
namespace, import);
}
}
xmlFree(namespace);
}
if (schemaLocation != NULL)
xmlFree(schemaLocation);
child = node->children;
while (IS_SCHEMA(child, "annotation")) {
@ -4271,6 +4412,7 @@ xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
xmlSchemaPErr(ctxt, (xmlNodePtr) doc,
XML_SCHEMAP_NOROOT,
"schemas has no root", NULL, NULL);
xmlFreeDoc(doc);
return (NULL);
}
@ -4338,8 +4480,10 @@ xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
* Then do the parsing for good
*/
ret = xmlSchemaParseSchema(ctxt, root);
if (ret == NULL)
if (ret == NULL) {
xmlFreeDoc(doc);
return (NULL);
}
ret->doc = doc;
/*

View File

@ -217,7 +217,8 @@ xmlNewTextWriterMemory(xmlBufferPtr buf, int compression ATTRIBUTE_UNUSED)
* Returns the new xmlTextWriterPtr or NULL in case of error
*/
xmlTextWriterPtr
xmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt, int compression)
xmlNewTextWriterPushParser(xmlParserCtxtPtr ctxt,
int compression ATTRIBUTE_UNUSED)
{
xmlTextWriterPtr ret;
xmlOutputBufferPtr out;
@ -273,7 +274,7 @@ xmlNewTextWriterDoc(xmlDocPtr * doc, int compression)
return NULL;
}
ctxt->myDoc = xmlNewDoc(XML_DEFAULT_VERSION);
ctxt->myDoc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
if (ctxt->myDoc == NULL) {
xmlFreeParserCtxt(ctxt);
xmlGenericError(xmlGenericErrorContext,
@ -552,6 +553,7 @@ xmlTextWriterEndDocument(xmlTextWriterPtr writer)
* xmlTextWriterWriteFormatComment:
* @writer: the xmlTextWriterPtr
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write an xml comment.
*
@ -929,6 +931,7 @@ xmlTextWriterFullEndElement(xmlTextWriterPtr writer)
* xmlTextWriterWriteFormatRaw:
* @writer: the xmlTextWriterPtr
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted raw xml text.
*
@ -1066,6 +1069,7 @@ xmlTextWriterWriteRaw(xmlTextWriterPtr writer, const xmlChar * content)
* xmlTextWriterWriteFormatString:
* @writer: the xmlTextWriterPtr
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted xml text.
*
@ -1644,6 +1648,7 @@ xmlTextWriterEndAttribute(xmlTextWriterPtr writer)
* @writer: the xmlTextWriterPtr
* @name: attribute name
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted xml attribute.
*
@ -1738,6 +1743,7 @@ xmlTextWriterWriteAttribute(xmlTextWriterPtr writer, const xmlChar * name,
* @name: attribute local name
* @namespaceURI: namespace URI
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted xml attribute.with namespace support
*
@ -1859,6 +1865,7 @@ xmlTextWriterWriteAttributeNS(xmlTextWriterPtr writer,
* @writer: the xmlTextWriterPtr
* @name: element name
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted xml element.
*
@ -1953,6 +1960,7 @@ xmlTextWriterWriteElement(xmlTextWriterPtr writer, const xmlChar * name,
* @name: element local name
* @namespaceURI: namespace URI
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted xml element with namespace support.
*
@ -2193,6 +2201,7 @@ xmlTextWriterEndPI(xmlTextWriterPtr writer)
* @writer: the xmlTextWriterPtr
* @target: PI target
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted PI.
*
@ -2401,6 +2410,7 @@ xmlTextWriterEndCDATA(xmlTextWriterPtr writer)
* xmlTextWriterWriteFormatCDATA:
* @writer: the xmlTextWriterPtr
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted xml CDATA.
*
@ -2655,6 +2665,7 @@ xmlTextWriterEndDTD(xmlTextWriterPtr writer)
* @pubid: the public identifier, which is an alternative to the system identifier
* @sysid: the system identifier, which is the URI of the DTD
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a DTD with a formatted markup declarations part.
*
@ -2840,6 +2851,7 @@ xmlTextWriterStartDTDElement(xmlTextWriterPtr writer, const xmlChar * name)
* @writer: the xmlTextWriterPtr
* @name: the name of the DTD element
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted DTD element.
*
@ -3024,6 +3036,7 @@ xmlTextWriterStartDTDAttlist(xmlTextWriterPtr writer, const xmlChar * name)
* @writer: the xmlTextWriterPtr
* @name: the name of the DTD ATTLIST
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted DTD ATTLIST.
*
@ -3219,6 +3232,7 @@ xmlTextWriterStartDTDEntity(xmlTextWriterPtr writer,
* @pe: TRUE if this is a parameter entity, FALSE if not
* @name: the name of the DTD entity
* @format: format string (see printf)
* @...: extra parameters for the format
*
* Write a formatted DTD internal entity.
*
@ -3795,7 +3809,7 @@ xmlTextWriterWriteDocCallback(void *context, const xmlChar * str, int len)
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) context;
int rc;
if ((rc = xmlParseChunk(ctxt, str, len, 0)) != 0) {
if ((rc = xmlParseChunk(ctxt, (const char *) str, len, 0)) != 0) {
xmlGenericError(xmlGenericErrorContext,
"xmlTextWriterWriteDocCallback : XML error %d !\n",
rc);