// Dwivedi, Ajay kumar Adwiv@Yahoo.com\r
// Enomoto, Atsushi ginga@kit.hi-ho.ne.jp\r
//\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System;\r
using System.Collections;\r
using System.Xml;\r
public class XmlSchemaElement : XmlSchemaParticle\r
{\r
private XmlSchemaDerivationMethod block;\r
- private XmlSchemaDerivationMethod blockResolved;\r
private XmlSchemaObjectCollection constraints;\r
private string defaultValue;\r
private object elementType;\r
+#if NET_2_0\r
+ private XmlSchemaType elementSchemaType;\r
+#endif\r
private XmlSchemaDerivationMethod final;\r
- private XmlSchemaDerivationMethod finalResolved;\r
private string fixedValue;\r
private XmlSchemaForm form;\r
private bool isAbstract;\r
private bool isNillable;\r
private string name;\r
- private XmlQualifiedName qName;\r
private XmlQualifiedName refName;\r
private XmlSchemaType schemaType;\r
private XmlQualifiedName schemaTypeName;\r
private XmlQualifiedName substitutionGroup;\r
+\r
+ // Post compilation items.\r
+ XmlSchema schema;\r
internal bool parentIsSchema = false;\r
- private string targetNamespace;\r
+ private XmlQualifiedName qName;\r
+ private XmlSchemaDerivationMethod blockResolved;\r
+ private XmlSchemaDerivationMethod finalResolved;\r
+// private XmlSchemaParticle substChoice;\r
+ private XmlSchemaElement referencedElement;\r
+ private ArrayList substitutingElements = new ArrayList ();\r
+ private XmlSchemaElement substitutionGroupElement;\r
+ private bool actualIsAbstract;\r
+ private bool actualIsNillable;\r
private string validatedDefaultValue;\r
private string validatedFixedValue;\r
- internal bool actualIsAbstract;\r
- internal bool actualIsNillable;\r
- private ArrayList substitutingElements = new ArrayList ();\r
- XmlSchemaElement referencedElement;\r
\r
- private static string xmlname = "element";\r
+ const string xmlname = "element";\r
\r
public XmlSchemaElement()\r
{\r
block = XmlSchemaDerivationMethod.None;\r
final = XmlSchemaDerivationMethod.None;\r
constraints = new XmlSchemaObjectCollection();\r
- qName = XmlQualifiedName.Empty;\r
refName = XmlQualifiedName.Empty;\r
schemaTypeName = XmlQualifiedName.Empty;\r
substitutionGroup = XmlQualifiedName.Empty;\r
- substitutionGroup = XmlQualifiedName.Empty;\r
+ InitPostCompileInformations ();\r
+ }\r
+\r
+ private void InitPostCompileInformations ()\r
+ {\r
+ qName = XmlQualifiedName.Empty;\r
+ schema = null;\r
+// parentIsSchema = false; ... it is set in Schema's Compile()\r
+ blockResolved = XmlSchemaDerivationMethod.None;\r
+ finalResolved = XmlSchemaDerivationMethod.None;\r
+// substChoice = null;\r
+ referencedElement = null;\r
+ substitutingElements.Clear ();\r
+ substitutionGroupElement = null;\r
+ actualIsAbstract = false;\r
+ actualIsNillable = false;\r
+ validatedDefaultValue = null;\r
+ validatedFixedValue = null;\r
}\r
\r
#region Attributes\r
set{ form = value; }\r
}\r
\r
- [DefaultValue(null)]\r
+ [DefaultValue("")]\r
[System.Xml.Serialization.XmlAttribute("name")]\r
public string Name \r
{\r
get{ return schemaTypeName; }\r
set{ schemaTypeName = value; }\r
}\r
+ #endregion\r
+\r
+ #region Elements\r
\r
- [XmlElement("simpleType",typeof(XmlSchemaSimpleType),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("complexType",typeof(XmlSchemaComplexType),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+ [XmlElement("simpleType",typeof(XmlSchemaSimpleType))]\r
+ [XmlElement("complexType",typeof(XmlSchemaComplexType))]\r
public XmlSchemaType SchemaType \r
{\r
get{ return schemaType; }\r
set{ schemaType = value; }\r
}\r
\r
- [XmlElement("unique",typeof(XmlSchemaUnique),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("key",typeof(XmlSchemaKey),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("keyref",typeof(XmlSchemaKeyref),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+ [XmlElement("unique",typeof(XmlSchemaUnique))]\r
+ [XmlElement("key",typeof(XmlSchemaKey))]\r
+ [XmlElement("keyref",typeof(XmlSchemaKeyref))]\r
public XmlSchemaObjectCollection Constraints \r
{\r
get{ return constraints; }\r
}\r
+ #endregion\r
\r
+ #region Post Compilation Schema Info\r
[XmlIgnore]\r
public XmlQualifiedName QualifiedName \r
{\r
}\r
\r
[XmlIgnore]\r
+#if NET_2_0\r
+ [Obsolete]\r
+#endif\r
public object ElementType \r
{\r
get {\r
return elementType;\r
}\r
}\r
- \r
+\r
+#if NET_2_0\r
+ [XmlIgnore]\r
+ public XmlSchemaType ElementSchemaType\r
+ {\r
+ get {\r
+ if (referencedElement != null)\r
+ return referencedElement.ElementSchemaType;\r
+ else\r
+ return elementSchemaType;\r
+ }\r
+ }\r
+#endif\r
+\r
[XmlIgnore]\r
public XmlSchemaDerivationMethod BlockResolved \r
{\r
}\r
}\r
\r
+ internal bool ActualIsNillable {\r
+ get {\r
+ if (referencedElement != null)\r
+ return referencedElement.ActualIsNillable;\r
+ else\r
+ return actualIsNillable;\r
+ }\r
+ }\r
+ \r
+ internal bool ActualIsAbstract {\r
+ get {\r
+ if (referencedElement != null)\r
+ return referencedElement.ActualIsAbstract;\r
+ else\r
+ return actualIsAbstract;\r
+ }\r
+ }\r
+ \r
// Post compilation default value (normalized)\r
- internal string ValidatedDefaultValue\r
- {\r
+ internal string ValidatedDefaultValue {\r
get{\r
if (referencedElement != null)\r
return referencedElement.ValidatedDefaultValue;\r
}\r
\r
// Post compilation fixed value (normalized)\r
- internal string ValidatedFixedValue \r
- {\r
+ internal string ValidatedFixedValue {\r
get{\r
if (referencedElement != null)\r
return referencedElement.ValidatedFixedValue;\r
}\r
}\r
\r
- internal ArrayList SubstitutingElements\r
- {\r
+ internal ArrayList SubstitutingElements {\r
get {\r
if (referencedElement != null)\r
return referencedElement.SubstitutingElements;\r
}\r
}\r
\r
+ internal XmlSchemaElement SubstitutionGroupElement {\r
+ get {\r
+ if (referencedElement != null)\r
+ return referencedElement.SubstitutionGroupElement;\r
+ else\r
+ return substitutionGroupElement;\r
+ }\r
+ }\r
+\r
#endregion\r
\r
/// <remarks>\r
/// 5. abstract is prohibited\r
/// 6. default and fixed must not both be present.(Actually both are absent)\r
/// </remarks> \r
- [MonoTODO]\r
internal override int Compile(ValidationEventHandler h, XmlSchema schema)\r
{\r
// If this is already compiled this time, simply skip.\r
- if (this.IsComplied (schema.CompilationId))\r
+ if (CompilationId == schema.CompilationId)\r
return 0;\r
+ InitPostCompileInformations ();\r
+ this.schema = schema;\r
+#if NET_2_0\r
+ if (SchemaType != null)\r
+ SchemaType.Parent = this;\r
+ foreach (XmlSchemaObject obj in Constraints)\r
+ obj.Parent = this;\r
+#endif\r
\r
if(this.defaultValue != null && this.fixedValue != null)\r
error(h,"both default and fixed can't be present");\r
{\r
// if((final & ~allfinal) != 0)\r
if ((final | XmlSchemaUtil.FinalAllowed) != XmlSchemaUtil.FinalAllowed)\r
- warn(h,"some values for final are invalid in this context");\r
+ error (h,"some values for final are invalid in this context");\r
finalResolved = final & allfinal;\r
}\r
\r
error(h,"substitutionGroup must be absent");\r
if(final != XmlSchemaDerivationMethod.None)\r
error(h,"final must be absent");\r
- // This is not W3C REC 3.3.3 requirement\r
-// if(isAbstract)\r
-// error(h,"abstract must be absent");\r
\r
CompileOccurence (h, schema);\r
\r
if(refName == null || RefName.IsEmpty)\r
{\r
+ string targetNamespace = String.Empty;\r
+\r
if(form == XmlSchemaForm.Qualified || (form == XmlSchemaForm.None && schema.ElementFormDefault == XmlSchemaForm.Qualified))\r
- this.targetNamespace = schema.TargetNamespace;\r
- else\r
- this.targetNamespace = "";\r
+ targetNamespace = schema.TargetNamespace;\r
\r
if(this.name == null) //b1\r
error(h,"Required attribute name must be present");\r
else if(!XmlSchemaUtil.CheckNCName(this.name)) // b1.2\r
error(h,"attribute name must be NCName");\r
else\r
- this.qName = new XmlQualifiedName(this.name, this.targetNamespace);\r
+ this.qName = new XmlQualifiedName(this.name, targetNamespace);\r
\r
- /*\r
- XmlSchemaDerivationMethod allblock = XmlSchemaDerivationMethod.Extension | \r
- XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Substitution;\r
-\r
- if(block == XmlSchemaDerivationMethod.All)\r
- blockResolved = allblock;\r
-// else if(block == XmlSchemaDerivationMethod.None)\r
-// blockResolved = allblock;\r
- else\r
- {\r
- if((block & ~allblock) != 0)\r
- warn(h,"Some of the values for block are invalid in this context");\r
- blockResolved = block & allblock;\r
- }\r
- */\r
-\r
if(schemaType != null && schemaTypeName != null && !schemaTypeName.IsEmpty)\r
{\r
error(h,"both schemaType and content can't be present");\r
break;\r
default:\r
if ((block | XmlSchemaUtil.ElementBlockAllowed) != XmlSchemaUtil.ElementBlockAllowed)\r
- warn(h,"Some of the values for block are invalid in this context");\r
+ error (h,"Some of the values for block are invalid in this context");\r
blockResolved = block;\r
break;\r
}\r
return errorCount;\r
}\r
\r
- [MonoTODO]\r
+ [MonoTODO ("Return clone in case when it returns itself")]\r
+ internal override XmlSchemaParticle GetOptimizedParticle (bool isTop)\r
+ {\r
+ if (OptimizedParticle != null)\r
+ return OptimizedParticle;\r
+ if (RefName != null && RefName != XmlQualifiedName.Empty) {\r
+ referencedElement = schema.Elements [RefName] as XmlSchemaElement;\r
+ }\r
+\r
+// if (this.referencedElement != null)\r
+// OptimizedParticle = referencedElement.GetOptimizedParticle (isTop);\r
+// else \r
+ if (ValidatedMaxOccurs == 0)\r
+ OptimizedParticle = XmlSchemaParticle.Empty;\r
+ // Substitution Group\r
+ else if (SubstitutingElements != null && SubstitutingElements.Count > 0) {\r
+ XmlSchemaChoice choice = new XmlSchemaChoice ();\r
+ choice.MinOccurs = MinOccurs;\r
+ choice.MaxOccurs = MaxOccurs;\r
+// substChoice = choice;\r
+ choice.Compile (null, schema); // compute Validated Min/Max Occurs.\r
+ XmlSchemaElement item = this.MemberwiseClone () as XmlSchemaElement;\r
+ item.MinOccurs = 1;\r
+ item.MaxOccurs = 1;\r
+ item.substitutionGroupElement = null;\r
+ item.substitutingElements = null;\r
+ for (int i = 0; i < SubstitutingElements.Count; i++) {\r
+ XmlSchemaElement se = SubstitutingElements [i] as XmlSchemaElement;\r
+// choice.Items.Add (se);\r
+// choice.CompiledItems.Add (se);\r
+ this.AddSubstElementRecursively (choice.Items, se);\r
+ this.AddSubstElementRecursively (choice.CompiledItems, se);\r
+ }\r
+ if (!choice.Items.Contains (item)) {\r
+ choice.Items.Add (item);\r
+ choice.CompiledItems.Add (item);\r
+ }\r
+ OptimizedParticle = choice;\r
+ }\r
+ else\r
+ OptimizedParticle = this;//.MemberwiseClone () as XmlSchemaElement;\r
+ return OptimizedParticle;\r
+ }\r
+\r
+ private void AddSubstElementRecursively (XmlSchemaObjectCollection col, XmlSchemaElement el)\r
+ {\r
+ if (el.SubstitutingElements != null)\r
+ for (int i = 0; i < el.SubstitutingElements.Count; i++)\r
+ this.AddSubstElementRecursively (col, el.SubstitutingElements [i] as XmlSchemaElement);\r
+ if (!col.Contains (el))\r
+ col.Add (el);\r
+ }\r
+\r
+ internal void FillSubstitutionElementInfo ()\r
+ {\r
+ if (this.substitutionGroupElement != null)\r
+ return;\r
+\r
+ if (this.SubstitutionGroup != XmlQualifiedName.Empty) {\r
+ XmlSchemaElement substElem = schema.Elements [SubstitutionGroup] as XmlSchemaElement;\r
+ this.substitutionGroupElement = substElem;\r
+ if (substElem != null)\r
+ substElem.substitutingElements.Add (this);\r
+ }\r
+ }\r
+\r
internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
{\r
if (IsValidated (schema.CompilationId))\r
this.actualIsNillable = IsNillable;\r
this.actualIsAbstract = IsAbstract;\r
\r
+ // Before determining element type, we need to validate substituting element\r
+ if (this.SubstitutionGroup != XmlQualifiedName.Empty) {\r
+ XmlSchemaElement substElem = substitutionGroupElement;\r
+ if (substElem != null)\r
+ substElem.Validate (h, schema);\r
+ }\r
+\r
// {type} from here\r
XmlSchemaDatatype datatype = null;\r
if (schemaType != null)\r
elementType = schemaType;\r
else if (SchemaTypeName != XmlQualifiedName.Empty) {\r
- XmlSchemaType type = schema.SchemaTypes [SchemaTypeName] as XmlSchemaType;\r
- // If el is null, then it is missing sub components .\r
+ XmlSchemaType type = schema.FindSchemaType (SchemaTypeName);\r
if (type != null) {\r
type.Validate (h, schema);\r
elementType = type;\r
}\r
else if (SchemaTypeName == XmlSchemaComplexType.AnyTypeName)\r
elementType = XmlSchemaComplexType.AnyType;
- else if (SchemaTypeName.Namespace == XmlSchema.Namespace) {\r
+ else if (XmlSchemaUtil.IsBuiltInDatatypeName (SchemaTypeName)) {\r
datatype = XmlSchemaDatatype.FromName (SchemaTypeName);\r
if (datatype == null)\r
error (h, "Invalid schema datatype was specified.");\r
if (refElem != null) {\r
this.referencedElement = refElem;\r
errorCount += refElem.Validate (h, schema);\r
- elementType = refElem.ElementType;\r
- this.validatedDefaultValue = refElem.validatedDefaultValue;\r
- this.validatedFixedValue = refElem.validatedFixedValue;\r
- this.actualIsAbstract = refElem.IsAbstract;\r
- this.actualIsNillable = refElem.IsNillable;\r
}\r
// otherwise, it might be missing sub components.\r
else if (!schema.IsNamespaceAbsent (RefName.Namespace))\r
error (h, "Referenced element " + RefName + " was not found in the corresponding schema.");\r
}\r
\r
- // Otherwise the -ur type- definition.\r
- if (elementType == null)\r
- elementType = XmlSchemaComplexType.AnyType;\r
+ // Otherwise if there are substitution group, then the type of the substitution group element.\r
+ if (referencedElement == null) {\r
+ if (elementType == null && this.substitutionGroupElement != null)\r
+ elementType = substitutionGroupElement.ElementType;\r
+ // Otherwise, the -ur type- definition.\r
+ if (elementType == null)\r
+ elementType = XmlSchemaComplexType.AnyType;\r
+ }\r
\r
XmlSchemaType xsType = elementType as XmlSchemaType;\r
if (xsType != null) {\r
XmlSchemaElement substElem = schema.Elements [SubstitutionGroup] as XmlSchemaElement;\r
// If el is null, then it is missing sub components .\r
if (substElem != null) {\r
- substElem.Validate (h, schema);\r
XmlSchemaType substSchemaType = substElem.ElementType as XmlSchemaType;\r
if (substSchemaType != null) {\r
// 3.3.6 Properties Correct 3.\r
if (xsSimpleType != null)\r
xsSimpleType.ValidateTypeDerivationOK (substElem.ElementType, h, schema, true);\r
}\r
- substElem.substitutingElements.Add (this);\r
+\r
}\r
// otherwise, it might be missing sub components.\r
else if (!schema.IsNamespaceAbsent (SubstitutionGroup.Namespace))\r
foreach (XmlSchemaIdentityConstraint ident in Constraints)\r
ident.Validate (h, schema);\r
\r
+#if NET_2_0\r
+ if (elementType != null) {\r
+ elementSchemaType = elementType as XmlSchemaType;\r
+ if (elementType == XmlSchemaSimpleType.AnySimpleType)\r
+ elementSchemaType = XmlSchemaSimpleType.XsAnySimpleType;\r
+ if (elementSchemaType == null)\r
+ elementSchemaType = XmlSchemaType.GetBuiltInSimpleType (SchemaTypeName);\r
+ }\r
+#endif\r
+\r
ValidationId = schema.ValidationId;\r
return errorCount;\r
}\r
\r
- internal override void ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,\r
- ValidationEventHandler h, XmlSchema schema)\r
+ internal override bool ParticleEquals (XmlSchemaParticle other)\r
+ {\r
+ XmlSchemaElement element = other as XmlSchemaElement;\r
+ if (element == null)\r
+ return false;\r
+ if (this.ValidatedMaxOccurs != element.ValidatedMaxOccurs ||\r
+ this.ValidatedMinOccurs != element.ValidatedMinOccurs)\r
+ return false;\r
+ if (this.QualifiedName != element.QualifiedName ||\r
+ this.ElementType != element.ElementType ||\r
+ this.Constraints.Count != element.Constraints.Count)\r
+ return false;\r
+ for (int i = 0; i < this.Constraints.Count; i++) {\r
+ XmlSchemaIdentityConstraint c1 = Constraints [i] as XmlSchemaIdentityConstraint;\r
+ XmlSchemaIdentityConstraint c2 = element.Constraints [i] as XmlSchemaIdentityConstraint;\r
+ if (c1.QualifiedName != c2.QualifiedName ||\r
+ c1.Selector.XPath != c2.Selector.XPath ||\r
+ c1.Fields.Count != c2.Fields.Count)\r
+ return false;\r
+ for (int f = 0; f < c1.Fields.Count; f++) {\r
+ XmlSchemaXPath f1 = c1.Fields [f] as XmlSchemaXPath;\r
+ XmlSchemaXPath f2 = c2.Fields [f] as XmlSchemaXPath;\r
+ if (f1.XPath != f2.XPath)\r
+ return false;\r
+ }\r
+ }\r
+ if (this.BlockResolved != element.BlockResolved ||\r
+ this.FinalResolved != element.FinalResolved ||\r
+ this.ValidatedDefaultValue != element.ValidatedDefaultValue ||\r
+ this.ValidatedFixedValue != element.ValidatedFixedValue)\r
+ return false;\r
+ return true;\r
+ }\r
+\r
+ internal override bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,\r
+ ValidationEventHandler h, XmlSchema schema, bool raiseError)\r
{\r
+ // element - NameAndTypeOK\r
XmlSchemaElement baseElement = baseParticle as XmlSchemaElement;\r
if (baseElement != null) {\r
- ValidateDerivationByRestrictionNameAndTypeOK (baseElement, h, schema);\r
- return;\r
+ return ValidateDerivationByRestrictionNameAndTypeOK (baseElement, h, schema, raiseError);\r
}\r
\r
+ // any - NSCompat\r
XmlSchemaAny baseAny = baseParticle as XmlSchemaAny;\r
if (baseAny != null) {\r
// NSCompat\r
- baseAny.ValidateWildcardAllowsNamespaceName (this.QualifiedName.Namespace, h, schema, true);\r
- ValidateOccurenceRangeOK (baseAny, h, schema);\r
- return;\r
+ if (!baseAny.ValidateWildcardAllowsNamespaceName (this.QualifiedName.Namespace, h, schema, raiseError))\r
+ return false;\r
+ return ValidateOccurenceRangeOK (baseAny, h, schema, raiseError);\r
}\r
+\r
+//*\r
+ // choice - RecurseAsIfGroup\r
+ XmlSchemaGroupBase gb = null;\r
+ if (baseParticle is XmlSchemaSequence)\r
+ gb = new XmlSchemaSequence ();\r
+ else if (baseParticle is XmlSchemaChoice)\r
+ gb = new XmlSchemaChoice ();\r
+ else if (baseParticle is XmlSchemaAll)\r
+ gb = new XmlSchemaAll ();\r
+\r
+ if (gb != null) {\r
+ gb.Items.Add (this);\r
+ gb.Compile (h, schema);\r
+ gb.Validate (h, schema);\r
+ // It looks weird, but here we never think about \r
+ // _pointlessness_ of this groupbase particle.\r
+ return gb.ValidateDerivationByRestriction (baseParticle, h, schema, raiseError);\r
+ }\r
+//*/\r
+ return true;\r
}\r
\r
- private void ValidateDerivationByRestrictionNameAndTypeOK (XmlSchemaElement baseElement,\r
- ValidationEventHandler h, XmlSchema schema)\r
+ private bool ValidateDerivationByRestrictionNameAndTypeOK (XmlSchemaElement baseElement,\r
+ ValidationEventHandler h, XmlSchema schema, bool raiseError)\r
{\r
// 1.\r
- if (this.QualifiedName != baseElement.QualifiedName)\r
- error (h, "Invalid derivation by restriction of particle was found. Both elements must have the same name.");\r
+ if (this.QualifiedName != baseElement.QualifiedName) {\r
+ if (raiseError)\r
+ error (h, "Invalid derivation by restriction of particle was found. Both elements must have the same name.");\r
+ return false;\r
+ }\r
// 2.\r
- if (this.isNillable && !baseElement.isNillable)\r
- error (h, "Invalid element derivation by restriction of particle was found. Base element is not nillable and derived type is nillable.");\r
+ if (this.isNillable && !baseElement.isNillable) {\r
+ if (raiseError)\r
+ error (h, "Invalid element derivation by restriction of particle was found. Base element is not nillable and derived type is nillable.");\r
+ return false;\r
+ }\r
// 3.\r
- ValidateOccurenceRangeOK (baseElement, h, schema);\r
+ if (!ValidateOccurenceRangeOK (baseElement, h, schema, raiseError))\r
+ return false;\r
// 4.\r
if (baseElement.ValidatedFixedValue != null &&\r
- baseElement.ValidatedFixedValue != this.ValidatedFixedValue)\r
- error (h, "Invalid element derivation by restriction of particle was found. Both fixed value must be the same.");\r
+ baseElement.ValidatedFixedValue != this.ValidatedFixedValue) {\r
+ if (raiseError)\r
+ error (h, "Invalid element derivation by restriction of particle was found. Both fixed value must be the same.");\r
+ return false;\r
+ }\r
// 5. TODO: What is "identity constraints subset" ???\r
\r
// 6. \r
- if ((baseElement.BlockResolved | this.BlockResolved) != this.BlockResolved)\r
- error (h, "Invalid derivation by restriction of particle was found. Derived element must contain all of the base element's block value.");\r
+ if ((baseElement.BlockResolved | this.BlockResolved) != this.BlockResolved) {\r
+ if (raiseError)\r
+ error (h, "Invalid derivation by restriction of particle was found. Derived element must contain all of the base element's block value.");\r
+ return false;\r
+ }\r
// 7.\r
if (baseElement.ElementType != null) {\r
XmlSchemaComplexType derivedCType = this.ElementType as XmlSchemaComplexType;\r
- if (derivedCType != null)\r
- // W3C REC says that it is Type Derivation OK to be check, but\r
+ if (derivedCType != null) {\r
+ // FIXME: W3C REC says that it is Type Derivation OK to be check, but\r
// in fact it should be DerivationValid (Restriction, Complex).\r
derivedCType.ValidateDerivationValidRestriction (\r
baseElement.ElementType as XmlSchemaComplexType, h, schema);\r
- // derivedCType.ValidateTypeDerivationOK (baseElement.ElementType, h, schema);\r
- else {\r
+ derivedCType.ValidateTypeDerivationOK (baseElement.ElementType, h, schema);\r
+ } else {\r
XmlSchemaSimpleType derivedSType = this.ElementType as XmlSchemaSimpleType;\r
if (derivedSType != null)\r
derivedSType.ValidateTypeDerivationOK (baseElement.ElementType, h, schema, true);\r
- else if (baseElement.ElementType != this.ElementType)\r
- error (h, "Invalid element derivation by restriction of particle was found. Both primitive types differ.");\r
+ else if (baseElement.ElementType != XmlSchemaComplexType.AnyType && baseElement.ElementType != this.ElementType) {\r
+ if (raiseError)\r
+ error (h, "Invalid element derivation by restriction of particle was found. Both primitive types differ.");\r
+ return false;\r
+ }\r
}\r
}\r
+ return true;\r
}\r
\r
internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)\r
{\r
XmlSchemaComplexType ct = this.ElementType as XmlSchemaComplexType;\r
- if (ct == null || ct.ContentTypeParticle == null)\r
+ if (ct == null || ct.Particle == null)\r
return;\r
- ct.ContentTypeParticle.CheckRecursion (depth + 1, h, schema);\r
+ ct.Particle.CheckRecursion (depth + 1, h, schema);\r
}\r
\r
internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames, ArrayList nsNames,\r
ValidationEventHandler h, XmlSchema schema)\r
{\r
- if (qnames.Contains (this.QualifiedName))\r
+ if (qnames.Contains (this.QualifiedName))// && !this.ParticleEquals ((XmlSchemaParticle) qnames [this.QualifiedName]))\r
error (h, "Ambiguous element label was detected: " + this.QualifiedName);\r
else {\r
foreach (XmlSchemaAny any in nsNames) {\r
continue;\r
if (any.HasValueAny ||\r
any.HasValueLocal && this.QualifiedName.Namespace == "" ||\r
- any.HasValueOther && this.QualifiedName.Namespace != this.targetNamespace ||\r
- any.HasValueTargetNamespace && this.QualifiedName.Namespace == this.targetNamespace) {\r
+ any.HasValueOther && this.QualifiedName.Namespace != this.QualifiedName.Namespace ||\r
+ any.HasValueTargetNamespace && this.QualifiedName.Namespace == this.QualifiedName.Namespace) {\r
error (h, "Ambiguous element label which is contained by -any- particle was detected: " + this.QualifiedName);\r
break;\r
- } else {\r
+ } else if (!any.HasValueOther) {\r
bool bad = false;\r
foreach (string ns in any.ResolvedNamespaces) {\r
if (ns == this.QualifiedName.Namespace) {\r
error (h, "Ambiguous element label which is contained by -any- particle was detected: " + this.QualifiedName);\r
break;\r
}\r
+ } else {\r
+ if (any.TargetNamespace != this.QualifiedName.Namespace)\r
+ error (h, "Ambiguous element label which is contained by -any- particle with ##other value was detected: " + this.QualifiedName);\r
}\r
}\r
qnames.Add (this.QualifiedName, this);\r
element.block = XmlSchemaUtil.ReadDerivationAttribute(reader,out innerex, "block",\r
XmlSchemaUtil.ElementBlockAllowed);\r
if(innerex != null)\r
- warn(h,"some invalid values for block attribute were found",innerex);\r
+ error (h,"some invalid values for block attribute were found",innerex);\r
}\r
else if(reader.Name == "default")\r
{\r
element.Final = XmlSchemaUtil.ReadDerivationAttribute(reader,out innerex, "final",\r
XmlSchemaUtil.FinalAllowed);\r
if(innerex != null)\r
- warn(h,"some invalid values for final attribute were found",innerex);\r
+ error (h,"some invalid values for final attribute were found",innerex);\r
}\r
else if(reader.Name == "fixed")\r
{\r