switch (typeName) {
case "XmlSchemaElement":
return AddElement ((XmlSchemaElement) xsobj);
- case "XmlSchemaGroupRef":
- return AddGroup ((XmlSchemaGroupRef) xsobj);
case "XmlSchemaSequence":
return AddSequence ((XmlSchemaSequence) xsobj);
case "XmlSchemaChoice":
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.");
}
}
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;
}
}
}
- 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;
return XsdValidationState.Invalid;
OccuredInternal++;
- Manager.SetProcessContents (any.ProcessContents);
+ Manager.SetProcessContents (any.ResolvedProcessContents);
if (Occured > any.ValidatedMaxOccurs)
return XsdValidationState.Invalid;
else if (Occured == any.ValidatedMaxOccurs)
XmlReader reader;
XmlValidatingReader xvReader;
+ XmlResolver resolver;
IHasXmlSchemaInfo sourceReaderSchemaInfo;
IXmlLineInfo readerLineInfo;
bool laxElementValidation = true;
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; }
}
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);
{
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;
}
// If validation state exists, then first assess particle validity.
+ context.SchemaType = null;
if (context.ParticleState != null) {
ValidateStartElementParticle ();
}
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) {
return attr;
}
}
- if (cType.AttributeWildcard.ProcessContents == XmlSchemaContentProcessing.Lax)
+ if (cType.AttributeWildcard.ResolvedProcessContents == XmlSchemaContentProcessing.Lax)
return cType.AttributeWildcard;
else
return null;
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().
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--;
}
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)
}
if (schema != null) {
try {
- schemas.Add (schema);
+ schemas.Add (schema, resolver);
} catch (XmlSchemaException ex) {
HandleError (ex);
}
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);