[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[xml] schema patch - processContents of wildcards
- From: Kasimier Buchcik <kbuchcik 4commerce de>
- To: <xml gnome org>
- Subject: [xml] schema patch - processContents of wildcards
- Date: Thu, 03 Jun 2004 17:12:06 +0200
Hi,
please find attached a small patch for xmlschemas.c.
It implements the the "processContents" functionality of wildcards for
<anyAttribute>.
Patch files:
xmlschemas.c.diff
Test files:
1. anyAttr-processContents1_0.xsd -
anyAttr-processContents1_0.xml
2. anyAttr-processContents-err1_0.xsd -
anyAttr-processContents-err1_0.xml (reports errors)
Greetings,
Kasimier
Index: xmlschemas.c
===================================================================
RCS file: /cvs/gnome/libxml2/xmlschemas.c,v
retrieving revision 1.65
diff -c -r1.65 xmlschemas.c
*** a/xmlschemas.c 3 Jun 2004 02:11:24 -0000 1.65
--- b/xmlschemas.c 3 Jun 2004 14:54:46 -0000
***************
*** 8344,8349 ****
--- 8344,8350 ----
int ret;
xmlAttrPtr attr; /* An attribute on the element. */
xmlChar *value;
+ const xmlChar *nsURI;
xmlSchemaAttributeLinkPtr attrUse;
xmlSchemaAttributePtr attrDecl;
int found;
***************
*** 8430,8436 ****
printf("found\n");
#endif
found = 1;
! ctxt->cur = (xmlNodePtr) attrDecl;
if (attrDecl->subtypes == NULL) {
curState->state = XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED;
--- 8431,8437 ----
printf("found\n");
#endif
found = 1;
! ctxt->cur = (xmlNodePtr) attr;
if (attrDecl->subtypes == NULL) {
curState->state = XML_SCHEMAS_ATTR_TYPE_NOT_RESOLVED;
***************
*** 8505,8510 ****
--- 8506,8519 ----
#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,8551 ****
} else
printf("empty\n");
! #endif
! /*
! * TODO: Implement processContents.
! */
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))
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,
--- 8535,8586 ----
} else
printf("empty\n");
!
! #endif
curState = ctxt->attr;
while (curState != NULL) {
! 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;
! }
! }
curState = curState->next;
}
}
#ifdef DEBUG_ATTR_VALIDATION
if (redundant)
xmlGenericError(xmlGenericErrorContext,
<?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>
<?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>
<?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>
<?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>
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]