private XmlSchemaSimpleType baseType;\r
private XmlQualifiedName baseTypeName;\r
private XmlSchemaObjectCollection facets;\r
- private int errorCount=0;\r
+ private static string xmlname = "restriction";\r
\r
public XmlSchemaSimpleContentRestriction()\r
{\r
set{ baseTypeName = value; }\r
}\r
\r
- [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]\r
- public XmlSchemaAnyAttribute AnyAttribute \r
- {\r
- get{ return any; }\r
- set{ any = value; }\r
- }\r
-\r
- [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- public XmlSchemaObjectCollection Attributes \r
- {\r
- get{ return attributes; }\r
- }\r
-\r
- [XmlElement("simpleType",Namespace="http://www.w3.org/2001/XMLSchema")]\r
+ [XmlElement("simpleType",Namespace=XmlSchema.Namespace)]\r
public XmlSchemaSimpleType BaseType \r
{ \r
get{ return baseType; } \r
set{ baseType = value; } \r
}\r
\r
- \r
- [XmlElement("minExclusive",typeof(XmlSchemaMinExclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("minInclusive",typeof(XmlSchemaMinInclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")] \r
- [XmlElement("maxExclusive",typeof(XmlSchemaMaxExclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("maxInclusive",typeof(XmlSchemaMaxInclusiveFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("totalDigits",typeof(XmlSchemaTotalDigitsFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("fractionDigits",typeof(XmlSchemaFractionDigitsFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("length",typeof(XmlSchemaLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("minLength",typeof(XmlSchemaMinLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("maxLength",typeof(XmlSchemaMaxLengthFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("enumeration",typeof(XmlSchemaEnumerationFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("whiteSpace",typeof(XmlSchemaWhiteSpaceFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
- [XmlElement("pattern",typeof(XmlSchemaPatternFacet),Namespace="http://www.w3.org/2001/XMLSchema")]\r
+ [XmlElement("minExclusive",typeof(XmlSchemaMinExclusiveFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("minInclusive",typeof(XmlSchemaMinInclusiveFacet),Namespace=XmlSchema.Namespace)] \r
+ [XmlElement("maxExclusive",typeof(XmlSchemaMaxExclusiveFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("maxInclusive",typeof(XmlSchemaMaxInclusiveFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("totalDigits",typeof(XmlSchemaTotalDigitsFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("fractionDigits",typeof(XmlSchemaFractionDigitsFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("length",typeof(XmlSchemaLengthFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("minLength",typeof(XmlSchemaMinLengthFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("maxLength",typeof(XmlSchemaMaxLengthFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("enumeration",typeof(XmlSchemaEnumerationFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("whiteSpace",typeof(XmlSchemaWhiteSpaceFacet),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("pattern",typeof(XmlSchemaPatternFacet),Namespace=XmlSchema.Namespace)]\r
public XmlSchemaObjectCollection Facets \r
{ \r
get{ return facets; } \r
}\r
+\r
+ [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace=XmlSchema.Namespace)]\r
+ [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace=XmlSchema.Namespace)]\r
+ public XmlSchemaObjectCollection Attributes \r
+ {\r
+ get{ return attributes; }\r
+ }\r
+\r
+ [XmlElement("anyAttribute",Namespace=XmlSchema.Namespace)]\r
+ public XmlSchemaAnyAttribute AnyAttribute \r
+ {\r
+ get{ return any; }\r
+ set{ any = value; }\r
+ }\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
+ 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
+ return 0;\r
+\r
+ if (this.isRedefinedComponent) {\r
+ if (Annotation != null)\r
+ Annotation.isRedefinedComponent = true;\r
+ if (AnyAttribute != null)\r
+ AnyAttribute.isRedefinedComponent = true;\r
+ foreach (XmlSchemaObject obj in Attributes)\r
+ obj.isRedefinedComponent = true;\r
+ }\r
+\r
if(BaseTypeName == null || BaseTypeName.IsEmpty)\r
{\r
- error(h, "base must be present and a QName");\r
+ error(h, "base must be present, as a QName");\r
}\r
+ else if(!XmlSchemaUtil.CheckQName(BaseTypeName))\r
+ error(h,"BaseTypeName must be a QName");\r
\r
if(BaseType != null)\r
{\r
- errorCount += BaseType.Compile(h,info);\r
+ errorCount += BaseType.Compile(h,schema);\r
}\r
\r
if(this.AnyAttribute != null)\r
{\r
- errorCount += AnyAttribute.Compile(h,info);\r
+ errorCount += AnyAttribute.Compile(h,schema);\r
}\r
\r
foreach(XmlSchemaObject obj in Attributes)\r
if(obj is XmlSchemaAttribute)\r
{\r
XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;\r
- errorCount += attr.Compile(h,info);\r
+ errorCount += attr.Compile(h,schema);\r
}\r
else if(obj is XmlSchemaAttributeGroupRef)\r
{\r
XmlSchemaAttributeGroupRef atgrp = (XmlSchemaAttributeGroupRef) obj;\r
- errorCount += atgrp.Compile(h,info);\r
+ errorCount += atgrp.Compile(h,schema);\r
}\r
else\r
- error(h,"object is not valid in this place");\r
+ error(h,obj.GetType() +" is not valid in this place::SimpleContentRestriction");\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
+ \r
+ XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);\r
+ this.CompilationId = schema.CompilationId;\r
return errorCount;\r
}\r
\r
[MonoTODO]\r
- internal int Validate(ValidationEventHandler h)\r
+ internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
{\r
+ if (IsValidated (schema.ValidationId))\r
+ return errorCount;\r
+\r
+ if (baseType != null) {\r
+ baseType.Validate (h, schema);\r
+ actualBaseSchemaType = baseType;\r
+ }\r
+ else if (baseTypeName != XmlQualifiedName.Empty) {\r
+ XmlSchemaType st = schema.SchemaTypes [baseTypeName] as XmlSchemaType;\r
+ if (st != null) {\r
+ st.Validate (h, schema);\r
+ actualBaseSchemaType = st;\r
+ } else if (baseTypeName == XmlSchemaComplexType.AnyTypeName) {\r
+ actualBaseSchemaType = XmlSchemaComplexType.AnyType;
+ } else if (baseTypeName.Namespace == XmlSchema.Namespace) {\r
+ actualBaseSchemaType = XmlSchemaDatatype.FromName (baseTypeName);\r
+ if (actualBaseSchemaType == null)\r
+ error (h, "Invalid schema datatype name is specified.");\r
+ }\r
+ // otherwise, it might be missing sub components.\r
+ else if (!schema.IsNamespaceAbsent (baseTypeName.Namespace))\r
+ error (h, "Referenced base schema type " + baseTypeName + " was not found in the corresponding schema.");\r
+ }\r
+\r
+ ValidationId = schema.ValidationId;\r
return errorCount;\r
}\r
\r
- internal void error(ValidationEventHandler handle,string message)\r
+ //<restriction \r
+ //base = QName \r
+ //id = ID \r
+ //{any attributes with non-schema namespace . . .}>\r
+ //Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))\r
+ //</restriction>\r
+ internal static XmlSchemaSimpleContentRestriction Read(XmlSchemaReader reader, ValidationEventHandler h)\r
{\r
- errorCount++;\r
- ValidationHandler.RaiseValidationError(handle,this,message);\r
+ XmlSchemaSimpleContentRestriction restriction = new XmlSchemaSimpleContentRestriction();\r
+ reader.MoveToElement();\r
+\r
+ if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)\r
+ {\r
+ error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);\r
+ reader.SkipToEnd();\r
+ return null;\r
+ }\r
+\r
+ restriction.LineNumber = reader.LineNumber;\r
+ restriction.LinePosition = reader.LinePosition;\r
+ restriction.SourceUri = reader.BaseURI;\r
+\r
+ while(reader.MoveToNextAttribute())\r
+ {\r
+ if(reader.Name == "base")\r
+ {\r
+ Exception innerex;\r
+ restriction.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);\r
+ if(innerex != null)\r
+ error(h, reader.Value + " is not a valid value for base attribute",innerex);\r
+ }\r
+ else if(reader.Name == "id")\r
+ {\r
+ restriction.Id = reader.Value;\r
+ }\r
+ else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)\r
+ {\r
+ error(h,reader.Name + " is not a valid attribute for restriction",null);\r
+ }\r
+ else\r
+ {\r
+ XmlSchemaUtil.ReadUnhandledAttribute(reader,restriction);\r
+ }\r
+ }\r
+ \r
+ reader.MoveToElement();\r
+ if(reader.IsEmptyElement)\r
+ return restriction;\r
+ \r
+ //Content: 1.annotation?, \r
+ // 2.simpleType?, \r
+ // 3.(minExclusive |...| enumeration | whiteSpace | pattern)*, \r
+ // 4.(attribute | attributeGroup)*, \r
+ // 5.anyAttribute?\r
+ int level = 1;\r
+ while(reader.ReadNextElement())\r
+ {\r
+ if(reader.NodeType == XmlNodeType.EndElement)\r
+ {\r
+ if(reader.LocalName != xmlname)\r
+ error(h,"Should not happen :2: XmlSchemaSimpleContentRestriction.Read, name="+reader.Name,null);\r
+ break;\r
+ }\r
+ if(level <= 1 && reader.LocalName == "annotation")\r
+ {\r
+ level = 2; //Only one annotation\r
+ XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);\r
+ if(annotation != null)\r
+ restriction.Annotation = annotation;\r
+ continue;\r
+ }\r
+ if(level <=2 && reader.LocalName == "simpleType")\r
+ {\r
+ level = 3;\r
+ XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader,h);\r
+ if(stype != null)\r
+ restriction.baseType = stype;\r
+ continue;\r
+ }\r
+ if(level <= 3)\r
+ {\r
+ if(reader.LocalName == "minExclusive")\r
+ {\r
+ level = 3;\r
+ XmlSchemaMinExclusiveFacet minex = XmlSchemaMinExclusiveFacet.Read(reader,h);\r
+ if(minex != null)\r
+ restriction.facets.Add(minex);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "minInclusive")\r
+ {\r
+ level = 3;\r
+ XmlSchemaMinInclusiveFacet mini = XmlSchemaMinInclusiveFacet.Read(reader,h);\r
+ if(mini != null)\r
+ restriction.facets.Add(mini);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "maxExclusive")\r
+ {\r
+ level = 3;\r
+ XmlSchemaMaxExclusiveFacet maxex = XmlSchemaMaxExclusiveFacet.Read(reader,h);\r
+ if(maxex != null)\r
+ restriction.facets.Add(maxex);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "maxInclusive")\r
+ {\r
+ level = 3;\r
+ XmlSchemaMaxInclusiveFacet maxi = XmlSchemaMaxInclusiveFacet.Read(reader,h);\r
+ if(maxi != null)\r
+ restriction.facets.Add(maxi);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "totalDigits")\r
+ {\r
+ level = 3;\r
+ XmlSchemaTotalDigitsFacet total = XmlSchemaTotalDigitsFacet.Read(reader,h);\r
+ if(total != null)\r
+ restriction.facets.Add(total);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "fractionDigits")\r
+ {\r
+ level = 3;\r
+ XmlSchemaFractionDigitsFacet fraction = XmlSchemaFractionDigitsFacet.Read(reader,h);\r
+ if(fraction != null)\r
+ restriction.facets.Add(fraction);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "length")\r
+ {\r
+ level = 3;\r
+ XmlSchemaLengthFacet length = XmlSchemaLengthFacet.Read(reader,h);\r
+ if(length != null)\r
+ restriction.facets.Add(length);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "minLength")\r
+ {\r
+ level = 3;\r
+ XmlSchemaMinLengthFacet minlen = XmlSchemaMinLengthFacet.Read(reader,h);\r
+ if(minlen != null)\r
+ restriction.facets.Add(minlen);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "maxLength")\r
+ {\r
+ level = 3;\r
+ XmlSchemaMaxLengthFacet maxlen = XmlSchemaMaxLengthFacet.Read(reader,h);\r
+ if(maxlen != null)\r
+ restriction.facets.Add(maxlen);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "enumeration")\r
+ {\r
+ level = 3;\r
+ XmlSchemaEnumerationFacet enumeration = XmlSchemaEnumerationFacet.Read(reader,h);\r
+ if(enumeration != null)\r
+ restriction.facets.Add(enumeration);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "whiteSpace")\r
+ {\r
+ level = 3;\r
+ XmlSchemaWhiteSpaceFacet ws = XmlSchemaWhiteSpaceFacet.Read(reader,h);\r
+ if(ws != null)\r
+ restriction.facets.Add(ws);\r
+ continue;\r
+ }\r
+ else if(reader.LocalName == "pattern")\r
+ {\r
+ level = 3;\r
+ XmlSchemaPatternFacet pattern = XmlSchemaPatternFacet.Read(reader,h);\r
+ if(pattern != null)\r
+ restriction.facets.Add(pattern);\r
+ continue;\r
+ }\r
+ }\r
+ if(level <= 4)\r
+ {\r
+ if(reader.LocalName == "attribute")\r
+ {\r
+ level = 4;\r
+ XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);\r
+ if(attr != null)\r
+ restriction.Attributes.Add(attr);\r
+ continue;\r
+ }\r
+ if(reader.LocalName == "attributeGroup")\r
+ {\r
+ level = 4;\r
+ XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);\r
+ if(attr != null)\r
+ restriction.attributes.Add(attr);\r
+ continue;\r
+ }\r
+ }\r
+ if(level <= 5 && reader.LocalName == "anyAttribute")\r
+ {\r
+ level = 6;\r
+ XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);\r
+ if(anyattr != null)\r
+ restriction.AnyAttribute = anyattr;\r
+ continue;\r
+ }\r
+ reader.RaiseInvalidElementError();\r
+ }\r
+ return restriction;\r
}\r
+\r
}\r
}\r