2004-01-26 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 26 Jan 2004 18:24:55 +0000 (18:24 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 26 Jan 2004 18:24:55 +0000 (18:24 -0000)
* XsdParticleValidationState.cs :
  - Now it uses ContentTypeParticle as inputs, so no GroupRef
    should occur anymore.
  - xs:any should use ResolvedProcessContents. It fixes some errors.
* XsdValidatingReader.cs :
  - Attribute wildcard validation should use ResolvedProcessContents.
  - Use newly added XmlResolver field to resolve external schemas
    specified by xsi:schemaLocation attributes.
  - Added warning handler and raise warning events when instance-
    specified schemas could not be resolved.
  - xs:anyType should not be treated as a primitive datatype at
    xsi:type resolution.
  - Schema type was incorrectly remained when the element is laxly
    validated.

svn path=/trunk/mcs/; revision=22508

mcs/class/System.XML/Mono.Xml.Schema/ChangeLog
mcs/class/System.XML/Mono.Xml.Schema/XsdParticleValidationState.cs
mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs

index a0c8b8d11a00c13eba4c1e87d88adbd7d20a3683..ab8099a6701796aed8caf15f301e1ed5a825ff69 100644 (file)
@@ -1,3 +1,20 @@
+2004-01-26  Atsushi Enomoto <atsushi@ximian.com>
+
+       * XsdParticleValidationState.cs :
+         - Now it uses ContentTypeParticle as inputs, so no GroupRef 
+           should occur anymore.
+         - xs:any should use ResolvedProcessContents. It fixes some errors.
+       * XsdValidatingReader.cs :
+         - Attribute wildcard validation should use ResolvedProcessContents.
+         - Use newly added XmlResolver field to resolve external schemas
+           specified by xsi:schemaLocation attributes.
+         - Added warning handler and raise warning events when instance-
+           specified schemas could not be resolved.
+         - xs:anyType should not be treated as a primitive datatype at
+           xsi:type resolution.
+         - Schema type was incorrectly remained when the element is laxly
+           validated.
+
 2004-01-21  Atsushi Enomoto <atsushi@ximian.com>
 
        * XsdKeyTable.cs : Matching evaluation is incorrect when path is more
index 48ca49f5263d4b1cc65b3bc17862d4654ecb3dd1..94ab3ea2df34df62d3467adc3c4ed5e1bcda95b7 100644 (file)
@@ -67,8 +67,6 @@ namespace Mono.Xml.Schema
                        switch (typeName) {
                        case "XmlSchemaElement":
                                return AddElement ((XmlSchemaElement) xsobj);
-                       case "XmlSchemaGroupRef":
-                               return AddGroup ((XmlSchemaGroupRef) xsobj);
                        case "XmlSchemaSequence":
                                return AddSequence ((XmlSchemaSequence) xsobj);
                        case "XmlSchemaChoice":
@@ -77,11 +75,11 @@ namespace Mono.Xml.Schema
                                return AddAll ((XmlSchemaAll) xsobj);
                        case "XmlSchemaAny":
                                return AddAny ((XmlSchemaAny) xsobj);
-                       case "EmptyParticle":   // Microsoft.NET
-                       case "XmlSchemaParticleEmpty":  // Mono
+                       case "EmptyParticle":
                                return AddEmpty ();
                        default:
-                               throw new InvalidOperationException (); // Should not occur.
+                               // GroupRef should not appear
+                               throw new InvalidOperationException ("Should not occur.");
                        }
                }
 
@@ -96,42 +94,30 @@ namespace Mono.Xml.Schema
                private XsdElementValidationState AddElement (XmlSchemaElement element)
                {
                        XsdElementValidationState got = new XsdElementValidationState (element, this);
-//                     table [element] = got;
-                       return got;
-               }
-
-               private XsdGroupValidationState AddGroup (XmlSchemaGroupRef groupRef)
-               {
-                       XsdGroupValidationState got = new XsdGroupValidationState (groupRef, this);
-//                     table [groupRef] = got;
                        return got;
                }
 
                private XsdSequenceValidationState AddSequence (XmlSchemaSequence sequence)
                {
                        XsdSequenceValidationState got = new XsdSequenceValidationState (sequence, this);
-//                     table [sequence] = got;
                        return got;
                }
 
                private XsdChoiceValidationState AddChoice (XmlSchemaChoice choice)
                {
                        XsdChoiceValidationState got = new XsdChoiceValidationState (choice, this);
-//                     table [choice] = got;
                        return got;
                }
 
                private XsdAllValidationState AddAll (XmlSchemaAll all)
                {
                        XsdAllValidationState got = new XsdAllValidationState (all, this);
-//                     table [all] = got;
                        return got;
                }
 
                private XsdAnyValidationState AddAny (XmlSchemaAny any)
                {
                        XsdAnyValidationState got = new XsdAnyValidationState (any, this);
-//                     table [any] = got;
                        return got;
                }
 
@@ -256,46 +242,6 @@ namespace Mono.Xml.Schema
                }
        }
 
-       public class XsdGroupValidationState : XsdValidationState
-       {
-               public XsdGroupValidationState (XmlSchemaGroupRef groupRef, XsdValidationStateManager manager)
-                       : base (manager)
-               {
-                       this.groupRef = groupRef;
-               }
-
-               XmlSchemaGroupRef groupRef;
-
-               // Methods
-
-               public override XsdValidationState EvaluateStartElement (string name, string ns)
-               {
-                       XsdValidationState xa = Manager.Create (groupRef.Particle);
-                       XsdValidationState result = xa.EvaluateStartElement (name, ns);
-                       if (result == XsdValidationState.Invalid)
-                               return result;
-
-                       OccuredInternal++;
-                       if (OccuredInternal > groupRef.ValidatedMaxOccurs)
-                               return XsdValidationState.Invalid;
-                       return Manager.MakeSequence (result, this);
-               }
-
-               public override bool EvaluateEndElement ()
-               {
-                       if (groupRef.ValidatedMinOccurs > Occured + 1)
-                               return false;
-                       else if (groupRef.ValidatedMinOccurs <= Occured)
-                               return true;
-                       return Manager.Create (groupRef.Particle).EvaluateIsEmptiable ();
-               }
-
-               internal override bool EvaluateIsEmptiable ()\r
-               {\r
-                       return (groupRef.ValidatedMinOccurs <= Occured);\r
-               }\r
-       }
-
        public class XsdSequenceValidationState : XsdValidationState
        {
                XmlSchemaSequence seq;
@@ -591,7 +537,7 @@ namespace Mono.Xml.Schema
                                return XsdValidationState.Invalid;
 
                        OccuredInternal++;
-                       Manager.SetProcessContents (any.ProcessContents);
+                       Manager.SetProcessContents (any.ResolvedProcessContents);
                        if (Occured > any.ValidatedMaxOccurs)
                                return XsdValidationState.Invalid;
                        else if (Occured == any.ValidatedMaxOccurs)
index 3b64a59f084b99dc44295aae077402af61c4a842..e0227bc373371228f5678d40bfb39ecef32b70eb 100644 (file)
@@ -27,6 +27,7 @@ namespace Mono.Xml.Schema
 
                XmlReader reader;
                XmlValidatingReader xvReader;
+               XmlResolver resolver;
                IHasXmlSchemaInfo sourceReaderSchemaInfo;
                IXmlLineInfo readerLineInfo;
                bool laxElementValidation = true;
@@ -111,6 +112,13 @@ namespace Mono.Xml.Schema
                        get { return reader; }
                }
 
+               // This is required to resolve xsi:schemaLocation
+               public XmlResolver XmlResolver {
+                       set {
+                               resolver = value;
+                       }
+               }
+
                // This should be changed before the first Read() call.
                public XmlSchemaCollection Schemas {
                        get { return schemas; }
@@ -461,22 +469,32 @@ namespace Mono.Xml.Schema
                }
 
                private void HandleError (string error, Exception innerException)
+               {
+                       HandleError (error, innerException, false);
+               }
+
+               private void HandleError (string error, Exception innerException, bool isWarning)
                {
                        if (reportNoValidationError)    // extra quick check
                                return;
 
                        XmlSchemaException schemaException = new XmlSchemaException (error, 
                                        this, this.BaseURI, null, innerException);
-                       HandleError (schemaException);
+                       HandleError (schemaException, isWarning);
                }
 
                private void HandleError (XmlSchemaException schemaException)
+               {
+                       HandleError (schemaException, false);
+               }
+
+               private void HandleError (XmlSchemaException schemaException, bool isWarning)
                {
                        if (reportNoValidationError)
                                return;
 
                        ValidationEventArgs e = new ValidationEventArgs (schemaException,
-                               schemaException.Message, XmlSeverityType.Error);
+                               schemaException.Message, isWarning ? XmlSeverityType.Warning : XmlSeverityType.Error);
 
                        if (this.ValidationEventHandler != null)
                                this.ValidationEventHandler (this, e);
@@ -710,12 +728,10 @@ namespace Mono.Xml.Schema
                {
                        object xsiType = null;
                        XmlQualifiedName typeQName = QualifyName (name);
-                       if (typeQName.Namespace == XmlSchema.Namespace) {
-                               if (typeQName.Name == "anyType")
-                                       xsiType = XmlSchemaComplexType.AnyType;
-                               else
-                                       xsiType = XmlSchemaDatatype.FromName (typeQName);
-                       }
+                       if (typeQName == XmlSchemaComplexType.AnyTypeName)
+                               xsiType = XmlSchemaComplexType.AnyType;
+                       else if (XmlSchemaUtil.IsBuiltInDatatypeName (typeQName))
+                               xsiType = XmlSchemaDatatype.FromName (typeQName);
                        else
                                xsiType = FindType (typeQName);
                        return xsiType;
@@ -780,6 +796,7 @@ namespace Mono.Xml.Schema
                        }
 
                        // If validation state exists, then first assess particle validity.
+                       context.SchemaType = null;
                        if (context.ParticleState != null) {
                                ValidateStartElementParticle ();
                        }
@@ -1042,7 +1059,7 @@ namespace Mono.Xml.Schema
                        if (!AttributeWildcardItemValid (cType.AttributeWildcard, qname))
                                return null;
 
-                       if (cType.AttributeWildcard.ProcessContents == XmlSchemaContentProcessing.Skip)
+                       if (cType.AttributeWildcard.ResolvedProcessContents == XmlSchemaContentProcessing.Skip)
                                return cType.AttributeWildcard;
                        foreach (XmlSchema schema in schemas) {
                                foreach (DictionaryEntry entry in schema.Attributes) {
@@ -1051,7 +1068,7 @@ namespace Mono.Xml.Schema
                                                return attr;
                                }
                        }
-                       if (cType.AttributeWildcard.ProcessContents == XmlSchemaContentProcessing.Lax)
+                       if (cType.AttributeWildcard.ResolvedProcessContents == XmlSchemaContentProcessing.Lax)
                                return cType.AttributeWildcard;
                        else
                                return null;
@@ -1157,8 +1174,6 @@ namespace Mono.Xml.Schema
                                shouldValidateCharacters = false;
                        }
 
-                       context.Load (reader.Depth);
-
                        // 3.3.4 Assess ElementLocallyValidElement 5: value constraints.
                        // 3.3.4 Assess ElementLocallyValidType 3.1.3. = StringValid(3.14.4)
                        // => ValidateEndCharacters().
@@ -1195,7 +1210,6 @@ namespace Mono.Xml.Schema
                        for (int i = 0; i < keyTables.Count; i++) {
                                XsdKeyTable keyseq = this.keyTables [i] as XsdKeyTable;
                                if (keyseq.StartDepth == reader.Depth) {
-//Console.WriteLine ("Finishing table.");
                                        keyTables.RemoveAt (i);
                                        i--;
                                }
@@ -1547,11 +1561,13 @@ namespace Mono.Xml.Schema
                                if (tmp.Length % 2 != 0)
                                        HandleError ("Invalid schemaLocation attribute format.");
                                for (int i = 0; i < tmp.Length; i += 2) {
+                                       Uri absUri = null;
                                        try {
-                                               Uri absUri = new Uri ((this.BaseURI != "" ? new Uri (BaseURI) : null), tmp [i + 1]);
+                                               absUri = new Uri ((this.BaseURI != "" ? new Uri (BaseURI) : null), tmp [i + 1]);
                                                XmlTextReader xtr = new XmlTextReader (absUri.ToString ());
                                                schema = XmlSchema.Read (xtr, null);
                                        } catch (Exception) { // FIXME: (wishlist) It is bad manner ;-(
+                                               HandleError ("Could not resolve schema location URI: " + absUri, null, true);\r
                                                continue;
                                        }
                                        if (schema.TargetNamespace == null)
@@ -1562,7 +1578,7 @@ namespace Mono.Xml.Schema
                        }
                        if (schema != null) {
                                try {
-                                       schemas.Add (schema);
+                                       schemas.Add (schema, resolver);
                                } catch (XmlSchemaException ex) {
                                        HandleError (ex);
                                }
@@ -1570,17 +1586,20 @@ namespace Mono.Xml.Schema
                        schema = null;
                        string noNsSchemaLocation = reader.GetAttribute ("noNamespaceSchemaLocation", XmlSchema.InstanceNamespace);
                        if (noNsSchemaLocation != null) {
+                               Uri absUri = null;
                                try {
-                                       Uri absUri = new Uri ((this.BaseURI != "" ? new Uri (BaseURI) : null), noNsSchemaLocation);
+                                       absUri = new Uri ((this.BaseURI != "" ? new Uri (BaseURI) : null), noNsSchemaLocation);
                                        XmlTextReader xtr = new XmlTextReader (absUri.ToString ());
                                        schema = XmlSchema.Read (xtr, null);
                                } catch (Exception) { // FIXME: (wishlist) It is bad manner ;-(
+                                       HandleError ("Could not resolve schema location URI: " + absUri, null, true);\r
                                }
                                if (schema != null && schema.TargetNamespace != null)
                                        HandleError ("Specified schema has different target namespace.");
                        }
                        if (schema != null) {
                                try {
+                                       schema.Compile (ValidationEventHandler, resolver);
                                        schemas.Add (schema);
                                } catch (XmlSchemaException ex) {
                                        HandleError (ex);