mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-09 04:58:16 +03:00
Added creation of the content type of xs:anyType. This is needed when
* xmlschemastypes.c: Added creation of the content type of xs:anyType. This is needed when trying to extend xs:anyType (although it makes no sense to extend it; IMHO the schema people should have ruled this out). This was reported by Yong Chen to the mailing list. * xmlschemas.c: Fixed handling of xs:anyType in xmlSchemaCheckCOSCTExtends() (reported by Young Chen). Tiny adjustment to an error report output. * test/schemas/extension2* result/schemas/extension2*: Added a test case provided by Young Chen.
This commit is contained in:
parent
38c4b332c4
commit
11162b7ce7
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
||||
Thu Jul 28 02:38:21 CEST 2005 Kasimier Buchcik <libxml2-cvs@cazic.net>
|
||||
|
||||
* xmlschemastypes.c: Added creation of the content type of
|
||||
xs:anyType. This is needed when trying to extend xs:anyType
|
||||
(although it makes no sense to extend it; IMHO the schema
|
||||
people should have ruled this out). This was reported
|
||||
by Yong Chen to the mailing list.
|
||||
* xmlschemas.c: Fixed handling of xs:anyType in
|
||||
xmlSchemaCheckCOSCTExtends() (reported by Young Chen). Tiny
|
||||
adjustment to an error report output.
|
||||
* test/schemas/extension2* result/schemas/extension2*:
|
||||
Added a test case provided by Young Chen.
|
||||
|
||||
Mon Jul 25 11:41:18 PDT 2005 William Brack <wbrack@mmm.com.hk>
|
||||
|
||||
* uri.c: enhanced xmlBuildRelativeURI to allow the URI and the
|
||||
|
1
result/schemas/extension2_1_0
Normal file
1
result/schemas/extension2_1_0
Normal file
@ -0,0 +1 @@
|
||||
./test/schemas/extension2_0.xml validates
|
0
result/schemas/extension2_1_0.err
Normal file
0
result/schemas/extension2_1_0.err
Normal file
4
test/schemas/extension2_0.xml
Normal file
4
test/schemas/extension2_0.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0"?>
|
||||
<foo xmlns="http://myns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://myns extension2_1.xsd"/>
|
17
test/schemas/extension2_1.xsd
Normal file
17
test/schemas/extension2_1.xsd
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns="http://myns"
|
||||
targetNamespace="http://myns"
|
||||
elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified"
|
||||
xml:lang="en">
|
||||
|
||||
<xs:complexType name="dataInlineType">
|
||||
<xs:complexContent>
|
||||
<xs:extension base="xs:anyType"/>
|
||||
</xs:complexContent>
|
||||
</xs:complexType>
|
||||
|
||||
<xs:element name="foo" type="dataInlineType"/>
|
||||
|
||||
</xs:schema>
|
13
xmlschemas.c
13
xmlschemas.c
@ -802,6 +802,8 @@ xmlSchemaCompTypeToString(xmlSchemaTypeType type)
|
||||
return(BAD_CAST "IDC (key)");
|
||||
case XML_SCHEMA_TYPE_IDC_KEYREF:
|
||||
return(BAD_CAST "IDC (keyref)");
|
||||
case XML_SCHEMA_TYPE_ANY:
|
||||
return(BAD_CAST "wildcard (any)");
|
||||
case XML_SCHEMA_EXTRA_QNAMEREF:
|
||||
return(BAD_CAST "[helper component] QName reference");
|
||||
default:
|
||||
@ -2577,7 +2579,7 @@ xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
|
||||
xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL);
|
||||
} else {
|
||||
msg = xmlStrcat(msg, BAD_CAST message);
|
||||
msg = xmlStrcat(msg, BAD_CAST "\n");
|
||||
msg = xmlStrcat(msg, BAD_CAST ".\n");
|
||||
xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL,
|
||||
(const char*) msg, str1, str2, NULL, NULL, NULL);
|
||||
}
|
||||
@ -3259,6 +3261,9 @@ xmlSchemaFreeType(xmlSchemaTypePtr type)
|
||||
}
|
||||
}
|
||||
if (type->type != XML_SCHEMA_TYPE_BASIC) {
|
||||
/*
|
||||
* TODO: Why is this restricted to non built-in types?
|
||||
*/
|
||||
if (type->attributeUses != NULL)
|
||||
xmlSchemaFreeAttributeUseList(type->attributeUses);
|
||||
}
|
||||
@ -11423,8 +11428,10 @@ xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr pctxt,
|
||||
default:
|
||||
xmlSchemaPInternalErr(pctxt, "xmlSchemaBuildAContentModel",
|
||||
"found unexpected term of type '%s' in content model of complex "
|
||||
"type '%s'.\n",
|
||||
"type '%s'",
|
||||
xmlSchemaCompTypeToString(particle->children->type), name);
|
||||
xmlGenericError(xmlGenericErrorContext,
|
||||
"Unexpected type: %d\n", particle->children->type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -14370,7 +14377,7 @@ xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
|
||||
* SPEC (1) "If the {base type definition} is a complex type definition,
|
||||
* then all of the following must be true:"
|
||||
*/
|
||||
if (base->type == XML_SCHEMA_TYPE_COMPLEX) {
|
||||
if (IS_COMPLEX_TYPE(base)) {
|
||||
/*
|
||||
* SPEC (1.1) "The {final} of the {base type definition} must not
|
||||
* contain extension."
|
||||
|
@ -318,6 +318,63 @@ xmlSchemaInitBasicType(const char *name, xmlSchemaValType type,
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING: Those type reside normally in xmlschemas.c but are
|
||||
* redefined here locally in oder of being able to use them for xs:anyType-
|
||||
* TODO: Remove those definition if we move the types to a header file.
|
||||
* TODO: Always keep those structs up-to-date with the originals.
|
||||
*/
|
||||
#define UNBOUNDED (1 << 30)
|
||||
|
||||
typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
|
||||
typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
|
||||
struct _xmlSchemaTreeItem {
|
||||
xmlSchemaTypeType type;
|
||||
xmlSchemaAnnotPtr annot;
|
||||
xmlSchemaTreeItemPtr next;
|
||||
xmlSchemaTreeItemPtr children;
|
||||
};
|
||||
|
||||
typedef struct _xmlSchemaParticle xmlSchemaParticle;
|
||||
typedef xmlSchemaParticle *xmlSchemaParticlePtr;
|
||||
struct _xmlSchemaParticle {
|
||||
xmlSchemaTypeType type;
|
||||
xmlSchemaAnnotPtr annot;
|
||||
xmlSchemaTreeItemPtr next;
|
||||
xmlSchemaTreeItemPtr children;
|
||||
int minOccurs;
|
||||
int maxOccurs;
|
||||
xmlNodePtr node;
|
||||
};
|
||||
|
||||
typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
|
||||
typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
|
||||
struct _xmlSchemaModelGroup {
|
||||
xmlSchemaTypeType type;
|
||||
xmlSchemaAnnotPtr annot;
|
||||
xmlSchemaTreeItemPtr next;
|
||||
xmlSchemaTreeItemPtr children;
|
||||
xmlNodePtr node;
|
||||
};
|
||||
|
||||
static xmlSchemaParticlePtr
|
||||
xmlSchemaAddParticle(void)
|
||||
{
|
||||
xmlSchemaParticlePtr ret = NULL;
|
||||
|
||||
ret = (xmlSchemaParticlePtr)
|
||||
xmlMalloc(sizeof(xmlSchemaParticle));
|
||||
if (ret == NULL) {
|
||||
xmlSchemaTypeErrMemory(NULL, "allocating particle component");
|
||||
return (NULL);
|
||||
}
|
||||
memset(ret, 0, sizeof(xmlSchemaParticle));
|
||||
ret->type = XML_SCHEMA_TYPE_PARTICLE;
|
||||
ret->minOccurs = 1;
|
||||
ret->maxOccurs = 1;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* xmlSchemaInitTypes:
|
||||
*
|
||||
@ -339,12 +396,56 @@ xmlSchemaInitTypes(void)
|
||||
NULL);
|
||||
xmlSchemaTypeAnyTypeDef->baseType = xmlSchemaTypeAnyTypeDef;
|
||||
xmlSchemaTypeAnyTypeDef->contentType = XML_SCHEMA_CONTENT_MIXED;
|
||||
/*
|
||||
* Init the content type.
|
||||
*/
|
||||
xmlSchemaTypeAnyTypeDef->contentType = XML_SCHEMA_CONTENT_MIXED;
|
||||
{
|
||||
xmlSchemaParticlePtr particle;
|
||||
xmlSchemaModelGroupPtr sequence;
|
||||
xmlSchemaWildcardPtr wild;
|
||||
|
||||
/* First particle. */
|
||||
particle = xmlSchemaAddParticle();
|
||||
if (particle == NULL)
|
||||
return;
|
||||
xmlSchemaTypeAnyTypeDef->subtypes = (xmlSchemaTypePtr) particle;
|
||||
/* Sequence model group. */
|
||||
sequence = (xmlSchemaModelGroupPtr)
|
||||
xmlMalloc(sizeof(xmlSchemaModelGroup));
|
||||
if (sequence == NULL) {
|
||||
xmlSchemaTypeErrMemory(NULL, "allocating model group component");
|
||||
return;
|
||||
}
|
||||
memset(sequence, 0, sizeof(xmlSchemaModelGroup));
|
||||
sequence->type = XML_SCHEMA_TYPE_SEQUENCE;
|
||||
particle->children = (xmlSchemaTreeItemPtr) sequence;
|
||||
/* Second particle. */
|
||||
particle = xmlSchemaAddParticle();
|
||||
if (particle == NULL)
|
||||
return;
|
||||
particle->minOccurs = 0;
|
||||
particle->maxOccurs = UNBOUNDED;
|
||||
sequence->children = (xmlSchemaTreeItemPtr) particle;
|
||||
/* The wildcard */
|
||||
wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));
|
||||
if (wild == NULL) {
|
||||
xmlSchemaTypeErrMemory(NULL, "could not create an attribute wildcard on anyType");
|
||||
xmlSchemaTypeErrMemory(NULL, "allocating wildcard component");
|
||||
return;
|
||||
}
|
||||
memset(wild, 0, sizeof(xmlSchemaWildcard));
|
||||
wild->type = XML_SCHEMA_TYPE_ANY;
|
||||
wild->any = 1;
|
||||
wild->minOccurs = 1;
|
||||
wild->maxOccurs = 1;
|
||||
wild->processContents = XML_SCHEMAS_ANY_LAX;
|
||||
particle->children = (xmlSchemaTreeItemPtr) wild;
|
||||
/*
|
||||
* Create the attribute wildcard.
|
||||
*/
|
||||
wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));
|
||||
if (wild == NULL) {
|
||||
xmlSchemaTypeErrMemory(NULL, "could not create an attribute "
|
||||
"wildcard on anyType");
|
||||
return;
|
||||
}
|
||||
memset(wild, 0, sizeof(xmlSchemaWildcard));
|
||||
@ -519,7 +620,24 @@ void
|
||||
xmlSchemaCleanupTypes(void) {
|
||||
if (xmlSchemaTypesInitialized == 0)
|
||||
return;
|
||||
xmlSchemaFreeWildcard(xmlSchemaTypeAnyTypeDef->attributeWildcard);
|
||||
/*
|
||||
* Free xs:anyType.
|
||||
*/
|
||||
{
|
||||
xmlSchemaParticlePtr particle;
|
||||
/* Attribute wildcard. */
|
||||
xmlSchemaFreeWildcard(xmlSchemaTypeAnyTypeDef->attributeWildcard);
|
||||
/* Content type. */
|
||||
particle = (xmlSchemaParticlePtr) xmlSchemaTypeAnyTypeDef->subtypes;
|
||||
/* Wildcard. */
|
||||
xmlSchemaFreeWildcard((xmlSchemaWildcardPtr)
|
||||
particle->children->children->children);
|
||||
xmlFree((xmlSchemaParticlePtr) particle->children->children);
|
||||
/* Sequence model group. */
|
||||
xmlFree((xmlSchemaModelGroupPtr) particle->children);
|
||||
xmlFree((xmlSchemaParticlePtr) particle);
|
||||
xmlSchemaTypeAnyTypeDef->subtypes = NULL;
|
||||
}
|
||||
xmlHashFree(xmlSchemaTypesBank, (xmlHashDeallocator) xmlSchemaFreeType);
|
||||
xmlSchemaTypesInitialized = 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user