Author: mukulg
Date: Fri Jan 7 11:47:20 2011
New Revision: 1056276
URL: http://svn.apache.org/viewvc?rev=1056276&view=rev
Log:
Fixes to assertions evaluations on elements with simpleType's specifying
default values.
It seems that the following element declaration,
<xs:element name="x">
<xs:complexType>
<xs:sequence>
<xs:element name="y" type="xs:string" default="hi" />
</xs:sequence>
<xs:assert test="y = 'hi'" />
</xs:complexType>
</xs:element>
should successfully validate the following instance fragment,
<x>
<y/>
</x>
(I believe that XML schema assertions should have access to the default value
of the element, in case the instance document doesn't provide a value for such
an element)
Prior to this fix, a text node that needs to be constructed from the default
value specified in the schema (with value "hi" in this case) wasn't part of the
XDM tree on which assertions evaluated.
This fix solves this issue.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
URL:
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java?rev=1056276&r1=1056275&r2=1056276&view=diff
==============================================================================
---
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
(original)
+++
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/XMLAssertPsychopathImpl.java
Fri Jan 7 11:47:20 2011
@@ -151,7 +151,7 @@ public class XMLAssertPsychopathImpl ext
fCurrentAssertDomNode.appendChild(elem);
fCurrentAssertDomNode = elem;
}
-
+
// add attribute nodes to DOM element node
final int attributesLength = attributes.getLength();
for (int attIndex = 0; attIndex < attributesLength; attIndex++) {
@@ -190,11 +190,18 @@ public class XMLAssertPsychopathImpl ext
*/
public void endElement(QName element, Augmentations augs) throws Exception
{
- if (fCurrentAssertDomNode != null) {
+ if (fCurrentAssertDomNode != null) {
// set PSVI information on the element
ElementPSVI elemPSVI = (ElementPSVI)
augs.getItem(Constants.ELEMENT_PSVI);
((PSVIElementNSImpl) fCurrentAssertDomNode).setPSVI(elemPSVI);
-
+
+ // handling default values of elements (adding them as 'text' node
in the assertion tree)
+ XSElementDecl elemDecl = (XSElementDecl)
elemPSVI.getElementDeclaration();
+ if (elemDecl != null && elemDecl.fDefault != null &&
fCurrentAssertDomNode.getChildNodes().getLength() == 0) {
+ String normalizedDefaultValue =
elemDecl.fDefault.normalizedValue;
+
fCurrentAssertDomNode.appendChild(fAssertDocument.createTextNode(normalizedDefaultValue));
+ }
+
// itemType for xs:list
XSSimpleTypeDefinition itemType = null;
@@ -220,13 +227,13 @@ public class XMLAssertPsychopathImpl ext
Boolean atomicValueValidity = (Boolean)
augs.getItem("ATOMIC_VALUE_VALIDITY");
if (atomicValueValidity.booleanValue()) {
// depending on simple content's validity status from
XMLSchemaValidator, process
- // XML schema assertions.
+ // XML schema assertions.
processAllAssertionsOnElement(element, itemType,
memberTypes, assertions, elemPSVI);
}
}
if (fCurrentAssertDomNode.getParentNode() instanceof Element) {
- fCurrentAssertDomNode =
(Element)fCurrentAssertDomNode.getParentNode();
+ fCurrentAssertDomNode = (Element)
fCurrentAssertDomNode.getParentNode();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]