new patch from Kasimier Buchcik for processContents of wildcards attribute

* xmlschemas.c: new patch from  Kasimier Buchcik for processContents
  of wildcards attribute handling
* test/schemas/anyAttr-* result/schemas/anyAttr-*: added specific
  regression tests
Daniel
This commit is contained in:
Daniel Veillard 2004-06-03 16:00:59 +00:00
parent 37fd307435
commit 8acdfbf53c
10 changed files with 144 additions and 15 deletions

View File

@ -1,3 +1,10 @@
Thu Jun 3 17:58:25 CEST 2004 Daniel Veillard <daniel@veillard.com>
* xmlschemas.c: new patch from Kasimier Buchcik for processContents
of wildcards attribute handling
* test/schemas/anyAttr-* result/schemas/anyAttr-*: added specific
regression tests
Thu Jun 3 13:20:36 CEST 2004 Daniel Veillard <daniel@veillard.com>
* parser.c: fixed a bug where invalid charrefs may not be detected

View File

@ -0,0 +1 @@
./test/schemas/anyAttr-processContents-err1_0.xml fails to validate

View File

@ -0,0 +1,3 @@
./test/schemas/anyAttr-processContents-err1_0.xml:11: element elem.lax: Schemas validity error : Failed to validate basic type language
./test/schemas/anyAttr-processContents-err1_0.xml:11: element elem.lax: Schemas validity error : Attribute bar on elem.lax does not match type
./test/schemas/anyAttr-processContents-err1_0.xml:12: element elem.strict: Schemas validity error : Attribute barB on elem.strict is unknown

View File

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

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<foo
xmlns="http://FOO"
xmlns:foo="http://FOO"
xmlns:bar="http://BAR"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://FOO anyAttr-processContents1_0.xsd">
<elem.lax foo:bar="o o"/>
<elem.strict foo:barB="GB"/>
</foo>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:foo="http://FOO"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://FOO">
<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="elem.lax" type="foo:type.lax"/>
<xsd:element name="elem.strict" type="foo:type.strict"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:attribute name="bar" type="xsd:language" />
<xsd:complexType name="type.lax">
<xsd:anyAttribute namespace="##any" processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="type.strict">
<xsd:anyAttribute namespace="##any" processContents="strict"/>
</xsd:complexType>
</xsd:schema>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<foo
xmlns="http://FOO"
xmlns:foo="http://FOO"
xmlns:bar="http://BAR"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://FOO anyAttr-processContents1_0.xsd">
<elem.lax.A foo:barA_1="PL"/>
<elem.lax.B foo:barA_2="o"/>
<elem.strict foo:barB="FR"/>
<elem.skip foo:barC="o"/>
</foo>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:foo="http://FOO"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://FOO">
<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="elem.lax.A" type="foo:type.lax"/>
<xsd:element name="elem.lax.B" type="foo:type.lax"/>
<xsd:element name="elem.strict" type="foo:type.strict"/>
<xsd:element name="elem.skip" type="foo:type.skip"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:attribute name="barA" type="xsd:language" />
<xsd:attribute name="barB" type="xsd:language" />
<xsd:complexType name="type.lax">
<xsd:anyAttribute namespace="##any" processContents="lax"/>
</xsd:complexType>
<xsd:complexType name="type.strict">
<xsd:anyAttribute namespace="##any"/>
</xsd:complexType>
<xsd:complexType name="type.skip">
<xsd:anyAttribute namespace="##any" processContents="skip"/>
</xsd:complexType>
</xsd:schema>

View File

@ -8344,6 +8344,7 @@ xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSche
int ret;
xmlAttrPtr attr; /* An attribute on the element. */
xmlChar *value;
const xmlChar *nsURI;
xmlSchemaAttributeLinkPtr attrUse;
xmlSchemaAttributePtr attrDecl;
int found;
@ -8430,7 +8431,7 @@ xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSche
printf("found\n");
#endif
found = 1;
ctxt->cur = (xmlNodePtr) attr;
ctxt->cur = (xmlNodePtr) attr;
if (attrDecl->subtypes == NULL) {
curState->state = XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED;
@ -8505,6 +8506,14 @@ xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSche
#ifdef DEBUG_ATTR_VALIDATION
xmlSchemaWildcardNsPtr ns;
printf("matching wildcard: [%d] of complexType: %s\n", type->attributeWildcard, type->name);
if (type->attributeWildcard->processContents ==
XML_SCHEMAS_ANY_LAX)
printf("processContents: lax\n");
else if (type->attributeWildcard->processContents ==
XML_SCHEMAS_ANY_STRICT)
printf("processContents: strict\n");
else
printf("processContents: skip\n");
if (type->attributeWildcard->any)
printf("type: any\n");
else if (type->attributeWildcard->negNsSet != NULL) {
@ -8526,26 +8535,52 @@ xmlSchemaValidateAttributes(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem, xmlSche
} else
printf("empty\n");
#endif
/*
* TODO: Implement processContents.
*/
#endif
curState = ctxt->attr;
while (curState != NULL) {
if ((curState->state == XML_SCHEMAS_ATTR_UNKNOWN) &&
(curState->attr != NULL)) {
if (curState->attr->ns != NULL) {
if (xmlSchemaMatchesWildcardNs(type->attributeWildcard,
curState->attr->ns->href))
if (curState->state == XML_SCHEMAS_ATTR_UNKNOWN) {
if (curState->attr->ns != NULL)
nsURI = curState->attr->ns->href;
else
nsURI = NULL;
if (xmlSchemaMatchesWildcardNs(type->attributeWildcard,
nsURI)) {
/*
* Handle processContents.
*/
if ((type->attributeWildcard->processContents ==
XML_SCHEMAS_ANY_LAX) ||
(type->attributeWildcard->processContents ==
XML_SCHEMAS_ANY_STRICT)) {
attr = curState->attr;
attrDecl = xmlSchemaGetAttribute(ctxt->schema,
attr->name, nsURI);
if (attrDecl != NULL) {
value = xmlNodeListGetString(elem->doc, attr->children, 1);
ret = xmlSchemaValidateSimpleValue(ctxt, attrDecl->subtypes,
value);
if (ret != 0)
curState->state = XML_SCHEMAS_ATTR_INVALID_VALUE;
else
curState->state = XML_SCHEMAS_ATTR_CHECKED;
curState->decl = attrDecl;
if (value != NULL) {
xmlFree(value);
}
} else if (type->attributeWildcard->processContents ==
XML_SCHEMAS_ANY_LAX) {
curState->state = XML_SCHEMAS_ATTR_CHECKED;
}
} else
curState->state = XML_SCHEMAS_ATTR_CHECKED;
} else if (xmlSchemaMatchesWildcardNs(type->attributeWildcard,
NULL))
curState->state = XML_SCHEMAS_ATTR_CHECKED;
}
}
}
curState = curState->next;
}
}
#ifdef DEBUG_ATTR_VALIDATION
if (redundant)
xmlGenericError(xmlGenericErrorContext,