--- /dev/null
+Bugs in Implementation:\r
+\r
+1. XmlSchema.Read Fails if there is a wrong value for a enum type. Eg form="none" will throw an exception.\r
+ The only conformant solution to this is using our own Deserializer or parser.\r
+2. Schema Compile ignores errors where a name or id (or any other attribute) is empty. Eg if a schama has name="",\r
+ it will not throw an exception but will be silently ignored. Again the solution is to write own parser.\r
+3. Not all Compile methods check for the Id attribute. Trivial but needs to be done.\r
+4. Need to check if errorCount is calculted correctly, and all of the error() methods increase it.\r
+2002-05-25 Dwivedi, Ajay kumar <adwiv@yahoo.com>
+ * BUGS.txt: New file to keep track of bugs
+
+ * ALL: All classes are initialized exactly as in .NET except
+ 1. inclusion of language attribute in schema
+ 2. ComplexContent's Particle is initialized to null whereas .NET
+ to some internal implementation. IMO Null is more appropriate
+
+ * ALL: Changed the Compile methods to return the count of errors.
+
+ * ALL: Complile methods are almost complete. Pass 1453 of 3061 tests.
+ This number should shoot up if we write a parser to read the
+ Schema instead of using reflection (which is slower too)
+
2002-05-04 Dwivedi, Ajay kumar <adwiv@yahoo.com>
* XmlSchemaUtil.cs: New file added.
/// </summary>\r
/// <remarks>\r
/// 1. blockDefault must be one of #all | List of (extension | restriction | substitution)\r
- /// 2. finalDefault must be one of (#all | List of (extension | restriction))\r
- /// BUGS: MS Implementation allows union and list on finaldefault. Why?\r
+ /// 2. finalDefault must be one of (#all | List of (extension | restriction| union| list))\r
/// 3. id must be of type ID\r
/// 4. targetNamespace should be any uri\r
/// 5. version should be a token\r
if((this.blockDefault & XmlSchemaDerivationMethod.Union)!=0 )\r
error(handler, "union is not allowed in blockDefault attribute");\r
}\r
- //2. List, Union and Substitution are not allowed in finaldefault.\r
+ //2. Substitution is not allowed in finaldefault.\r
if(this.finalDefault != XmlSchemaDerivationMethod.All)\r
{\r
- if((this.finalDefault & XmlSchemaDerivationMethod.List)!=0 )\r
- error(handler, "list is not allowed in finalDefault attribute");\r
- if((this.finalDefault & XmlSchemaDerivationMethod.Union)!=0 )\r
- error(handler, "union is not allowed in finalDefault attribute");\r
if((this.finalDefault & XmlSchemaDerivationMethod.Substitution)!=0 )\r
error(handler, "substitution is not allowed in finalDefault attribute");\r
}\r
//3. id must be of type ID\r
- if(!XmlSchemaUtil.CheckID(this.id))\r
+ if(this.id != null && !XmlSchemaUtil.CheckID(this.id))\r
error(handler, "id attribute is not a valid ID");\r
\r
//4. targetNamespace should be of type anyURI\r
info = new XmlSchemaInfo();\r
if(this.targetNamespace != null && XmlSchemaUtil.CheckAnyUri(this.targetNamespace))\r
info.targetNS = this.TargetNamespace;\r
- info.finalDefault = (FinalDefault & XmlSchemaDerivationMethod.Extension & XmlSchemaDerivationMethod.Restriction);\r
- info.blockDefault = (blockDefault & XmlSchemaDerivationMethod.Extension & \r
- XmlSchemaDerivationMethod.Restriction & XmlSchemaDerivationMethod.Substitution);\r
+ \r
+ if(this.ElementFormDefault != XmlSchemaForm.Qualified)\r
+ info.formDefault = XmlSchemaForm.Unqualified;\r
+ else\r
+ info.formDefault = XmlSchemaForm.Qualified;\r
+\r
+ if(FinalDefault == XmlSchemaDerivationMethod.All)\r
+ info.finalDefault = XmlSchemaDerivationMethod.All;\r
+ else // If finalDefault is None, info's finalDefault is set to empty\r
+ info.finalDefault = (FinalDefault & (XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction));\r
+\r
+ if(BlockDefault == XmlSchemaDerivationMethod.All)\r
+ info.blockDefault = XmlSchemaDerivationMethod.All;\r
+ else // If finalDefault is None, info's blockDefault is set to empty\r
+ info.blockDefault = (blockDefault & (XmlSchemaDerivationMethod.Extension |\r
+ XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Substitution));\r
\r
// Compile the content of this schema\r
foreach(XmlSchemaObject obj in Includes)\r
{\r
if(obj is XmlSchemaAnnotation)\r
{\r
- if(((XmlSchemaAnnotation)obj).Compile(handler,info))\r
+ if(((XmlSchemaAnnotation)obj).Compile(handler,info) == 0)\r
{\r
//FIXME: What PSVI set do we add this to?\r
}\r
else if(obj is XmlSchemaAttribute)\r
{\r
XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
- if(attr.Compile(handler,info))\r
+ attr.parentIsSchema = true;\r
+ if(attr.Compile(handler,info) == 0)\r
{\r
- attr.parentIsSchema = true;\r
Attributes.Add(attr.QualifiedName, attr);\r
}\r
}\r
else if(obj is XmlSchemaAttributeGroup)\r
{\r
XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup) obj;\r
- if(attrgrp.Compile(handler,info))\r
+ if(attrgrp.Compile(handler,info) == 0)\r
{\r
AttributeGroups.Add(attrgrp.QualifiedName, attrgrp);\r
}\r
else if(obj is XmlSchemaComplexType)\r
{\r
XmlSchemaComplexType ctype = (XmlSchemaComplexType) obj;\r
- if(ctype.Compile(handler,info))\r
+ ctype.istoplevel = true;\r
+ if(ctype.Compile(handler,info) == 0)\r
{\r
schemaTypes.Add(ctype.QualifiedName, ctype);\r
}\r
else if(obj is XmlSchemaSimpleType)\r
{\r
XmlSchemaSimpleType stype = (XmlSchemaSimpleType) obj;\r
- if(stype.Compile(handler,info))\r
+ stype.islocal = false; //This simple type is toplevel\r
+ if(stype.Compile(handler,info) == 0)\r
{\r
SchemaTypes.Add(stype.QualifiedName, stype);\r
}\r
else if(obj is XmlSchemaElement)\r
{\r
XmlSchemaElement elem = (XmlSchemaElement) obj;\r
- if(elem.Compile(handler,info))\r
+ elem.parentIsSchema = true;\r
+ if(elem.Compile(handler,info) == 0)\r
{\r
Elements.Add(elem.QualifiedName,elem);\r
}\r
else if(obj is XmlSchemaGroup)\r
{\r
XmlSchemaGroup grp = (XmlSchemaGroup) obj;\r
- if(grp.Compile(handler,info))\r
+ if(grp.Compile(handler,info) == 0)\r
{\r
Groups.Add(grp.QualifiedName,grp);\r
}\r
else if(obj is XmlSchemaNotation)\r
{\r
XmlSchemaNotation ntn = (XmlSchemaNotation) obj;\r
- if(ntn.Compile(handler,info))\r
+ if(ntn.Compile(handler,info) == 0)\r
{\r
Notations.Add(ntn.QualifiedName, ntn);\r
}\r
public class XmlSchemaAll : XmlSchemaGroupBase\r
{\r
private XmlSchemaObjectCollection items;\r
+ private int errorCount=0;\r
public XmlSchemaAll()\r
{\r
items = new XmlSchemaObjectCollection();\r
{\r
get{ return items; }\r
}\r
+ /// <remarks>\r
+ /// 1. MaxOccurs must be one. (default is also one)\r
+ /// 2. MinOccurs must be zero or one.\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(MaxOccurs != Decimal.One)\r
+ error(h,"maxOccurs must be 1");\r
+ if(MinOccurs != Decimal.One && MinOccurs != Decimal.Zero)\r
+ error(h,"minOccurs must be 0 or 1");\r
+\r
+ foreach(XmlSchemaObject obj in Items)\r
+ {\r
+ if(obj is XmlSchemaElement)\r
+ {\r
+ errorCount += ((XmlSchemaElement)obj).Compile(h,info);\r
+ }\r
+ else\r
+ {\r
+ error(h,"XmlSchemaAll can only contain Items of type Element");\r
+ }\r
+ }\r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
}\r
\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
- return false;\r
+ return 1;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
{\r
- return false;\r
+ return 1;\r
}\r
}\r
}\r
{\r
private string nameSpace;\r
private XmlSchemaContentProcessing processing;\r
+ private int errorCount = 0;\r
\r
public XmlSchemaAny()\r
{\r
- nameSpace = string.Empty;\r
}\r
\r
[System.Xml.Serialization.XmlAttribute("namespace")]\r
get{ return processing; } \r
set{ processing = value; }\r
}\r
+\r
+ /// <remarks>\r
+ /// 1. id must be of type ID\r
+ /// 2. namespace can have one of the following values:\r
+ /// a) ##any or ##other\r
+ /// b) list of anyURI and ##targetNamespace and ##local\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ errorCount = 0;\r
+\r
+ if(Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ {\r
+ error(h, "id attribute must be a valid ID");\r
+ }\r
+ //define ##any=1,##other=2,##targetNamespace=4,##local=8,anyURI=16\r
+ int nscount = 0;\r
+ string[] nslist = XmlSchemaUtil.SplitList(Namespace);\r
+ foreach(string ns in nslist)\r
+ {\r
+ switch(ns)\r
+ {\r
+ case "##any": \r
+ nscount |= 1;\r
+ break;\r
+ case "##other":\r
+ nscount |= 2;\r
+ break;\r
+ case "##targetNamespace":\r
+ nscount |= 4;\r
+ break;\r
+ case "##local":\r
+ nscount |= 8;\r
+ break;\r
+ default:\r
+ if(!XmlSchemaUtil.CheckAnyUri(ns))\r
+ error(h,"the namespace is not a valid anyURI");\r
+ else\r
+ nscount |= 16;\r
+ break;\r
+ }\r
+ }\r
+ if((nscount&1) == 1 && nscount != 1)\r
+ error(h,"##any if present must be the only namespace attribute");\r
+ if((nscount&2) == 2 && nscount != 2)\r
+ error(h,"##other if present must be the only namespace attribute");\r
+ \r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
{\r
private string nameSpace;\r
private XmlSchemaContentProcessing processing;\r
+ private int errorCount;\r
\r
public XmlSchemaAnyAttribute()\r
{\r
- nameSpace = string.Empty;\r
}\r
\r
[System.Xml.Serialization.XmlAttribute("namespace")]\r
get{ return processing; } \r
set{ processing = value; }\r
}\r
+\r
+ /// <remarks>\r
+ /// 1. id must be of type ID\r
+ /// 2. namespace can have one of the following values:\r
+ /// a) ##any or ##other\r
+ /// b) list of anyURI and ##targetNamespace and ##local\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ errorCount = 0;\r
+\r
+ if(Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ {\r
+ error(h, "id attribute must be a valid ID");\r
+ }\r
+ //define ##any=1,##other=2,##targetNamespace=4,##local=8,anyURI=16\r
+ int nscount = 0;\r
+ string[] nslist = XmlSchemaUtil.SplitList(Namespace);\r
+ foreach(string ns in nslist)\r
+ {\r
+ switch(ns)\r
+ {\r
+ case "##any": \r
+ nscount |= 1;\r
+ break;\r
+ case "##other":\r
+ nscount |= 2;\r
+ break;\r
+ case "##targetNamespace":\r
+ nscount |= 4;\r
+ break;\r
+ case "##local":\r
+ nscount |= 8;\r
+ break;\r
+ default:\r
+ if(!XmlSchemaUtil.CheckAnyUri(ns))\r
+ error(h,"the namespace is not a valid anyURI");\r
+ else\r
+ nscount |= 16;\r
+ break;\r
+ }\r
+ }\r
+ if((nscount&1) == 1 && nscount != 1)\r
+ error(h,"##any if present must be the only namespace attribute");\r
+ if((nscount&2) == 2 && nscount != 2)\r
+ error(h,"##other if present must be the only namespace attribute");\r
+ \r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+ \r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ this.errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
\r
public XmlSchemaAppInfo()\r
{\r
- source = string.Empty;\r
}\r
\r
[XmlAnyElement]\r
private XmlSchemaUse use;\r
//Compilation fields\r
internal bool parentIsSchema = false;\r
- internal XmlSchema schema = null;\r
- internal bool errorOccured = false;\r
+ internal int errorCount;\r
\r
public XmlSchemaAttribute()\r
{\r
/// 14. name must not be xmlns\r
/// 15. Targetnamespace must not be xsi. This implies the target namespace of schema can't be xsi if toplevel attributes are used.\r
/// 16. *Exception to rule 15* inbuilt attributes: xsi:nil, xsi:type, xsi:schemaLocation, xsi: noNamespaceSchemaLocation\r
- /// b) *TODO*: If the parent is complextype and ref is not set\r
- /// c) *TODO*: if the parent is not schema and ref is set\r
+ /// b) If the parent is complextype and ref is not set\r
+ /// 1. name must be present and of type NCName.\r
+ /// 2. type and <simpleType> must not both be present.\r
+ /// 3. default and fixed must not both be present. \r
+ /// 4. If default and use are both present, use must have the ·actual value· optional.\r
+ /// 5. name must not be xmlns\r
+ /// 6. Targetnamespace must not be xsi.\r
+ /// 7. *Exception to rule 15* inbuilt attributes: xsi:nil, xsi:type, xsi:schemaLocation, xsi: noNamespaceSchemaLocation\r
+ /// 8. If form has actual value qualified or the schema's formdefault is qualified, targetnamespace\r
+ /// is same as schema's target namespace, otherwise absent.\r
+ /// c) if the parent is not schema and ref is set\r
+ /// 1. name must not be present\r
+ /// 2. all of <simpleType>, form and type must be absent. \r
+ /// 3. default and fixed must not both be present. \r
+ /// 4. If default and use are both present, use must have the ·actual value· optional.\r
/// </remarks>\r
[MonoTODO]\r
//FIXME: Should we set a property to null if an error occurs? Or should we stop the validation?\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
+ errorCount = 0;\r
+ \r
if(parentIsSchema)//a\r
{\r
if(this.refName!= null && !this.refName.IsEmpty) // a.1\r
if(this.use != XmlSchemaUse.None) // a.3\r
error(h,"use must be absent in the top level <attribute>");\r
\r
- if(this.name == null) //a.4\r
- error(h,"name must be present if attribute has schema as its parent");\r
- else if(!XmlSchemaUtil.CheckNCName(this.name)) // a.4.2\r
+ // TODO: a.10, a.11, a.12, a.13\r
+ CompileCommon(h,info, true);\r
+ }\r
+ else // local\r
+ {\r
+ if(this.refName == null || this.refName.IsEmpty)\r
+ {\r
+ //TODO: b.8\r
+ CompileCommon(h,info, true);\r
+ }\r
+ else\r
+ {\r
+ if(this.name != null)\r
+ error(h,"name must be absent if ref is present");\r
+ if(this.form != XmlSchemaForm.None)\r
+ error(h,"form must be absent if ref is present");\r
+ if(this.schemaType != null)\r
+ error(h,"simpletype must be absent if ref is present");\r
+ if(this.schemaTypeName != null && !this.schemaTypeName.IsEmpty)\r
+ error(h,"type must be absent if ref is present");\r
+ CompileCommon(h,info,false);\r
+ }\r
+ }\r
+\r
+ return errorCount;\r
+ }\r
+ \r
+ private void CompileCommon(ValidationEventHandler h, XmlSchemaInfo info, bool refIsNotPresent)\r
+ {\r
+ if(refIsNotPresent)\r
+ {\r
+ if(this.name == null) //a.4, b.1, \r
+ error(h,"Required attribute name must be present");\r
+ else if(!XmlSchemaUtil.CheckNCName(this.name)) // a.4.2, b1.2\r
error(h,"attribute name must be NCName");\r
- else if(this.name == "xmlns") // a.14 \r
+ else if(this.name == "xmlns") // a.14 , b5\r
error(h,"attribute name can't be xmlns");\r
else\r
this.qualifiedName = new XmlQualifiedName(this.name, info.targetNS); \r
- \r
- // TODO: a.10, a.11, a.12, a.13\r
- if(this.defaultValue != null && this.fixedValue != null) // a.6\r
- error(h,"default and fixed must not both be present in an Attribute");\r
\r
if(this.schemaType != null)\r
{\r
error(h,"attribute can't have both a type and <simpleType> content");\r
else \r
{\r
- this.SchemaType.islocal = true;\r
- this.schemaType.Compile(h,info); \r
+ errorCount += this.schemaType.Compile(h,info); \r
}\r
}\r
-\r
- if(info.targetNS == XmlSchema.InstanceNamespace && this.name != "nil" && this.name != "type" \r
- && this.name != "schemaLocation" && this.name != "noNamespaceSchemaLocation") // a.15, a.16\r
- error(h,"targetNamespace can't be " + XmlSchema.InstanceNamespace);\r
-\r
}\r
-// TODO: \r
-// else\r
-// {\r
-// }\r
- if(!XmlSchemaUtil.CheckID(this.Id))\r
- error(h,"id must be a valid ID");\r
+ else\r
+ {\r
+ // redundant since we call function after check\r
+ //if(this.refName == null || this.refName.IsEmpty) \r
+ // error(h,"refname must be present");\r
+ this.qualifiedName = this.refName;\r
+ }\r
+ if(info.targetNS == XmlSchema.InstanceNamespace && this.name != "nil" && this.name != "type" \r
+ && this.name != "schemaLocation" && this.name != "noNamespaceSchemaLocation") // a.15, a.16\r
+ error(h,"targetNamespace can't be " + XmlSchema.InstanceNamespace);\r
+\r
+ if(this.defaultValue != null && this.fixedValue != null) // a.6, b.3, c.3\r
+ error(h,"default and fixed must not both be present in an Attribute");\r
\r
- return !errorOccured;\r
+ if(this.defaultValue != null && this.use != XmlSchemaUse.None && this.use != XmlSchemaUse.Optional)\r
+ error(h,"if default is present, use must be optional");\r
+ \r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h,"id attribute must be a valid ID");\r
}\r
- \r
+\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
{\r
- return false;\r
+ return errorCount;\r
}\r
\r
internal void error(ValidationEventHandler handle,string message)\r
{\r
- this.errorOccured = true;\r
+ this.errorCount++;\r
ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
private string name;\r
private XmlSchemaAttributeGroup redefined;\r
private XmlQualifiedName qualifiedName;\r
+ private int errorCount;\r
\r
public XmlSchemaAttributeGroup()\r
{\r
attributes = new XmlSchemaObjectCollection();\r
- //FIXME:\r
- redefined = this;\r
}\r
\r
[XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]\r
get{ return qualifiedName;}\r
}\r
\r
+ /// <remarks>\r
+ /// An Attribute group can only be defined as a child of XmlSchema or in XmlSchemaRedefine.\r
+ /// The other attributeGroup has type XmlSchemaAttributeGroupRef.\r
+ /// 1. Name must be present\r
+ /// </remarks>\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
- return false;\r
+ errorCount = 0;\r
+\r
+ if(this.Name == null) //1\r
+ error(h,"Name is required in top level simpletype");\r
+ else if(!XmlSchemaUtil.CheckNCName(this.Name)) // b.1.2\r
+ error(h,"name attribute of a simpleType must be NCName");\r
+ else\r
+ this.qualifiedName = new XmlQualifiedName(this.Name,info.targetNS);\r
+ \r
+ if(this.AnyAttribute != null)\r
+ {\r
+ errorCount += this.AnyAttribute.Compile(h,info);\r
+ }\r
+ \r
+ foreach(XmlSchemaObject obj in Attributes)\r
+ {\r
+ if(obj is XmlSchemaAttribute)\r
+ {\r
+ XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
+ errorCount += attr.Compile(h, info);\r
+ }\r
+ else if(obj is XmlSchemaAttributeGroupRef)\r
+ {\r
+ XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef) obj;\r
+ errorCount += gref.Compile(h, info);\r
+ }\r
+ else\r
+ {\r
+ error(h,"invalid type of object in Attributes property");\r
+ }\r
+ }\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+ \r
+ internal void error(ValidationEventHandler handle,string message)\r
{\r
- return false;\r
+ this.errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
}\r
public class XmlSchemaAttributeGroupRef : XmlSchemaAnnotated\r
{\r
private XmlQualifiedName refName;\r
+ private int errorCount;\r
\r
public XmlSchemaAttributeGroupRef()\r
- {}\r
+ {\r
+ refName = XmlQualifiedName.Empty;\r
+ }\r
\r
[System.Xml.Serialization.XmlAttribute("ref")]\r
public XmlQualifiedName RefName \r
get{ return refName; }\r
set{ refName = value; }\r
}\r
+\r
+ /// <remarks>\r
+ /// 1. ref must be present\r
+ /// 2. The element must be empty. FIXME: does it mean no id attribute too??\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ errorCount = 0;\r
+ if(this.refName == null || this.refName.IsEmpty)\r
+ error(h, "ref must be present");\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+ if(this.Annotation != null)\r
+ error(h, "attributegroup with a ref can't have any content");\r
+ \r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+ \r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ this.errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
public class XmlSchemaChoice : XmlSchemaGroupBase\r
{\r
private XmlSchemaObjectCollection items;\r
+ private int errorCount=0;\r
public XmlSchemaChoice()\r
{\r
items = new XmlSchemaObjectCollection();\r
{\r
get{ return items; }\r
}\r
+\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ foreach(XmlSchemaObject obj in Items)\r
+ {\r
+ if(obj is XmlSchemaElement)\r
+ {\r
+ errorCount += ((XmlSchemaElement)obj).Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaGroupRef)\r
+ {\r
+ errorCount += ((XmlSchemaGroupRef)obj).Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaChoice)\r
+ {\r
+ errorCount += ((XmlSchemaChoice)obj).Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaSequence)\r
+ {\r
+ errorCount += ((XmlSchemaSequence)obj).Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaAny)\r
+ {\r
+ errorCount += ((XmlSchemaAny)obj).Compile(h,info);\r
+ }\r
+ }\r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
{\r
private XmlSchemaContent content;\r
private bool isMixed;\r
+ private int errorCount=0;\r
\r
public XmlSchemaComplexContent()\r
{}\r
get{ return isMixed; } \r
set{ isMixed = value; }\r
}\r
+\r
+ /// <remarks>\r
+ /// 1. Content must be present\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(Content == null)\r
+ {\r
+ error(h, "Content must be present in a complexContent");\r
+ }\r
+ else\r
+ {\r
+ if(Content is XmlSchemaComplexContentRestriction)\r
+ {\r
+ XmlSchemaComplexContentRestriction xscr = (XmlSchemaComplexContentRestriction) Content;\r
+ errorCount += xscr.Compile(h,info);\r
+ }\r
+ else if(Content is XmlSchemaComplexContentExtension)\r
+ {\r
+ XmlSchemaComplexContentExtension xsce = (XmlSchemaComplexContentExtension) Content;\r
+ errorCount += xsce.Compile(h,info);\r
+ }\r
+ else\r
+ error(h,"complexContent can't have any value other than restriction or extention");\r
+ }\r
+\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+\r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
private XmlSchemaObjectCollection attributes;\r
private XmlQualifiedName baseTypeName;\r
private XmlSchemaParticle particle;\r
+ private int errorCount = 0;\r
+\r
public XmlSchemaComplexContentExtension()\r
{\r
attributes = new XmlSchemaObjectCollection();\r
+ baseTypeName = XmlQualifiedName.Empty;\r
}\r
\r
[System.Xml.Serialization.XmlAttribute("base")]\r
get{ return baseTypeName; }\r
set{ baseTypeName = value; }\r
}\r
+\r
[XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]\r
public XmlSchemaAnyAttribute AnyAttribute \r
{\r
get{ return particle; }\r
set{ particle = value; }\r
}\r
+\r
+ /// <remarks>\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(BaseTypeName == null || BaseTypeName.IsEmpty)\r
+ {\r
+ error(h, "base must be present and a QName");\r
+ }\r
+ \r
+ if(this.AnyAttribute != null)\r
+ {\r
+ errorCount += AnyAttribute.Compile(h,info);\r
+ }\r
+\r
+ foreach(XmlSchemaObject obj in Attributes)\r
+ {\r
+ if(obj is XmlSchemaAttribute)\r
+ {\r
+ XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
+ errorCount += attr.Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaAttributeGroupRef)\r
+ {\r
+ XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;\r
+ errorCount += atgrp.Compile(h,info);\r
+ }\r
+ else\r
+ error(h,"object is not valid in this place");\r
+ }\r
+ \r
+ if(Particle != null)\r
+ {\r
+ if(Particle is XmlSchemaGroupRef)\r
+ {\r
+ errorCount += ((XmlSchemaGroupRef)Particle).Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaAll)\r
+ {\r
+ errorCount += ((XmlSchemaAll)Particle).Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaChoice)\r
+ {\r
+ errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaSequence)\r
+ {\r
+ errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);\r
+ }\r
+ }\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+ \r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
private XmlSchemaObjectCollection attributes;\r
private XmlQualifiedName baseTypeName;\r
private XmlSchemaParticle particle;\r
+ private int errorCount = 0;\r
\r
public XmlSchemaComplexContentRestriction()\r
{\r
get{ return particle; }\r
set{ particle = value; }\r
}\r
+\r
+ /// <remarks>\r
+ /// 1. base must be present\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(BaseTypeName == null || BaseTypeName.IsEmpty)\r
+ {\r
+ error(h, "base must be present and a QName");\r
+ }\r
+ \r
+ if(this.AnyAttribute != null)\r
+ {\r
+ errorCount += AnyAttribute.Compile(h,info);\r
+ }\r
+\r
+ foreach(XmlSchemaObject obj in Attributes)\r
+ {\r
+ if(obj is XmlSchemaAttribute)\r
+ {\r
+ XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
+ errorCount += attr.Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaAttributeGroupRef)\r
+ {\r
+ XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;\r
+ errorCount += atgrp.Compile(h,info);\r
+ }\r
+ else\r
+ error(h,"object is not valid in this place");\r
+ }\r
+ \r
+ if(Particle != null)\r
+ {\r
+ if(Particle is XmlSchemaGroupRef)\r
+ {\r
+ errorCount += ((XmlSchemaGroupRef)Particle).Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaAll)\r
+ {\r
+ errorCount += ((XmlSchemaAll)Particle).Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaChoice)\r
+ {\r
+ errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaSequence)\r
+ {\r
+ errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);\r
+ }\r
+ }\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+ \r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
private bool isAbstract;\r
private bool isMixed;\r
private XmlSchemaParticle particle;\r
+ \r
+ private int errorCount;\r
+ internal bool istoplevel = false;\r
\r
public XmlSchemaComplexType()\r
{\r
attributes = new XmlSchemaObjectCollection();\r
block = XmlSchemaDerivationMethod.None;\r
+ attributeUses = new XmlSchemaObjectTable();\r
}\r
\r
#region Attributes\r
set{ contentModel = value; }\r
}\r
\r
+ //LAMESPEC: The default value for particle in Schema is of Type EmptyParticle (internal?)\r
+ //But since Particle is a PSVI \r
[XmlElement("group",typeof(XmlSchemaGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]\r
[XmlElement("all",typeof(XmlSchemaAll),Namespace="http://www.w3.org/2001/XMLSchema")]\r
[XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")]\r
}\r
#endregion\r
\r
+ /// <remarks>\r
+ /// 1. If ContentModel is present, neither particle nor Attributes nor AnyAttribute can be present.\r
+ /// 2. If particle is present, \r
+ /// a. For a topLevelComplexType\r
+ /// 1. name must be present and type NCName\r
+ /// 2. if block is #all, blockdefault is #all, else List of (extension | restriction)\r
+ /// 3. if final is #all, finaldefault is #all, else List of (extension | restriction)\r
+ /// b. For a local Complex type \r
+ /// 1. abstract must be false\r
+ /// 2. Name must be absent\r
+ /// 3. final must be absent\r
+ /// 4. block must be absent\r
+ /// \r
+ /// </remarks>\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
- return false;\r
+ if(istoplevel)\r
+ {\r
+ if(this.Name == null || this.Name == string.Empty)\r
+ error(h,"name must be present in a top level complex type");\r
+ else\r
+ {\r
+ if(!XmlSchemaUtil.CheckNCName(Name))\r
+ error(h,"name must be a NCName");\r
+ else\r
+ this.qName = new XmlQualifiedName(info.targetNS, Name);\r
+ }\r
+ if(Block != XmlSchemaDerivationMethod.None)\r
+ {\r
+ if(Block == XmlSchemaDerivationMethod.All)\r
+ {\r
+ blockResolved = XmlSchemaDerivationMethod.All;\r
+ }\r
+ else\r
+ {\r
+ //TODO: Check what all is not allowed\r
+ blockResolved = Block & (XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if(info.blockDefault == XmlSchemaDerivationMethod.All)\r
+ {\r
+ blockResolved = XmlSchemaDerivationMethod.All;\r
+ }\r
+ else\r
+ blockResolved = info.blockDefault & (XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction);\r
+ }\r
+ if(Final != XmlSchemaDerivationMethod.None)\r
+ {\r
+ if(Final == XmlSchemaDerivationMethod.All)\r
+ {\r
+ finalResolved = XmlSchemaDerivationMethod.All;\r
+ }\r
+ else\r
+ {\r
+ //TODO: Check what all is not allowed\r
+ finalResolved = Final & (XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if(info.finalDefault == XmlSchemaDerivationMethod.All)\r
+ {\r
+ finalResolved = XmlSchemaDerivationMethod.All;\r
+ }\r
+ else\r
+ {\r
+ finalResolved = info.blockDefault & (XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction);\r
+ }\r
+ }\r
+ }\r
+ else // Not Top Level\r
+ {\r
+ if(isAbstract)\r
+ error(h,"abstract must be false in a local complex type");\r
+ if(Name != null)\r
+ error(h,"name must be absent in a local complex type");\r
+ if(Final != XmlSchemaDerivationMethod.None)\r
+ error(h,"final must be absent in a local complex type");\r
+ if(block != XmlSchemaDerivationMethod.None)\r
+ error(h,"block must be absent in a local complex type");\r
+ }\r
+\r
+ if(ContentModel != null)\r
+ {\r
+ if(anyAttribute != null || Attributes.Count != 0 || Particle != null)\r
+ error(h,"attributes, particles or anyattribute is not allowed if ContentModel is present");\r
+\r
+ if(ContentModel is XmlSchemaSimpleContent)\r
+ {\r
+ XmlSchemaSimpleContent smodel = (XmlSchemaSimpleContent)ContentModel;\r
+ errorCount += smodel.Compile(h,info);\r
+ }\r
+ else if(ContentModel is XmlSchemaComplexContent)\r
+ {\r
+ XmlSchemaComplexContent cmodel = (XmlSchemaComplexContent)ContentModel;\r
+ errorCount += cmodel.Compile(h,info);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if(Particle is XmlSchemaGroupRef)\r
+ {\r
+ XmlSchemaGroupRef xsgr = (XmlSchemaGroupRef)Particle;\r
+ errorCount += xsgr.Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaAll)\r
+ {\r
+ XmlSchemaAll xsa = (XmlSchemaAll)Particle;\r
+ errorCount += xsa.Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaChoice)\r
+ {\r
+ XmlSchemaChoice xsc = (XmlSchemaChoice)Particle;\r
+ errorCount += xsc.Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaSequence)\r
+ {\r
+ XmlSchemaSequence xss = (XmlSchemaSequence)Particle;\r
+ errorCount += xss.Compile(h,info);\r
+ }\r
+\r
+ if(this.anyAttribute != null)\r
+ {\r
+ AnyAttribute.Compile(h,info);\r
+ }\r
+ foreach(XmlSchemaObject obj in Attributes)\r
+ {\r
+ if(obj is XmlSchemaAttribute)\r
+ {\r
+ XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
+ attr.Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaAttributeGroup)\r
+ {\r
+ XmlSchemaAttributeGroup atgrp = (XmlSchemaAttributeGroup) obj;\r
+ atgrp.Compile(h,info);\r
+ }\r
+ else\r
+ error(h,"object is not valid in this place");\r
+ }\r
+ \r
+ }\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
{\r
- return false;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
}\r
private XmlSchemaType schemaType;\r
private XmlQualifiedName schemaTypeName;\r
private XmlQualifiedName substitutionGroup;\r
+ internal bool parentIsSchema = false;\r
+ private int errorCount;\r
+ private string targetNamespace;\r
\r
public XmlSchemaElement()\r
{\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
+\r
substitutionGroup = XmlQualifiedName.Empty;\r
}\r
\r
\r
#endregion\r
\r
+ /// <remarks>\r
+ /// a) If Element has parent as schema:\r
+ /// 1. name must be present and of type NCName.\r
+ /// 2. ref must be absent\r
+ /// 3. form must be absent\r
+ /// 4. minOccurs must be absent\r
+ /// 5. maxOccurs must be absent\r
+ /// b) If Element has parent is not schema and ref is absent\r
+ /// 1. name must be present and of type NCName.\r
+ /// 2. if form equals qualified or form is absent and schema's formdefault is qualifed,\r
+ /// targetNamespace is schema's targetnamespace else empty.\r
+ /// 3. type and either <simpleType> or <complexType> are mutually exclusive\r
+ /// 4. default and fixed must not both be present.\r
+ /// 5. substitutiongroup must be absent\r
+ /// 6. final must be absent\r
+ /// 7. abstract must be absent\r
+ /// c) if the parent is not schema and ref is set\r
+ /// 1. name must not be present\r
+ /// 2. all of <simpleType>,<complexType>, <key>, <keyref>, <unique>, nillable, \r
+ /// default, fixed, form, block and type, must be absent.\r
+ /// 3. substitutiongroup is prohibited\r
+ /// 4. final is prohibited\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 bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
- return false;\r
+ \r
+ if(this.defaultValue != null && this.fixedValue != null)\r
+ error(h,"both default and fixed can't be present");\r
+\r
+ if(parentIsSchema)\r
+ {\r
+ if(this.refName != null && !RefName.IsEmpty)\r
+ error(h,"ref must be absent");\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, info.targetNS);\r
+ \r
+ if(form != XmlSchemaForm.None)\r
+ error(h,"form must be absent");\r
+ if(MinOccursString != null)\r
+ error(h,"minOccurs must be absent");\r
+ if(MaxOccursString != null)\r
+ error(h,"maxOccurs must be absent");\r
+\r
+ \r
+ if(final == XmlSchemaDerivationMethod.All)\r
+ finalResolved = XmlSchemaDerivationMethod.All;\r
+ else if(final == XmlSchemaDerivationMethod.None)\r
+ finalResolved = info.blockDefault & (XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction);\r
+ else \r
+ finalResolved = final & (XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction);\r
+\r
+ if(block == XmlSchemaDerivationMethod.All)\r
+ blockResolved = XmlSchemaDerivationMethod.All;\r
+ else if(block == XmlSchemaDerivationMethod.None)\r
+ blockResolved = info.blockDefault & (XmlSchemaDerivationMethod.Extension | \r
+ XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Substitution);\r
+ else \r
+ blockResolved = block & (XmlSchemaDerivationMethod.Extension | \r
+ XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Substitution);\r
+\r
+ if(schemaType != null && schemaTypeName != null && !schemaTypeName.IsEmpty)\r
+ {\r
+ error(h,"both schemaType and content can't be present");\r
+ }\r
+ else\r
+ {\r
+ if(schemaType != null)\r
+ {\r
+ if(schemaType is XmlSchemaSimpleType)\r
+ errorCount += ((XmlSchemaSimpleType)schemaType).Compile(h,info);\r
+ else if(schemaType is XmlSchemaComplexType)\r
+ errorCount += ((XmlSchemaComplexType)schemaType).Compile(h,info);\r
+ else\r
+ error(h,"only simpletype or complextype is allowed");\r
+ }\r
+ else\r
+ {\r
+ if(schemaTypeName == null || schemaTypeName.IsEmpty)\r
+ error(h,"one of schemaType or schemaTypeName must be present");\r
+ }\r
+ }\r
+\r
+ foreach(XmlSchemaObject obj in constraints)\r
+ {\r
+ if(obj is XmlSchemaUnique)\r
+ ((XmlSchemaUnique)obj).Compile(h,info);\r
+ else if(obj is XmlSchemaKey)\r
+ ((XmlSchemaKey)obj).Compile(h,info);\r
+ else if(obj is XmlSchemaKeyref)\r
+ ((XmlSchemaKeyref)obj).Compile(h,info);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if(substitutionGroup != null && !substitutionGroup.IsEmpty)\r
+ error(h,"substitutionGroup must be absent");\r
+ if(final != XmlSchemaDerivationMethod.None)\r
+ error(h,"final must be absent");\r
+ if(isAbstract)\r
+ error(h,"abstract must be absent");\r
+\r
+ if(refName == null || RefName.IsEmpty)\r
+ {\r
+ if(form == XmlSchemaForm.Qualified || (form == XmlSchemaForm.None && info.formDefault == XmlSchemaForm.Qualified))\r
+ this.targetNamespace = info.targetNS;\r
+ else\r
+ this.targetNamespace = string.Empty;\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
+ \r
+ if(block == XmlSchemaDerivationMethod.All)\r
+ blockResolved = XmlSchemaDerivationMethod.All;\r
+ else if(block == XmlSchemaDerivationMethod.None)\r
+ blockResolved = info.blockDefault & (XmlSchemaDerivationMethod.Extension | \r
+ XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Substitution);\r
+ else \r
+ blockResolved = block & (XmlSchemaDerivationMethod.Extension | \r
+ XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Substitution);\r
+\r
+ if(schemaType != null && schemaTypeName != null && !schemaTypeName.IsEmpty)\r
+ {\r
+ error(h,"both schemaType and content can't be present");\r
+ }\r
+ else\r
+ {\r
+ if(schemaType != null)\r
+ {\r
+ if(schemaType is XmlSchemaSimpleType)\r
+ errorCount += ((XmlSchemaSimpleType)schemaType).Compile(h,info);\r
+ else if(schemaType is XmlSchemaComplexType)\r
+ errorCount += ((XmlSchemaComplexType)schemaType).Compile(h,info);\r
+ else\r
+ error(h,"only simpletype or complextype is allowed");\r
+ }\r
+ else\r
+ {\r
+ if(schemaTypeName == null || schemaTypeName.IsEmpty)\r
+ error(h,"one of schemaType or schemaTypeName must be present");\r
+ }\r
+ }\r
+\r
+ foreach(XmlSchemaObject obj in constraints)\r
+ {\r
+ if(obj is XmlSchemaUnique)\r
+ ((XmlSchemaUnique)obj).Compile(h,info);\r
+ else if(obj is XmlSchemaKey)\r
+ ((XmlSchemaKey)obj).Compile(h,info);\r
+ else if(obj is XmlSchemaKeyref)\r
+ ((XmlSchemaKeyref)obj).Compile(h,info);\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if(name != null)\r
+ error(h,"name must not be present when ref is present");\r
+ if(Constraints.Count != 0)\r
+ error(h,"key, keyref and unique must be absent");\r
+ if(isNillable)\r
+ error(h,"nillable must be absent");\r
+ if(defaultValue != null)\r
+ error(h,"default must be absent");\r
+ if(fixedValue != null)\r
+ error(h,"fixed must be null");\r
+ if(form != XmlSchemaForm.None)\r
+ error(h,"form must be absent");\r
+ if(block != XmlSchemaDerivationMethod.None)\r
+ error(h,"block must be absent");\r
+ if(schemaTypeName != null && !schemaTypeName.IsEmpty)\r
+ error(h,"type must be absent");\r
+ if(SchemaType != null)\r
+ error(h,"simpleType or complexType must be absent");\r
+ }\r
+ }\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
{\r
- return false;\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
}\r
\r
protected XmlSchemaFacet()\r
{\r
- val = string.Empty;\r
}\r
+\r
[DefaultValue(false)]\r
[System.Xml.Serialization.XmlAttribute("fixed")]\r
public virtual bool IsFixed \r
get{ return isFixed; }\r
set{ isFixed = value; }\r
}\r
+ \r
[System.Xml.Serialization.XmlAttribute("value")]\r
public string Value\r
{\r
private string name;\r
private XmlSchemaGroupBase particle;\r
private XmlQualifiedName qualifiedName;\r
+ private int errorCount;\r
\r
public XmlSchemaGroup()\r
{\r
get{ return qualifiedName;}\r
}\r
\r
+ // 1. name must be present\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
- return false;\r
+ if(Name == null)\r
+ error(h,"Required attribute name must be present");\r
+ else if(!XmlSchemaUtil.CheckNCName(this.name)) \r
+ error(h,"attribute name must be NCName");\r
+ else\r
+ qualifiedName = new XmlQualifiedName(Name,info.targetNS);\r
+ \r
+ if(Particle == null)\r
+ {\r
+ error(h,"Particle is required");\r
+ }\r
+ else if(Particle is XmlSchemaChoice)\r
+ {\r
+ errorCount += ((XmlSchemaChoice)Particle).Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaSequence)\r
+ {\r
+ errorCount += ((XmlSchemaSequence)Particle).Compile(h,info);\r
+ }\r
+ else if(Particle is XmlSchemaAll)\r
+ {\r
+ errorCount += ((XmlSchemaAll)Particle).Compile(h,info);\r
+ }\r
+ else\r
+ {\r
+ error(h,"only all,choice or sequence are allowed");\r
+ }\r
+\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+ \r
+ internal void error(ValidationEventHandler handle,string message)\r
{\r
- return false;\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
}\r
{\r
private XmlSchemaGroupBase particle;\r
private XmlQualifiedName refName;\r
+ private int errorCount=0;\r
public XmlSchemaGroupRef()\r
{\r
+ refName = XmlQualifiedName.Empty;\r
}\r
[XmlIgnore]\r
public XmlSchemaGroupBase Particle \r
get{ return refName; } \r
set{ refName = value; }\r
}\r
+ /// <remarks>\r
+ /// 1. RefName must be present\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(refName == null || refName.IsEmpty)\r
+ {\r
+ error(h,"ref must be present");\r
+ }\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+ \r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
private string name;\r
private XmlQualifiedName qName;\r
private XmlSchemaXPath selector;\r
+ private int errorCount = 0;\r
\r
public XmlSchemaIdentityConstraint()\r
{\r
{\r
get{ return qName; }\r
}\r
+ /// <remarks>\r
+ /// 1. name must be present\r
+ /// 2. selector and field must be present\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(Name == null)\r
+ error(h,"Required attribute name must be present");\r
+ else if(!XmlSchemaUtil.CheckNCName(this.name)) \r
+ error(h,"attribute name must be NCName");\r
+ else\r
+ this.qName = new XmlQualifiedName(Name,info.targetNS);\r
+\r
+ //TODO: Compile Xpath. \r
+ if(Selector == null)\r
+ error(h,"selector must be present");\r
+ \r
+ if(Fields.Count == 0)\r
+ error(h,"atleast one field value must be present");\r
+\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle, string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle, this, message);\r
+ }\r
}\r
}\r
internal string targetNS;\r
internal XmlSchemaDerivationMethod finalDefault;\r
internal XmlSchemaDerivationMethod blockDefault;\r
+ internal XmlSchemaForm formDefault;\r
}\r
}\r
/// </summary>\r
public class XmlSchemaKey : XmlSchemaIdentityConstraint\r
{\r
+ private int errorCount;\r
+\r
public XmlSchemaKey()\r
{\r
}\r
+ /// <remarks>\r
+ /// 1. name must be present\r
+ /// 2. selector and field must be present\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal new int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ return base.Compile(h,info);\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal new void error(ValidationEventHandler handle, string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle, this, message);\r
+ }\r
}\r
}\r
public class XmlSchemaKeyref : XmlSchemaIdentityConstraint\r
{\r
private XmlQualifiedName refer;\r
+ private int errorCount;\r
\r
public XmlSchemaKeyref()\r
{\r
+ refer = XmlQualifiedName.Empty;\r
}\r
\r
[System.Xml.Serialization.XmlAttribute("refer")]\r
get{ return refer; } \r
set{ refer = value; }\r
}\r
+ /// <remarks>\r
+ /// 1. name must be present\r
+ /// 2. selector and field must be present\r
+ /// 3. refer must be present\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal new int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ errorCount = base.Compile(h,info);\r
+ if(refer == null || refer.IsEmpty)\r
+ error(h,"refer must be present");\r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal new void error(ValidationEventHandler handle, string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle, this, message);\r
+ }\r
}\r
}\r
private string pub;\r
private string system;\r
private XmlQualifiedName qualifiedName;\r
+ private int errorCount;\r
\r
public XmlSchemaNotation()\r
{\r
get{ return qualifiedName;}\r
}\r
\r
+ // 1. name and public must be present\r
+ // public and system must be anyURI\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
- return false;\r
+ if(Name == null)\r
+ error(h,"Required attribute name must be present");\r
+ else if(!XmlSchemaUtil.CheckNCName(this.name)) \r
+ error(h,"attribute name must be NCName");\r
+ else\r
+ qualifiedName = new XmlQualifiedName(Name,info.targetNS);\r
+\r
+ if(Public==null||Public == "")\r
+ error(h,"public must be present");\r
+ else if(!XmlSchemaUtil.CheckAnyUri(Public))\r
+ error(h,"public must be anyURI");\r
+\r
+ if(system != null && XmlSchemaUtil.CheckAnyUri(system))\r
+ error(h,"system must be anyURI");\r
+\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+ \r
+ internal void error(ValidationEventHandler handle,string message)\r
{\r
- return false;\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
}\r
private int linePosition;\r
private string sourceUri;\r
private XmlSerializerNamespaces namespaces;\r
- \r
+\r
protected XmlSchemaObject()\r
{\r
namespaces = new XmlSerializerNamespaces();\r
\r
public XmlSchemaRedefine()\r
{\r
+ attributeGroups = new XmlSchemaObjectTable();\r
+ groups = new XmlSchemaObjectTable();\r
+ items = new XmlSchemaObjectCollection(this);\r
+ schemaTypes = new XmlSchemaObjectTable();\r
}\r
[XmlIgnore]\r
public XmlSchemaObjectTable AttributeGroups \r
public class XmlSchemaSequence : XmlSchemaGroupBase\r
{\r
private XmlSchemaObjectCollection items;\r
+ private int errorCount=0;\r
public XmlSchemaSequence()\r
{\r
items = new XmlSchemaObjectCollection();\r
{\r
get{ return items; }\r
}\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ foreach(XmlSchemaObject obj in Items)\r
+ {\r
+ if(obj is XmlSchemaElement)\r
+ {\r
+ errorCount += ((XmlSchemaElement)obj).Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaGroupRef)\r
+ {\r
+ errorCount += ((XmlSchemaGroupRef)obj).Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaChoice)\r
+ {\r
+ errorCount += ((XmlSchemaChoice)obj).Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaSequence)\r
+ {\r
+ errorCount += ((XmlSchemaSequence)obj).Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaAny)\r
+ {\r
+ errorCount += ((XmlSchemaAny)obj).Compile(h,info);\r
+ }\r
+ }\r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
public class XmlSchemaSimpleContent : XmlSchemaContentModel\r
{\r
private XmlSchemaContent content;\r
+ private int errorCount;\r
\r
public XmlSchemaSimpleContent()\r
{\r
get{ return content; } \r
set{ content = value; }\r
}\r
+\r
+ ///<remarks>\r
+ /// 1. Content must be present and one of restriction or extention\r
+ ///</remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(Content == null)\r
+ {\r
+ error(h, "Content must be present in a simpleContent");\r
+ }\r
+ else\r
+ {\r
+ if(Content is XmlSchemaSimpleContentRestriction)\r
+ {\r
+ XmlSchemaSimpleContentRestriction xscr = (XmlSchemaSimpleContentRestriction) Content;\r
+ errorCount += xscr.Compile(h,info);\r
+ }\r
+ else if(Content is XmlSchemaSimpleContentExtension)\r
+ {\r
+ XmlSchemaSimpleContentExtension xsce = (XmlSchemaSimpleContentExtension) Content;\r
+ errorCount += xsce.Compile(h,info);\r
+ }\r
+ else\r
+ error(h,"simpleContent can't have any value other than restriction or extention");\r
+ }\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
private XmlSchemaAnyAttribute any;\r
private XmlSchemaObjectCollection attributes;\r
private XmlQualifiedName baseTypeName;\r
+ private int errorCount=0;\r
\r
public XmlSchemaSimpleContentExtension()\r
{\r
get{ return baseTypeName; }\r
set{ baseTypeName = value; }\r
}\r
+ ///<remarks>\r
+ /// 1. Base must be present and a QName\r
+ ///</remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(BaseTypeName == null || BaseTypeName.IsEmpty)\r
+ {\r
+ error(h, "base must be present and a QName");\r
+ }\r
+ \r
+ if(this.AnyAttribute != null)\r
+ {\r
+ AnyAttribute.Compile(h,info);\r
+ }\r
+\r
+ foreach(XmlSchemaObject obj in Attributes)\r
+ {\r
+ if(obj is XmlSchemaAttribute)\r
+ {\r
+ XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
+ attr.Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaAttributeGroup)\r
+ {\r
+ XmlSchemaAttributeGroup atgrp = (XmlSchemaAttributeGroup) obj;\r
+ atgrp.Compile(h,info);\r
+ }\r
+ else\r
+ error(h,"object is not valid in this place");\r
+ }\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+\r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
private XmlSchemaSimpleType baseType;\r
private XmlQualifiedName baseTypeName;\r
private XmlSchemaObjectCollection facets;\r
+ private int errorCount=0;\r
\r
public XmlSchemaSimpleContentRestriction()\r
{\r
{ \r
get{ return facets; } \r
}\r
+ ///<remarks>\r
+ /// 1. Base must be present and a QName\r
+ ///</remarks>\r
+ [MonoTODO]\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ if(BaseTypeName == null || BaseTypeName.IsEmpty)\r
+ {\r
+ error(h, "base must be present and a QName");\r
+ }\r
+\r
+ if(BaseType != null)\r
+ {\r
+ errorCount += BaseType.Compile(h,info);\r
+ }\r
+\r
+ if(this.AnyAttribute != null)\r
+ {\r
+ errorCount += AnyAttribute.Compile(h,info);\r
+ }\r
+\r
+ foreach(XmlSchemaObject obj in Attributes)\r
+ {\r
+ if(obj is XmlSchemaAttribute)\r
+ {\r
+ XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
+ errorCount += attr.Compile(h,info);\r
+ }\r
+ else if(obj is XmlSchemaAttributeGroupRef)\r
+ {\r
+ XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;\r
+ errorCount += atgrp.Compile(h,info);\r
+ }\r
+ else\r
+ error(h,"object is not valid in this place");\r
+ }\r
+ \r
+ //TODO: Compile Facets: Looks like they are a part of datatypes. So we'll do them with the datatypes\r
+\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(Id))\r
+ error(h, "id must be a valid ID");\r
+ return errorCount;\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal void error(ValidationEventHandler handle,string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle,this,message);\r
+ }\r
}\r
}\r
{\r
private XmlSchemaSimpleTypeContent content;\r
//compilation vars\r
- internal bool islocal = false;\r
- private bool errorOccured = false;\r
+ internal bool islocal = true; // Assuming local means we have to specify islocal=false only in XmlSchema\r
+ private int errorCount;\r
\r
public XmlSchemaSimpleType()\r
{\r
/// 4.2 otherwise simple ur-type\r
/// </remarks>\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
+ errorCount = 0;\r
+\r
if(this.islocal) // a\r
{\r
if(this.Name != null) // a.1\r
else\r
this.qName = new XmlQualifiedName(this.Name,info.targetNS);\r
\r
- XmlSchemaDerivationMethod finaltmp;\r
-\r
- // The possible values of finalDefault on schema are #all | List of (extension | restriction)\r
- // Of these, the only possible values for us are #all | restriction.\r
- if(this.Final != XmlSchemaDerivationMethod.None)\r
- finaltmp = this.Final;\r
- else\r
- finaltmp = info.finalDefault;// & XmlSchemaDerivationMethod.Restriction;\r
- \r
- switch(finaltmp) //b.3, b.4, b.5\r
+ //NOTE: Although the FinalResolved can be Empty, it is not a valid value for Final\r
+ //DEVIATION: If an error occurs, the finaldefault is always consulted. This deviates\r
+ // from the way MS implementation works.\r
+ switch(this.Final) //b.3, b.4\r
{\r
+ // Invalid values: Throw error and use "prohibited substitutions"\r
case XmlSchemaDerivationMethod.Substitution:\r
error(h,"substition is not a valid value for final in a simpletype");\r
- break;\r
+ goto case XmlSchemaDerivationMethod.None;\r
case XmlSchemaDerivationMethod.Extension:\r
error(h,"extension is not a valid value for final in a simpletype");\r
- break;\r
- case XmlSchemaDerivationMethod.Union:\r
- error(h,"union is not a valid value for final in simpletype");\r
- break;\r
+ goto case XmlSchemaDerivationMethod.None;\r
case XmlSchemaDerivationMethod.Empty:\r
- this.finalResolved = XmlSchemaDerivationMethod.Empty;\r
+ error(h,"empty is not a valid value for final in simpletype");\r
+ goto case XmlSchemaDerivationMethod.None;\r
+ //valid cases:\r
+ case XmlSchemaDerivationMethod.All:\r
+ this.finalResolved = XmlSchemaDerivationMethod.All;\r
break;\r
case XmlSchemaDerivationMethod.List:\r
this.finalResolved = XmlSchemaDerivationMethod.List;\r
break;\r
+ case XmlSchemaDerivationMethod.Union:\r
+ this.finalResolved = XmlSchemaDerivationMethod.Union;\r
+ break;\r
case XmlSchemaDerivationMethod.Restriction:\r
this.finalResolved = XmlSchemaDerivationMethod.Restriction;\r
break;\r
- case XmlSchemaDerivationMethod.All:\r
- this.finalResolved = XmlSchemaDerivationMethod.All;\r
- break;\r
- case XmlSchemaDerivationMethod.None: // Default is empty\r
- this.finalResolved = XmlSchemaDerivationMethod.Empty;\r
- break;\r
+ // If mutliple values are specified\r
default:\r
error(h,"simpletype can't have more than one value for final");\r
+ goto case XmlSchemaDerivationMethod.None;\r
+ // use assignment from finaldefault on schema.\r
+ // The possible values of finalDefault on schema are #all | List of (extension | restriction)\r
+ // Of these, the only possible values for us are #all | restriction.\r
+ case XmlSchemaDerivationMethod.None: // b.5\r
+ if(info.finalDefault == XmlSchemaDerivationMethod.All)\r
+ finalResolved = XmlSchemaDerivationMethod.All;\r
+ else // Either Restriction or Empty\r
+ finalResolved = info.finalDefault & XmlSchemaDerivationMethod.Restriction;\r
break;\r
}\r
}\r
- if(!XmlSchemaUtil.CheckID(this.Id))\r
+\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(this.Id))\r
error(h,"id must be a valid ID");\r
\r
if(this.Content == null) //a.3,b.2\r
error(h,"Content is required in a simpletype");\r
else if(Content is XmlSchemaSimpleTypeRestriction)\r
{\r
- ((XmlSchemaSimpleTypeRestriction)Content).Compile(h,info);\r
+ errorCount += ((XmlSchemaSimpleTypeRestriction)Content).Compile(h,info);\r
}\r
else if(Content is XmlSchemaSimpleTypeList)\r
{\r
- ((XmlSchemaSimpleTypeList)Content).Compile(h,info);\r
+ errorCount += ((XmlSchemaSimpleTypeList)Content).Compile(h,info);\r
}\r
else if(Content is XmlSchemaSimpleTypeUnion)\r
{\r
- ((XmlSchemaSimpleTypeUnion)Content).Compile(h,info);\r
+ errorCount += ((XmlSchemaSimpleTypeUnion)Content).Compile(h,info);\r
}\r
- return !errorOccured;\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
{\r
- return false;\r
+ return errorCount;\r
}\r
\r
internal void error(ValidationEventHandler handle,string message)\r
{\r
- this.errorOccured = true;\r
+ this.errorCount++;\r
ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
{\r
private XmlSchemaSimpleType itemType;\r
private XmlQualifiedName itemTypeName;\r
- private bool errorOccured;\r
+ private int errorCount;\r
\r
public XmlSchemaSimpleTypeList()\r
- {}\r
+ {\r
+ this.ItemTypeName = XmlQualifiedName.Empty;\r
+ }\r
\r
[XmlElement("simpleType",Namespace="http://www.w3.org/2001/XMLSchema")]\r
public XmlSchemaSimpleType ItemType \r
set\r
{\r
itemType = value;\r
- itemTypeName = null;\r
}\r
}\r
\r
set\r
{\r
itemTypeName = value;\r
- itemType = null;\r
}\r
}\r
/// <remarks>\r
/// 2. id must be of type ID\r
/// </remarks>\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
+ errorCount = 0;\r
+\r
if(this.itemType != null && !this.ItemTypeName.IsEmpty)\r
error(h, "both itemType and simpletype can't be present");\r
if(this.itemType == null && this.ItemTypeName.IsEmpty)\r
error(h, "one of itemType or simpletype must be present");\r
if(this.itemType != null)\r
{\r
- this.itemType.islocal = true;\r
- this.itemType.Compile(h,info);\r
+ errorCount += this.itemType.Compile(h,info);\r
}\r
\r
- if(!XmlSchemaUtil.CheckID(this.Id))\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(this.Id))\r
error(h,"id must be a valid ID");\r
\r
- return !errorOccured;\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
{\r
- return false;\r
+ return errorCount;\r
}\r
\r
internal void error(ValidationEventHandler handle,string message)\r
{\r
- this.errorOccured = true;\r
+ this.errorCount++;\r
ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
private XmlSchemaSimpleType baseType;\r
private XmlQualifiedName baseTypeName;\r
private XmlSchemaObjectCollection facets;\r
- bool errorOccured;\r
+ private int errorCount;\r
\r
public XmlSchemaSimpleTypeRestriction()\r
{\r
/// 3. base must be a valid QName *NO CHECK REQUIRED*\r
/// </remarks>\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
+ errorCount = 0;\r
+\r
if(this.baseType != null && !this.BaseTypeName.IsEmpty)\r
error(h, "both base and simpletype can't be set");\r
if(this.baseType == null && this.BaseTypeName.IsEmpty)\r
error(h, "one of basetype or simpletype must be present");\r
if(this.baseType != null)\r
{\r
- this.baseType.islocal = true;\r
- this.baseType.Compile(h,info);\r
+ errorCount += this.baseType.Compile(h,info);\r
}\r
\r
- if(!XmlSchemaUtil.CheckID(this.Id))\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(this.Id))\r
error(h,"id must be a valid ID");\r
\r
- return !errorOccured;\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
{\r
- return false;\r
+ return errorCount;\r
}\r
\r
internal void error(ValidationEventHandler handle,string message)\r
{\r
- this.errorOccured = true;\r
+ this.errorCount++;\r
ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
}\r
{\r
private XmlSchemaObjectCollection baseTypes;\r
private XmlQualifiedName[] memberTypes;\r
- private bool errorOccured;\r
+ private int errorCount;\r
\r
public XmlSchemaSimpleTypeUnion()\r
{\r
/// 2. id must be a valid ID\r
/// </remarks>\r
[MonoTODO]\r
- internal bool Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
{\r
- if(BaseTypes.Count + MemberTypes.Length == 0)\r
+ errorCount = 0;\r
+\r
+ int count = BaseTypes.Count;\r
+ if(MemberTypes != null)\r
+ count += MemberTypes.Length;\r
+\r
+ if(count == 0)\r
error(h, "Atleast one simpletype or membertype must be present");\r
\r
foreach(XmlSchemaObject obj in baseTypes)\r
if(obj != null && obj is XmlSchemaSimpleType)\r
{\r
XmlSchemaSimpleType stype = (XmlSchemaSimpleType) obj;\r
- stype.Compile(h,info);\r
+ errorCount += stype.Compile(h,info);\r
}\r
else\r
{\r
error(h, "baseTypes can't have objects other than a simpletype");\r
}\r
}\r
- for(int i=0; i< memberTypes.Length; i++)\r
+ \r
+ if(memberTypes!=null)\r
{\r
- if(memberTypes[i] == null)\r
+ for(int i=0; i< memberTypes.Length; i++)\r
{\r
- warn(h,"memberTypes should not have a null value");\r
- memberTypes[i] = XmlQualifiedName.Empty;\r
+ if(memberTypes[i] == null)\r
+ {\r
+ warn(h,"memberTypes should not have a null value");\r
+ memberTypes[i] = XmlQualifiedName.Empty;\r
+ }\r
}\r
}\r
- if(!XmlSchemaUtil.CheckID(this.Id))\r
+\r
+ if(this.Id != null && !XmlSchemaUtil.CheckID(this.Id))\r
error(h,"id must be a valid ID");\r
\r
- return !errorOccured;\r
+ return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal bool Validate(ValidationEventHandler h)\r
+ internal int Validate(ValidationEventHandler h)\r
{\r
- return false;\r
+ return errorCount;\r
}\r
\r
internal void error(ValidationEventHandler handle,string message)\r
{\r
- this.errorOccured = true;\r
+ this.errorCount++;\r
ValidationHandler.RaiseValidationError(handle,this,message);\r
}\r
\r
internal void warn(ValidationEventHandler handle,string message)\r
{\r
- this.errorOccured = true;\r
+ this.errorCount++;\r
ValidationHandler.RaiseValidationWarning(handle,this,message);\r
}\r
}\r
public XmlSchemaType()\r
{\r
final = XmlSchemaDerivationMethod.None;\r
+ qName = XmlQualifiedName.Empty;\r
}\r
\r
#region Attributes\r
// Author: Dwivedi, Ajay kumar\r
// Adwiv@Yahoo.com\r
using System;\r
+using System.Xml;\r
\r
namespace System.Xml.Schema\r
{\r
/// </summary>\r
public class XmlSchemaUnique : XmlSchemaIdentityConstraint\r
{\r
+ private int errorCount;\r
+\r
public XmlSchemaUnique()\r
{\r
}\r
+ /// <remarks>\r
+ /// 1. name must be present\r
+ /// 2. selector and field must be present\r
+ /// </remarks>\r
+ [MonoTODO]\r
+ internal new int Compile(ValidationEventHandler h, XmlSchemaInfo info)\r
+ {\r
+ return base.Compile(h,info);\r
+ }\r
+ \r
+ [MonoTODO]\r
+ internal int Validate(ValidationEventHandler h)\r
+ {\r
+ return errorCount;\r
+ }\r
+\r
+ internal new void error(ValidationEventHandler handle, string message)\r
+ {\r
+ errorCount++;\r
+ ValidationHandler.RaiseValidationError(handle, this, message);\r
+ }\r
}\r
}\r
using System;\r
+using System.Xml;\r
\r
namespace System.Xml.Schema\r
{\r
public static bool CheckID(string id)\r
{\r
//check if the string conforms to http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/datatypes.html#ID\r
+ // 1. ID must be a NCName\r
+ // 2. ID must be unique in the schema\r
+ if(!CheckNCName(id)) \r
+ return false;\r
+ //If !unique\r
+\r
return true;\r
}\r
[MonoTODO]\r
public static bool CheckNCName(string name)\r
{\r
//check if the string conforms to http://www.w3.org/TR/2001/REC-xmlschema-2-20010502/datatypes.html#NCName\r
- return true;\r
+ try\r
+ {\r
+ XmlConvert.VerifyNCName(name);\r
+ return true;\r
+ }\r
+ catch(Exception ex)\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+ public static string[] SplitList(string ns)\r
+ {\r
+ return ns.Split(new char[]{' '});\r
+ }\r
+\r
+ // To Be Removed\r
+ public static XmlQualifiedName GetRandomQName()\r
+ {\r
+ return new XmlQualifiedName(new Random().Next(int.MaxValue).ToString());\r
}\r
}\r
}\r