зеркало из https://github.com/mozilla/gecko-dev.git
Bug 335367 - add support for xsd:import. Patch by sspeiche, r=me
This commit is contained in:
Родитель
14f5109950
Коммит
94b5c794b4
|
@ -29,7 +29,7 @@
|
|||
function validateDOMNode(aNodeValue, aType, aNSPrefix, aIsValid) {
|
||||
var rv = false;
|
||||
|
||||
var x = dp.parseFromString('<test xmlns:test="http://www.mozilla.org/schema/test" xmlns="http://www.mozilla.org/schema/test" xmlns:xsi="http://www.w3.org/1999/XMLSchema" xsi:type="' + aNSPrefix + ":" + aType + '">' + aNodeValue + '</test>', "text/xml");
|
||||
var x = dp.parseFromString('<test xmlns:test="http://www.mozilla.org/schema/test" xmlns:testi="http://www.mozilla.org/schema/test_imported" xmlns="http://www.mozilla.org/schema/test" xmlns:xsi="http://www.w3.org/1999/XMLSchema" xsi:type="' + aNSPrefix + ":" + aType + '">' + aNodeValue + '</test>', "text/xml");
|
||||
|
||||
rv = getValidator().validate(x.documentElement);
|
||||
|
||||
|
@ -44,6 +44,13 @@
|
|||
results[results.length] = {type: aType, nodevalue: aNodeValue, rv: rv, isvalid: aIsValid};
|
||||
}
|
||||
|
||||
function validateStringNS(aNodeValue, aType, aNS, aIsValid) {
|
||||
var rv = getValidator().validateString(aNodeValue, aType, aNS);
|
||||
|
||||
counter++;
|
||||
results[results.length] = {type: aType, nodevalue: aNodeValue, rv: rv, isvalid: aIsValid};
|
||||
}
|
||||
|
||||
function validateSimpleTypeString(aNodeValue, aType, aIsValid) {
|
||||
var rv = getValidator().validateString(aNodeValue, aType, "http://www.w3.org/1999/XMLSchema");
|
||||
|
||||
|
@ -634,6 +641,21 @@
|
|||
validate("Applicant Trustee Supplier", "IndividualRoleListType5", false);
|
||||
validate("Applicant Trustee", "IndividualRoleListType5", true);
|
||||
|
||||
validateStringNS("220", "import-integer-test-1", "http://www.mozilla.org/schema/test_imported", false);
|
||||
validateStringNS("6", "import-integer-test-1", "http://www.mozilla.org/schema/test_imported", true);
|
||||
|
||||
validateStringNS("-220", "import-integer-test-2", "http://www.mozilla.org/schema/test_imported2", false);
|
||||
validateStringNS( "-2", "import-integer-test-2", "http://www.mozilla.org/schema/test_imported2", true);
|
||||
|
||||
validateStringNS("220", "include-integer-test-1", "http://www.mozilla.org/schema/test_imported", false);
|
||||
validateStringNS("6", "include-integer-test-1", "http://www.mozilla.org/schema/test_imported", true);
|
||||
|
||||
validateStringNS("220", "include-integer-test-2", "http://www.mozilla.org/schema/test_imported", false);
|
||||
validateStringNS("6", "include-integer-test-2", "http://www.mozilla.org/schema/test_imported", true);
|
||||
|
||||
validateStringNS("220", "include-integer-test-3", "http://www.mozilla.org/schema/test_imported", false);
|
||||
validateStringNS("6", "include-integer-test-3", "http://www.mozilla.org/schema/test_imported", true);
|
||||
|
||||
}
|
||||
|
||||
end = new Date();
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
attributeFormDefault="qualified"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<import namespace="http://www.mozilla.org/schema/test_imported" schemaLocation="schema_imported.xsd" />
|
||||
|
||||
<simpleType name="integer-test-1">
|
||||
<restriction base='integer'>
|
||||
<totalDigits value="3"/>
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" ?>
|
||||
<schema targetNamespace="http://www.mozilla.org/schema/test_imported"
|
||||
xmlns:test="http://www.mozilla.org/schema/test_imported"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="qualified"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<import namespace="http://www.mozilla.org/schema/test_imported2" schemaLocation="schema_imported2.xsd" />
|
||||
|
||||
<include schemaLocation="schema_no_ns.xsd" />
|
||||
<include schemaLocation="schema_ns.xsd" />
|
||||
|
||||
<simpleType name="import-integer-test-1">
|
||||
<restriction base='integer'>
|
||||
<maxExclusive value="10"/>
|
||||
<minExclusive value="5"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
|
||||
</schema>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" ?>
|
||||
<schema targetNamespace="http://www.mozilla.org/schema/test_imported2"
|
||||
xmlns:test="http://www.mozilla.org/schema/test_imported2"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="qualified"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<simpleType name="import-integer-test-2">
|
||||
<restriction base='integer'>
|
||||
<maxExclusive value="-1"/>
|
||||
<minExclusive value="-5"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
|
||||
</schema>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" ?>
|
||||
<schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="qualified"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<include schemaLocation="schema_no_ns2.xsd" />
|
||||
|
||||
<simpleType name="include-integer-test-1">
|
||||
<restriction base='integer'>
|
||||
<maxExclusive value="10"/>
|
||||
<minExclusive value="5"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
|
||||
</schema>
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" ?>
|
||||
<schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="qualified"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<simpleType name="include-integer-test-2">
|
||||
<restriction base='integer'>
|
||||
<maxExclusive value="10"/>
|
||||
<minExclusive value="5"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
|
||||
</schema>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" ?>
|
||||
<schema targetNamespace="http://www.mozilla.org/schema/test_imported"
|
||||
xmlns:test="http://www.mozilla.org/schema/test_imported"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
|
||||
attributeFormDefault="qualified"
|
||||
xmlns="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<simpleType name="include-integer-test-3">
|
||||
<restriction base='integer'>
|
||||
<maxExclusive value="10"/>
|
||||
<minExclusive value="5"/>
|
||||
</restriction>
|
||||
</simpleType>
|
||||
|
||||
|
||||
</schema>
|
||||
|
|
@ -786,7 +786,6 @@ nsSchemaLoader::ProcessSchemaElement(nsIDOMElement* aElement,
|
|||
|
||||
// For now, ignore the following
|
||||
// annotations
|
||||
// import
|
||||
// redefine
|
||||
// notation
|
||||
// identity-constraint elements
|
||||
|
@ -842,13 +841,24 @@ nsSchemaLoader::ProcessSchemaElement(nsIDOMElement* aElement,
|
|||
rv = schemaInst->AddModelGroup(modelGroup);
|
||||
}
|
||||
}
|
||||
else if (tagName == nsSchemaAtoms::sInclude_atom) {
|
||||
/* http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-include
|
||||
else if (tagName == nsSchemaAtoms::sInclude_atom ||
|
||||
tagName == nsSchemaAtoms::sImport_atom) {
|
||||
/* Mixing the handling of <include> and <import> as they are very similar,
|
||||
other than a few requirements regarding namespaces.
|
||||
|
||||
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-include
|
||||
If we include a schema, it must either
|
||||
(a) have the same targetNamespace as the including schema document or
|
||||
(b) no targetNamespace at all
|
||||
|
||||
If the uri to load doesn't resolve, it isn't a error. It is if it's an
|
||||
http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/structures.html#element-import
|
||||
When importing a schema, it must either
|
||||
(a) if namespace is defined, then namespace == imported
|
||||
targetNamespace
|
||||
(b) if namespace is not defined, then imported schema must NOT
|
||||
have a targetNamespace
|
||||
|
||||
If the uri to load doesn't resolve, it isn't a error. It is if its an
|
||||
invalid XML document or not a schema file
|
||||
*/
|
||||
|
||||
|
@ -937,6 +947,13 @@ nsSchemaLoader::ProcessSchemaElement(nsIDOMElement* aElement,
|
|||
|
||||
// XXX: check the target namespace requirements
|
||||
|
||||
// If <import>, simply call self to do all the heavy lifting
|
||||
if (tagName == nsSchemaAtoms::sImport_atom) {
|
||||
rv = ProcessSchemaElement(element, nsnull, aResult);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
continue;
|
||||
}
|
||||
|
||||
// import/append all elements in the included file to our schema element
|
||||
nsCOMPtr<nsIDOMDocument> ownerDoc;
|
||||
rv = childElement->GetOwnerDocument(getter_AddRefs(ownerDoc));
|
||||
|
@ -977,7 +994,6 @@ nsSchemaLoader::ProcessSchemaElement(nsIDOMElement* aElement,
|
|||
iterator.SetElement(aElement);
|
||||
iterator.Reset(index);
|
||||
} else if (tagName != nsSchemaAtoms::sAnnotation_atom &&
|
||||
tagName != nsSchemaAtoms::sImport_atom &&
|
||||
tagName != nsSchemaAtoms::sRedefine_atom &&
|
||||
tagName != nsSchemaAtoms::sNotation_atom) {
|
||||
// if it is none of these, unexpected element.
|
||||
|
|
Загрузка…
Ссылка в новой задаче