(NPOTDB) Bug 278449 - Implement XML Schema Validation for Complex Types. r=aaronr

This commit is contained in:
doronr%us.ibm.com 2006-03-30 21:01:35 +00:00
parent a757cb0909
commit a83505cb84
9 changed files with 3074 additions and 216 deletions

View File

@ -65,6 +65,7 @@ REQUIRES = xpcom \
widget \
unicharutil \
content \
layout \
js \
htmlparser \
necko \

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,7 @@
#include "nsISchema.h"
#include "nsCOMPtr.h"
#include "nsCOMArray.h"
#include "nsIAtom.h"
/* eced2af3-fde9-4575-b5a4-e1c830b24611 */
#define NS_SCHEMAVALIDATOR_CID \
@ -107,7 +108,8 @@ private:
nsStringArray *aEnumerationList,
PRBool *aResult);
nsresult ValidateBuiltinTypeBoolean(const nsAString & aNodeValue, PRBool *aResult);
nsresult ValidateBuiltinTypeBoolean(const nsAString & aNodeValue,
PRBool *aResult);
nsresult ValidateBuiltinTypeGDay(const nsAString & aNodeValue,
const nsAString & aMaxExclusive,
@ -126,7 +128,8 @@ private:
const nsAString & aMaxInclusive,
const nsAString & aMinInclusive,
PRBool *aResult);
PRBool IsValidSchemaGMonth(const nsAString & aNodeValue, nsSchemaGMonth *aResult);
PRBool IsValidSchemaGMonth(const nsAString & aNodeValue,
nsSchemaGMonth *aResult);
nsresult ValidateBuiltinTypeGYear(const nsAString & aNodeValue,
const nsAString & aMaxExclusive,
@ -134,7 +137,8 @@ private:
const nsAString & aMaxInclusive,
const nsAString & aMinInclusive,
PRBool *aResult);
PRBool IsValidSchemaGYear(const nsAString & aNodeValue, nsSchemaGYear *aResult);
PRBool IsValidSchemaGYear(const nsAString & aNodeValue,
nsSchemaGYear *aResult);
nsresult ValidateBuiltinTypeGYearMonth(const nsAString & aNodeValue,
const nsAString & aMaxExclusive,
@ -142,7 +146,8 @@ private:
const nsAString & aMaxInclusive,
const nsAString & aMinInclusive,
PRBool *aResult);
PRBool IsValidSchemaGYearMonth(const nsAString & aNodeValue, nsSchemaGYearMonth *aYearMonth);
PRBool IsValidSchemaGYearMonth(const nsAString & aNodeValue,
nsSchemaGYearMonth *aYearMonth);
nsresult ValidateBuiltinTypeGMonthDay(const nsAString & aNodeValue,
const nsAString & aMaxExclusive,
@ -150,7 +155,8 @@ private:
const nsAString & aMaxInclusive,
const nsAString & aMinInclusive,
PRBool *aResult);
PRBool IsValidSchemaGMonthDay(const nsAString & aNodeValue, nsSchemaGMonthDay *aYearMonth);
PRBool IsValidSchemaGMonthDay(const nsAString & aNodeValue,
nsSchemaGMonthDay *aYearMonth);
nsresult ValidateBuiltinTypeDateTime(const nsAString & aNodeValue,
const nsAString & aMaxExclusive,
@ -160,7 +166,8 @@ private:
PRBool *aResult);
int CompareSchemaDateTime(nsSchemaDateTime datetime1,
nsSchemaDateTime datetime2);
PRBool IsValidSchemaDateTime(const nsAString & aNodeValue, nsSchemaDateTime *aResult);
PRBool IsValidSchemaDateTime(const nsAString & aNodeValue,
nsSchemaDateTime *aResult);
nsresult ValidateBuiltinTypeDate(const nsAString & aNodeValue,
const nsAString & aMaxExclusive,
@ -228,7 +235,8 @@ private:
PRBool *aResult);
PRBool IsValidSchemaDecimal(const nsAString & aNodeValue, nsAString & aWholePart,
nsAString & aFractionPart);
int CompareFractionStrings(const nsAString & aString1, const nsAString & aString2);
int CompareFractionStrings(const nsAString & aString1,
const nsAString & aString2);
nsresult ValidateBuiltinTypeAnyURI(const nsAString & aNodeValue,
PRUint32 aLength, PRUint32 aMinLength,
@ -246,7 +254,8 @@ private:
PRBool aMaxLengthDefined,
nsStringArray *aEnumerationList,
PRBool *aResult);
PRBool IsValidSchemaBase64Binary(const nsAString & aString, char** aDecodedString);
PRBool IsValidSchemaBase64Binary(const nsAString & aString,
char** aDecodedString);
nsresult ValidateBuiltinTypeHexBinary(const nsAString & aNodeValue,
@ -275,8 +284,71 @@ private:
// helper methods
void DumpBaseType(nsISchemaBuiltinType *aBuiltInType);
// methods dealing with complextypes
nsresult ValidateComplextype(nsIDOMNode *aNode,
nsISchemaComplexType *aSchemaComplexType,
PRBool *aResult);
nsresult ValidateComplexModelElement(nsIDOMNode *aNode,
nsISchemaComplexType *aSchemaComplexType,
PRBool *aResult);
nsresult ValidateComplexModelSimple(nsIDOMNode *aNode,
nsISchemaComplexType *aSchemaComplexType,
PRBool *aResult);
nsresult ValidateComplexModelGroup(nsIDOMNode* aNode,
nsISchemaModelGroup *aSchemaModelGroup,
nsIDOMNode **aLeftOvers, PRBool *aResult);
nsresult ValidateComplexSequence(nsIDOMNode *aStartNode,
nsISchemaModelGroup *aSchemaModelGroup,
nsIDOMNode **aLeftOvers, PRBool *aNotFound,
PRBool *aResult);
nsresult ValidateComplexParticle(nsIDOMNode* aNode,
nsISchemaParticle *aSchemaParticle,
nsIDOMNode **aLeftOvers, PRBool *aNotFound,
PRBool *aResult);
nsresult ValidateComplexElement(nsIDOMNode* aNode,
nsISchemaParticle *aSchemaParticle,
PRBool *aResult);
nsresult ValidateComplexChoice(nsIDOMNode* aStartNode,
nsISchemaModelGroup *aSchemaModelGroup,
nsIDOMNode **aLeftOvers, PRBool *aNotFound,
PRBool *aResult);
nsresult ValidateComplexAll(nsIDOMNode* aStartNode,
nsISchemaModelGroup *aSchemaModelGroup,
nsIDOMNode **aLeftOvers, PRBool *aNotFound,
PRBool *aResult);
nsresult ValidateAttributeComponent(nsIDOMNode* aNode,
nsISchemaAttributeComponent *aAttrComp,
PRUint32 *aFoundAttrCount, PRBool *aResult);
nsresult ValidateSchemaAttribute(nsIDOMNode* aNode, nsISchemaAttribute *aAttr,
const nsAString & aAttrName,
PRUint32 *aFoundAttrCount, PRBool *aResult);
nsresult ValidateSchemaAttributeGroup(nsIDOMNode* aNode,
nsISchemaAttributeGroup *aAttr,
const nsAString & aAttrName,
PRUint32 *aFoundAttrCount,
PRBool *aResult);
static void
ReleaseObject(void *aObject,
nsIAtom *aPropertyName,
void *aPropertyValue,
void *aData)
{
NS_STATIC_CAST(nsISupports *, aPropertyValue)->Release();
}
protected:
nsCOMPtr<nsISchemaCollection> mSchema;
PRBool mForceInvalid;
};
#endif // __nsSchemaValidator_h__

View File

@ -200,10 +200,14 @@ nsSchemaValidatorUtils::ParseSchemaDate(const nsAString & aStrValue,
case 0: {
// year
if (currentChar == '-') {
year.Assign(Substring(buffStart, --start));
state = 1;
buffLength = 0;
buffStart = ++start;
if (buffLength < 4) {
done = PR_TRUE;
} else {
year.Assign(Substring(buffStart, --start));
state = 1;
buffLength = 0;
buffStart = ++start;
}
} else {
// has to be a numerical character or else abort
if ((currentChar > '9') || (currentChar < '0'))
@ -218,7 +222,7 @@ nsSchemaValidatorUtils::ParseSchemaDate(const nsAString & aStrValue,
if (buffLength > 2) {
done = PR_TRUE;
} else if (currentChar == '-') {
if (strcmp(month, "12") == 1) {
if (strcmp(month, "12") == 1 || buffLength < 2) {
done = PR_TRUE;
} else {
state = 2;
@ -241,7 +245,7 @@ nsSchemaValidatorUtils::ParseSchemaDate(const nsAString & aStrValue,
if (buffLength > 2) {
done = PR_TRUE;
} else if (currentChar == 'T') {
if ((start == end) && (strcmp(day, "31") < 1))
if ((start == end) && (buffLength == 2) && (strcmp(day, "31") < 1))
isValid = PR_TRUE;
done = PR_TRUE;
} else {
@ -288,7 +292,6 @@ nsSchemaValidatorUtils::ParseSchemaDate(const nsAString & aStrValue,
return isValid;
}
// parses a string as a schema time type and returns the parsed
// hour/minute/second/fraction seconds as well as if its a valid
// schema time type.
@ -347,7 +350,7 @@ nsSchemaValidatorUtils::ParseSchemaTime(const nsAString & aStrValue,
break;
}
case 1 : {
case 1: {
// minute
if (buffLength > 2) {
done = PR_TRUE;
@ -371,16 +374,14 @@ nsSchemaValidatorUtils::ParseSchemaTime(const nsAString & aStrValue,
break;
}
case 2 : {
case 2: {
// seconds
if (buffLength > 2) {
done = PR_TRUE;
} else if (currentChar == 'Z') {
// if its Z, has to be the last character
if ((start == end) && (strcmp(second, "59") != 1)) {
isValid = PR_TRUE;
//sprintf(rv_second, "%s", NS_ConvertUTF16toUTF8(Substring(buffStart, start)).get());
}
done = PR_TRUE;
tzSign = currentChar;
@ -415,7 +416,7 @@ nsSchemaValidatorUtils::ParseSchemaTime(const nsAString & aStrValue,
break;
}
case 3 : {
case 3: {
// fractional seconds
if (currentChar == 'Z') {
@ -442,7 +443,7 @@ nsSchemaValidatorUtils::ParseSchemaTime(const nsAString & aStrValue,
break;
}
case 4 : {
case 4: {
// timezone hh:mm
if (buffStart.size_forward() == 5)
isValid = ParseSchemaTimeZone(Substring(buffStart, end), timezoneHour,
@ -453,6 +454,7 @@ nsSchemaValidatorUtils::ParseSchemaTime(const nsAString & aStrValue,
}
}
}
if (isValid) {
char * pEnd;
@ -731,7 +733,6 @@ nsSchemaValidatorUtils::AddTimeZoneToDateTime(nsSchemaDateTime aDateTime,
}
// day
if (day == 0) {
// if day is 0, go back a month and make sure we handle month 0 (ie back a year).
month--;
@ -824,7 +825,7 @@ nsSchemaValidatorUtils::CompareGMonthDay(nsSchemaGMonthDay aMonthDay1,
if (aMonthDay1.gDay.day > aMonthDay2.gDay.day)
rv = 1;
else if (aMonthDay1.gDay.day < aMonthDay2.gDay.day)
rv = -1;
rv = -1;
else
rv = 0;
}
@ -1725,3 +1726,27 @@ nsSchemaValidatorUtils::CopyDerivedSimpleType(nsSchemaDerivedSimpleType *aDerive
aDerivedDest->enumerationList = aDerivedSrc->enumerationList;
}
// sets aResultNode to aNode, making sure it points to null or a dom element
void
nsSchemaValidatorUtils::SetToNullOrElement(nsIDOMNode *aNode,
nsIDOMNode **aResultNode)
{
nsCOMPtr<nsIDOMNode> currentNode(aNode), tmpNode;
if (currentNode) {
PRUint16 nodeType;
currentNode->GetNodeType(&nodeType);
// if not an element node, skip
while (currentNode && nodeType != nsIDOMNode::ELEMENT_NODE) {
currentNode->GetNextSibling(getter_AddRefs(tmpNode));
currentNode = tmpNode;
if (currentNode)
currentNode->GetNodeType(&nodeType);
}
currentNode.swap(*aResultNode);
}
}

View File

@ -42,6 +42,7 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsISchema.h"
#include "nsIDOMNode.h"
#include "nsCOMArray.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
@ -228,6 +229,8 @@ public:
nsSchemaDerivedSimpleType *aDerived);
static void CopyDerivedSimpleType(nsSchemaDerivedSimpleType *aDerivedDest,
nsSchemaDerivedSimpleType *aDerivedSrc);
static void SetToNullOrElement(nsIDOMNode *aNode, nsIDOMNode **aResultNode);
private:
nsSchemaValidatorUtils();
~nsSchemaValidatorUtils();

View File

@ -0,0 +1,319 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<style>
.passed {background-color:lightgreen;}
.failed {background-color:red;}
td {
padding:3px;
}
</style>
<script>
var myValidator = null;
var counter;
var failCounter = 0;
var results;
var start;
var end;
var gXMLDoc;
function getValidator() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (!myValidator)
myValidator = Components.classes["@mozilla.org/xmlextras/schemas/schemavalidator;1"]
.getService(Components.interfaces.nsISchemaValidator);
return myValidator;
}
function validateComplexType(aID, aType, aIsValid){
var rv = false;
if (!gXMLDoc) {
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.open("GET", "file:///home/doron/mozbuilds/trunk/mozilla/extensions/schema-validation/tests/schema-complex-test.xml", false);
xmlHTTP.send(null);
gXMLDoc = xmlHTTP.responseXML;
}
var elm = gXMLDoc.getElementById(aID);
if (!elm) {
alert("No element found!");
} else {
//elm.removeAttribute("id");
rv = getValidator().validate(elm);
}
counter++;
results[results.length] = {type: aType, nodevalue: aID, rv: rv, isvalid: aIsValid};
}
function validateFile(aFile, aSchema, aIsValid) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
try{
var myValidator = Components.classes["@mozilla.org/schemavalidator;1"].getService(Components.interfaces.nsISchemaValidator);
} catch(e){ alert(e) }
var schemaLoader = Components.classes["@mozilla.org/xmlextras/schemas/schemaloader;1"]
.getService(Components.interfaces.nsISchemaLoader);
try {
schema = schemaLoader.load(aSchema);
myValidator.loadSchema(schema);
} catch(e){alert(e)}
var rv = false;
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.open("GET", aFile, false);
xmlHTTP.send(null);
xmlDoc = xmlHTTP.responseXML;
xmlDoc.documentElement.removeAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
rv = getValidator().validate(xmlDoc.documentElement);
counter++;
results[results.length] = {type: "file", nodevalue: "", rv: rv, isvalid: aIsValid};
}
function displayResults(){
var tbody = document.createElement("tbody");
var tr, td, textNode;
for (var run = 0; run < results.length; run++){
tr = document.createElement("tr");
td = document.createElement("td");
textNode = document.createTextNode(run + 1);
td.appendChild(textNode);
tr.appendChild(td);
td = document.createElement("td");
textNode = document.createTextNode(results[run].type);
td.appendChild(textNode);
tr.appendChild(td);
td = document.createElement("td");
textNode = document.createTextNode(results[run].nodevalue);
td.appendChild(textNode);
tr.appendChild(td);
td = document.createElement("td");
textNode = document.createTextNode(results[run].rv);
td.appendChild(textNode);
tr.appendChild(td);
td = document.createElement("td");
textNode = document.createTextNode(results[run].isvalid);
td.appendChild(textNode);
tr.appendChild(td);
td = document.createElement("td");
textNode = document.createTextNode((results[run].rv == results[run].isvalid) ? "Passed" : "Failed");
td.appendChild(textNode);
td.className = (results[run].rv == results[run].isvalid) ? "passed" : "failed";
tr.appendChild(td);
tbody.appendChild(tr);
if (results[run].rv!=results[run].isvalid)
failCounter++;
}
document.getElementById("resultTable").replaceChild(tbody, document.getElementById("results"));
}
var dp = new DOMParser();
var schema;
function test() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
try{
myValidator = Components.classes["@mozilla.org/schemavalidator;1"].getService(Components.interfaces.nsISchemaValidator);
} catch(e){ alert(e) }
var schemaLoader = Components.classes["@mozilla.org/xmlextras/schemas/schemaloader;1"]
.getService(Components.interfaces.nsISchemaLoader);
try {
schema = schemaLoader.load("file:///home/doron/mozbuilds/trunk/mozilla/extensions/schema-validation/tests/schema.xsd");
//alert(schema.attributeFormDefaultQualified)
myValidator.loadSchema(schema);
} catch(e){alert(e)}
//schema collection
var schemaCollection = schema.collection;
document.getElementById("results").innerHTML = "";
counter = 0;
failCounter = 0;
results = new Array();
start = new Date();
if (1) {
validateComplexType("balance-1", "balance-1", true);
validateComplexType("balance-2", "balance-2", false);
validateComplexType("balance-3", "balance-3", false);
validateComplexType("balance-4", "balance-4", false);
validateComplexType("balance-5", "balance-5", true);
validateComplexType("balance2-1", "balance2-1", true);
validateComplexType("balance2-2", "balance2-2", false);
validateComplexType("balance2-3", "balance2-3", false);
validateComplexType("balance2-4", "balance2-4", false);
validateComplexType("balance3-1", "balance3-1", true);
validateComplexType("balance3-2", "balance3-2", true);
validateComplexType("balance3-3", "balance3-3", false);
validateComplexType("balance3-4", "balance3-4", true);
validateComplexType("balance3-5", "balance3-5", false);
validateComplexType("balance4-1", "balance4-1", true);
validateComplexType("balance4-2", "balance4-2", true);
validateComplexType("balance4-3", "balance4-3", false);
validateComplexType("balance4-4", "balance4-4", false);
validateComplexType("balance5-1", "balance5-1", true);
validateComplexType("balance5-2", "balance5-2", false);
validateComplexType("balance5-3", "balance5-3", true);
validateComplexType("balance5-4", "balance5-4", true);
validateComplexType("balance5-5", "balance5-5", false);
validateComplexType("balance5-6", "balance5-6", false);
validateComplexType("balance6-1", "balance6-1", true);
validateComplexType("balance6-2", "balance6-2", true);
validateComplexType("balance6-3", "balance6-3", true);
validateComplexType("balance6-4", "balance6-4", true);
validateComplexType("balance6-5", "balance6-5", false);
validateComplexType("balance6-6", "balance6-6", true);
validateComplexType("balance6-7", "balance6-7", true);
validateComplexType("balance6-8", "balance6-8", true);
validateComplexType("balance6-9", "balance6-9", false);
validateComplexType("balance7-1", "balance7-1", false);
validateComplexType("balance7-2", "balance7-2", true);
validateComplexType("balance7-3", "balance7-3", false);
validateComplexType("balance7-4", "balance7-4", true);
validateComplexType("balance7-5", "balance7-5", false);
validateComplexType("balance7-6", "balance7-6", true);
validateComplexType("balance7-7", "balance7-7", true);
validateComplexType("balance7-8", "balance7-8", true);
validateComplexType("balance7-9", "balance7-9", false);
validateComplexType("balance7-10", "balance7-10", false);
validateComplexType("balance7-11", "balance7-11", false);
validateComplexType("balance8-1", "balance8-1", true);
validateComplexType("balance8-2", "balance8-2", true);
validateComplexType("balance8-3", "balance8-3", false);
validateComplexType("balance8-4", "balance8-4", true);
validateComplexType("balance8-5", "balance8-5", true);
validateComplexType("balance8-6", "balance8-6", false);
validateComplexType("balance8-7", "balance8-7", false);
validateComplexType("balance9-1", "balance9-1", true);
validateComplexType("balance9-2", "balance9-2", false);
validateComplexType("balance9-3", "balance9-3", false);
validateComplexType("balance9-4", "balance9-4", true);
validateComplexType("balance9-5", "balance9-5", false);
validateComplexType("balance9-6", "balance9-6", false);
validateComplexType("balance10-1", "balance10-1", false);
validateComplexType("balance10-2", "balance10-2", false);
validateComplexType("balance10-3", "balance10-3", false);
validateComplexType("balance11-1", "balance11-1", true);
validateComplexType("balance11-2", "balance11-2", false);
validateComplexType("balance12-1", "balance12-1", true);
validateComplexType("balance12-2", "balance12-2", true);
validateComplexType("balance12-3", "balance12-3", false);
validateComplexType("balance12-4", "balance12-4", false);
validateComplexType("balance12-5", "balance12-5", false);
validateComplexType("t1", "t1", true);
validateComplexType("t2", "t2", false);
validateComplexType("t3", "t3", true);
validateComplexType("t4", "t4", false);
validateComplexType("t5", "t5", false);
validateComplexType("t6", "t6", true);
validateComplexType("t7", "t7", false);
validateComplexType("t8", "t8", false);
validateComplexType("t9", "t9", false);
validateComplexType("t10", "t10", false);
validateComplexType("t11", "t11", true);
validateComplexType("t12", "t12", true);
validateComplexType("t13", "t13", false);
validateComplexType("author-1", "author-1", true);
validateComplexType("author-2", "author-2", false);
validateComplexType("author-3", "author-3", false);
validateComplexType("author-4", "author-4", false);
validateComplexType("author-5", "author-5", true);
validateComplexType("author-6", "author-6", false);
validateComplexType("author-7", "author-7", false);
validateComplexType("author-8", "author-8", false);
validateComplexType("author-2-1", "author-2-1", true);
validateComplexType("author-2-2", "author-2-2", false);
validateComplexType("author-2-3", "author-2-3", false);
validateComplexType("author-3-1", "author-3-1", true);
validateComplexType("author-3-2", "author-3-2", true);
validateComplexType("author-4-1", "author-4-1", true);
validateComplexType("balance-attrgroup-1-1", "balance-attrgroup-1-1", true);
validateComplexType("balance-attrgroup-1-2", "balance-attrgroup-1-2", true);
validateComplexType("balance-attrgroup-1-3", "balance-attrgroup-1-3", false);
validateComplexType("balance-attrgroup-1-4", "balance-attrgroup-1-4", false);
validateComplexType("group-1", "group-1", true);
validateComplexType("group-2", "group-2", true);
validateComplexType("group-3", "group-3", false);
validateComplexType("group-4", "group-4", false);
validateComplexType("deriv-ext-1-1", "deriv-ext-1-1", true);
validateComplexType("deriv-ext-1-2", "deriv-ext-1-2", false);
validateComplexType("deriv-ext-1-3", "deriv-ext-1-3", false);
validateComplexType("deriv-res-1-1", "deriv-res-1-1", true);
validateComplexType("deriv-res-1-2", "deriv-res-1-2", false);
validateComplexType("deriv-res-2-1", "deriv-res-2-1", true);
validateComplexType("deriv-res-2-2", "deriv-res-2-2", false);
validateComplexType("deriv-ext-complex-1-1", "deriv-ext-complex-1-1", true);
validateComplexType("deriv-ext-complex-1-2", "deriv-ext-complex-1-2", false);
validateComplexType("deriv-ext-restriction-1-1", "deriv-ext-restriction-1-1", true);
validateComplexType("deriv-ext-restriction-1-2", "deriv-ext-restriction-1-2", false);
}
end = new Date();
// final result
displayResults();
document.getElementById("finalResults").innerHTML = counter + " Tests Completed, with " + failCounter + " Failures" +
". Seconds: " + ((end-start) / 1000);
}
</script>
</head>
<body>
<button onclick="test()">Do</button>
<div id="finalResults"></div>
<table border=1 cellpadding=0 cellspacing=0 width="100%" id="resultTable" style="font-size:0.8em;">
<thead>
<td>#</td>
<td>Type</td>
<td>Value</td>
<td>Is Valid?</td>
<td>Should be Valid?</td>
<td>Result</td>
</thead>
<tbody id="results" />
</table>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -137,6 +137,14 @@
results = new Array();
start = new Date();
/*
try {
var x = myValidator.validateBuiltinTypeDuration("P200Y30M23DT21H456M3234.345S");
alert(x.getSeconds() + " " + x.getFractionSeconds());
} catch (e) {
alert("invalid")
}
*/
if (1) {
validate("220", "integer-test-1", false);
@ -438,10 +446,19 @@
validate("2001-01-18T22:20:03Z", "datetime-test-3", false);
validate("2004-02-18T12:21:03-02:00", "datetime-test-3", false);
validate("2004-02-18T12:21:03+02:00", "datetime-test-3", true);
validate("2004-02-18T12:21:03+00:23", "datetime-test-3", true);
validate("2004-02-18T12:21:03+14:00", "datetime-test-3", true);
validate("2003-02-18T12:21:03-00:45", "datetime-test-3", true);
validate("2001-01-18", "date-test-1", true);
validate("2001-0a-18", "date-test-1", false);
validate("2001-01-36", "date-test-1", false);
validate("2001-01-1", "date-test-1", false);
validate("2001-1-11", "date-test-1", false);
validate("201-01-11", "date-test-1", false);
// leap year test
validate("2000-02-29", "date-test-1", true);
validate("2001-02-29", "date-test-1", false);
validate("2004-02-17", "date-test-2", true);
validate("2004-02-18", "date-test-2", false);
@ -516,10 +533,11 @@
validate("P200Y20D30M", "duration-test-1", false);
validate("P200Y30MT20S5H", "duration-test-1", false);
validate("P200Y30MT21H32.34S", "duration-test-1", true);
validate("P200Y30MT21H32.34.2S", "duration-test-1", false);
validate("P200Y30M23DT21H456M3234S", "duration-test-1", true);
validate("P200Y30MT21H32.3a4S", "duration-test-1", false);
validate("P200Y-20M", "duration-test-1", false);
validate("P2147483647Y", "duration-test-1", true);
validate("P214748364Y", "duration-test-1", true);
validate("P2147583647Y", "duration-test-1", false);
validate("P21475836433337Y", "duration-test-1", false);
@ -540,33 +558,6 @@
validate("n:s", "qname-test-1", true);
validate("test:123456789", "qname-test-1", false);
validate("2004-02-28T24:21:03Z", "datetime-test-1", true);
validate("2004-02-28T25:21:03Z", "datetime-test-1", false);
validate("2004-02-28T22:61:03Z", "datetime-test-1", false);
validate("-2004-02-28T12:21:03.434Z", "datetime-test-1", true);
validate("-2004-02-28T12:21:03-04:00", "datetime-test-1", true);
validate("-2004-02-30T12:21:03Z", "datetime-test-1", false);
validate("2004-02-11T12:21:03Z", "datetime-test-2", true);
validate("2004-02-18T00:00:00Z", "datetime-test-2", true);
validate("2004-02-18T12:21:03Z", "datetime-test-2", false);
validate("2004-02-30T12:21:03Z", "datetime-test-2", false);
validate("2002-06-29T12:21:03Z", "datetime-test-2", true);
validate("2001-02-18T12:21:03Z", "datetime-test-2", false);
validate("2001-01-18T12:21:03Z", "datetime-test-2", false);
validate("2002-02-30T12:21:03Z", "datetime-test-2", false);
validate("2004-02-18T12:21:03Z", "datetime-test-3", true);
validate("2004-02-18T00:00:00Z", "datetime-test-3", true);
validate("2004-02-18T12:22:03Z", "datetime-test-3", false);
validate("2004-02-21T12:22:03Z", "datetime-test-3", false);
validate("2001-02-18T12:21:03Z", "datetime-test-3", true);
validate("2002-02-18T12:21:03Z", "datetime-test-3", true);
validate("2001-02-18T12:20:03Z", "datetime-test-3", false);
validate("2001-01-18T22:20:03Z", "datetime-test-3", false);
validate("2004-02-18T12:21:03-02:00", "datetime-test-3", false);
validate("2004-02-18T12:21:03+02:00", "datetime-test-3", true);
validate("true false 0 1", "list-test-1", true);
validate("true false e 1", "list-test-1", false);
@ -592,7 +583,7 @@
validateSimpleTypeString("2", "language", false);
validate("Applicant", "IndividualRole", true);
validate("Applicanter", "IndividualRole", true);
validate("Applicanter", "IndividualRole", false);
validate("Applicant1", "IndividualRole", false);
validate("Applicant Trustee", "IndividualRoleList", true);

View File

@ -1,9 +1,9 @@
<?xml version="1.0" ?>
<schema targetNamespace="http://www.mozilla.org/schema/test"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:test="http://www.mozilla.org/schema/test"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://www.w3.org/2001/XMLSchema">
<simpleType name="integer-test-1">
<restriction base='integer'>
@ -484,6 +484,12 @@
</simpleType>
<!-- complex types -->
<element name="foo" type="test:duration-test-2"/>
<attributeGroup name="attrgroup-1">
<attribute name="id" type="string" form="unqualified"/>
</attributeGroup>
<element name="transaction">
<complexType>
@ -499,10 +505,9 @@
<element name="balance">
<complexType>
<sequence>
<element ref="transaction" />
<element ref="test:transaction" />
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -520,8 +525,7 @@
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -539,8 +543,7 @@
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -558,8 +561,7 @@
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -577,8 +579,7 @@
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -597,12 +598,11 @@
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<attribute name="testAttr3" type="boolean" fixed="true"/>
<attribute name="testAttr3" type="boolean" />
<attribute name="testAttr4" type="boolean"/>
<element name="balance7">
@ -617,14 +617,13 @@
<element name="amount" type="decimal" minOccurs="0"/>
</sequence>
<attribute name="testAttr" type="boolean" use="required"/>
<attribute name="testAttr2" type="boolean" use="optional" fixed="true"/>
<attribute ref="testAttr3" use="optional"/>
<attribute ref="testAttr4" use="required"/>
<attribute name="testAttr2" type="boolean" use="optional" form="unqualified"/>
<attribute ref="test:testAttr3" use="optional"/>
<attribute ref="test:testAttr4" use="required"/>
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -646,8 +645,7 @@
<element name="lastname" type="string" minOccurs="0"/>
</sequence>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -673,8 +671,7 @@
<element name="test2" type="string" />
</sequence>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -696,8 +693,7 @@
<element name="lastname" type="string" minOccurs="0"/>
</sequence>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -714,7 +710,7 @@
<element name="foopy">
<complexType>
<sequence minOccurs="2" maxOccurs="4">
<element ref="balance9"/>
<element ref="test:balance9"/>
</sequence>
</complexType>
</element>
@ -722,8 +718,7 @@
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
@ -745,93 +740,284 @@
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<element name="date" type="date"/>
<element name="balance13">
<complexType>
<sequence>
<element ref="test:date"/>
</sequence>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<!-- Chilled -->
<simpleType name="chilledDecimal">
<restriction base="decimal">
<totalDigits value="5"/>
<fractionDigits value="2"/>
<minInclusive value="0"/>
</restriction>
</simpleType>
<simpleType name="chilledDecimal">
<restriction base="decimal">
<totalDigits value="5"/>
<fractionDigits value="2"/>
<minInclusive value="0"/>
</restriction>
</simpleType>
<simpleType name="milk">
<restriction base="string">
<enumeration value="full-cream"/>
<enumeration value="semi-skimmed"/>
<enumeration value="skimmed"/>
</restriction>
</simpleType>
<simpleType name="milk">
<simpleType name="milk2">
<restriction base="test:milk">
<enumeration value="full-cream"/>
</restriction>
</simpleType>
<simpleType name="butter">
<restriction base="string">
<enumeration value="full-cream"/>
<enumeration value="semi-skimmed"/>
<enumeration value="skimmed"/>
<enumeration value="salted"/>
<enumeration value="non-salted"/>
</restriction>
</simpleType>
<simpleType name="butter">
<restriction base="string">
<enumeration value="salted"/>
<enumeration value="non-salted"/>
</restriction>
</simpleType>
</simpleType>
<element name="volume">
<complexType>
<simpleContent>
<extension base="test:chilledDecimal">
<attribute name="uom" fixed="litres" type="string"/>
<attribute name="uom" fixed="litres" type="string" form="unqualified"/>
</extension>
</simpleContent>
</complexType>
</element>
<element name="weight">
<complexType>
<simpleContent>
<extension base="test:chilledDecimal">
<attribute name="uom" fixed="kg" type="string"/>
</extension>
</simpleContent>
</complexType>
</element>
<element name="weight">
<complexType>
<simpleContent>
<extension base="test:chilledDecimal">
<attribute name="uom" fixed="kg" type="string" form="unqualified"/>
</extension>
</simpleContent>
</complexType>
</element>
<element name="fridge">
<element name="fridge">
<complexType>
<sequence>
<element name="contents">
<complexType>
<sequence>
<element name="dairyProduce" type="test:dairy_Produce" minOccurs="0"/>
</sequence>
</complexType>
</element>
</sequence>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<complexType name="dairy_Produce">
<sequence>
<element name="milk" minOccurs="1" maxOccurs="unbounded">
<complexType>
<sequence>
<element name="contents">
<complexType>
<sequence>
<element name="dairyProduce" type="test:dairy_Produce" minOccurs="0"/>
</sequence>
</complexType>
</element>
<element ref="test:volume"/>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
<attribute name="type" type="test:milk" form="unqualified"/>
<attribute name="type2" type="test:milk2" use="optional" form="unqualified"/>
</complexType>
</element>
<complexType name="dairy_Produce">
<sequence>
<element name="milk" minOccurs="1" maxOccurs="unbounded">
<complexType>
<sequence>
<element ref="volume"/>
</sequence>
<attribute name="type" type="test:milk"/>
</complexType>
</element>
<element name="butter" minOccurs="0" maxOccurs="unbounded">
<complexType>
<sequence>
<element ref="weight"/>
</sequence>
<attribute name="type" type="test:butter"/>
</complexType>
</element>
</sequence>
<attribute name="id" type="string"/>
<attribute name="xsi:type" type="string"/>
</element>
<element name="butter" minOccurs="0" maxOccurs="unbounded">
<complexType>
<sequence>
<element ref="test:weight"/>
</sequence>
<attribute name="type" type="test:butter" form="unqualified"/>
</complexType>
</element>
</sequence>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
<element name="dairy" type="test:dairy_Produce"/>
<!-- xsd:all checks -->
<element name="name" type="string"/>
<element name="born" type="date"/>
<element name="dead" type="date"/>
<element name="author">
<complexType>
<all>
<element ref="test:name"/>
<element ref="test:born"/>
<element ref="test:dead" minOccurs="0"/>
</all>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<element name="author-2">
<complexType>
<sequence>
<element ref="test:author"/>
<element ref="test:transaction"/>
</sequence>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<element name="author-3">
<complexType>
<sequence>
<element ref="test:author" minOccurs="0"/>
<element ref="test:transaction"/>
</sequence>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<element name="author-4">
<complexType>
<all minOccurs="0">
<element ref="test:name"/>
<element ref="test:born"/>
<element ref="test:dead" minOccurs="0"/>
</all>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<!-- attr group -->
<attributeGroup name="attrgroup-2">
<attributeGroup ref="test:attrgroup-1"/>
<attribute name="test" type="boolean" use="optional"/>
</attributeGroup>
<element name="balance-attrgroup-1">
<complexType>
<sequence>
<element ref="test:transaction" />
</sequence>
<attributeGroup ref="test:attrgroup-2"/>
</complexType>
</element>
<!-- group -->
<group name="group-1">
<sequence>
<element ref="test:name"/>
<element ref="test:born"/>
<element ref="test:dead" minOccurs="0"/>
</sequence>
</group>
<element name="balance-group-1">
<complexType>
<sequence>
<group ref="test:group-1" />
</sequence>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
</element>
<!-- deriviation by extension -->
<complexType name="deriv-base">
<sequence>
<element ref="test:name"/>
<element ref="test:born"/>
</sequence>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
<complexType name="deriv-ext-type-1">
<complexContent>
<extension base="test:deriv-base">
<sequence>
<element ref="test:dead"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="deriv-ext-1" id="deriv-ext-1-1" type="test:deriv-ext-type-1"/>
<!-- deriviation by restriction-->
<complexType name="deriv-res-base">
<sequence>
<element ref="test:name"/>
<element ref="test:born"/>
<element ref="test:dead" minOccurs="0"/>
</sequence>
<attribute name="id" type="string" form="unqualified" use="required"/>
</complexType>
<element name="deriv-res-1">
<complexType>
<complexContent>
<restriction base="test:deriv-res-base">
<sequence>
<element ref="test:name"/>
<element ref="test:born"/>
</sequence>
</restriction>
</complexContent>
</complexType>
</element>
<element name="deriv-res-2">
<complexType>
<complexContent>
<restriction base="test:deriv-res-base">
<sequence>
<element ref="test:name"/>
<element ref="test:born"/>
<element ref="test:dead"/>
</sequence>
</restriction>
</complexContent>
</complexType>
</element>
<!-- DERIVATION_EXTENSION_COMPLEX -->
<complexType name="personName">
<sequence>
<element name="title" type="string" minOccurs="0"/>
<element name="forename" type="string" minOccurs="0" maxOccurs="unbounded"/>
<element name="surname" type="string"/>
</sequence>
<attributeGroup ref="test:attrgroup-1"/>
</complexType>
<complexType name="extendedName">
<complexContent>
<extension base="test:personName">
<sequence>
<element name="generation" type="string" minOccurs="0"/>
</sequence>
</extension>
</complexContent>
</complexType>
<element name="deriv-ext-complex-1" type="test:extendedName"/>
<!-- DERIVATION_RESTRICTION_COMPLEX -->
<complexType name="simpleName">
<complexContent>
<restriction base="test:personName">
<sequence>
<element name="forename" type="string" minOccurs="1" maxOccurs="1"/>
<element name="surname" type="string"/>
</sequence>
</restriction>
</complexContent>
</complexType>
<element name="deriv-ext-restriction-1" type="test:simpleName"/>
</schema>