private void LoadSchemaFromLocation(string uri) { // is x-schema if (!XdrBuilder.IsXdrSchema(uri)) { return; } string url = uri.Substring(x_schema.Length); XmlReader reader = null; SchemaInfo xdrSchema = null; try { Uri ruri = this.XmlResolver.ResolveUri(BaseUri, url); Stream stm = (Stream)this.XmlResolver.GetEntity(ruri, null, null); reader = new XmlTextReader(ruri.ToString(), stm, NameTable); ((XmlTextReader)reader).XmlResolver = this.XmlResolver; Parser parser = new Parser(SchemaType.XDR, NameTable, SchemaNames, EventHandler); parser.XmlResolver = this.XmlResolver; parser.Parse(reader, uri); while (reader.Read()) { ; // wellformness check } xdrSchema = parser.XdrSchema; } catch (XmlSchemaException e) { SendValidationEvent(SR.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Error); } catch (Exception e) { SendValidationEvent(SR.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Warning); } finally { if (reader != null) { reader.Close(); } } if (xdrSchema != null && xdrSchema.ErrorCount == 0) { schemaInfo.Add(xdrSchema, EventHandler); SchemaCollection.Add(uri, xdrSchema, null, false); } }
private void LoadSchemaFromLocation(string uri) { if (XdrBuilder.IsXdrSchema(uri)) { string relativeUri = uri.Substring("x-schema:".Length); XmlReader reader = null; SchemaInfo sinfo = null; try { Uri absoluteUri = base.XmlResolver.ResolveUri(base.BaseUri, relativeUri); Stream input = (Stream)base.XmlResolver.GetEntity(absoluteUri, null, null); reader = new XmlTextReader(absoluteUri.ToString(), input, base.NameTable); ((XmlTextReader)reader).XmlResolver = base.XmlResolver; System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XDR, base.NameTable, base.SchemaNames, base.EventHandler) { XmlResolver = base.XmlResolver }; parser.Parse(reader, uri); while (reader.Read()) { } sinfo = parser.XdrSchema; } catch (XmlSchemaException exception) { base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception.Message }, XmlSeverityType.Error); } catch (Exception exception2) { base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception2.Message }, XmlSeverityType.Warning); } finally { if (reader != null) { reader.Close(); } } if ((sinfo != null) && (sinfo.ErrorCount == 0)) { base.schemaInfo.Add(sinfo, base.EventHandler); base.SchemaCollection.Add(uri, sinfo, null, false); } } }
private ValidationType DetectValidationType() { //Type not yet detected : Check in Schema Collection if (reader.Schemas != null && reader.Schemas.Count > 0) { XmlSchemaCollectionEnumerator enumerator = reader.Schemas.GetEnumerator(); while (enumerator.MoveNext()) { XmlSchemaCollectionNode node = enumerator.CurrentNode !; SchemaInfo schemaInfo = node.SchemaInfo !; if (schemaInfo.SchemaType == SchemaType.XSD) { return(ValidationType.Schema); } else if (schemaInfo.SchemaType == SchemaType.XDR) { return(ValidationType.XDR); } } } if (reader.NodeType == XmlNodeType.Element) { SchemaType schemaType = SchemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI); if (schemaType == SchemaType.XSD) { return(ValidationType.Schema); } else if (schemaType == SchemaType.XDR) { return(ValidationType.XDR); } else { int count = reader.AttributeCount; for (int i = 0; i < count; i++) { reader.MoveToAttribute(i); string objectNs = reader.NamespaceURI; string objectName = reader.LocalName; if (Ref.Equal(objectNs, SchemaNames.NsXmlNs)) { if (XdrBuilder.IsXdrSchema(reader.Value)) { reader.MoveToElement(); return(ValidationType.XDR); } } else if (Ref.Equal(objectNs, SchemaNames.NsXsi)) { reader.MoveToElement(); return(ValidationType.Schema); } else if (Ref.Equal(objectNs, SchemaNames.QnDtDt.Namespace) && Ref.Equal(objectName, SchemaNames.QnDtDt.Name)) { reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value); reader.MoveToElement(); return(ValidationType.XDR); } } //end of for if (count > 0) { reader.MoveToElement(); } } } return(ValidationType.Auto); }
private ValidationType DetectValidationType() { if ((base.reader.Schemas != null) && (base.reader.Schemas.Count > 0)) { XmlSchemaCollectionEnumerator enumerator = base.reader.Schemas.GetEnumerator(); while (enumerator.MoveNext()) { SchemaInfo schemaInfo = enumerator.CurrentNode.SchemaInfo; if (schemaInfo.SchemaType == SchemaType.XSD) { return(ValidationType.Schema); } if (schemaInfo.SchemaType == SchemaType.XDR) { return(ValidationType.XDR); } } } if (base.reader.NodeType == XmlNodeType.Element) { switch (base.SchemaNames.SchemaTypeFromRoot(base.reader.LocalName, base.reader.NamespaceURI)) { case SchemaType.XSD: return(ValidationType.Schema); case SchemaType.XDR: return(ValidationType.XDR); } int attributeCount = base.reader.AttributeCount; for (int i = 0; i < attributeCount; i++) { base.reader.MoveToAttribute(i); string namespaceURI = base.reader.NamespaceURI; string localName = base.reader.LocalName; if (Ref.Equal(namespaceURI, base.SchemaNames.NsXmlNs)) { if (XdrBuilder.IsXdrSchema(base.reader.Value)) { base.reader.MoveToElement(); return(ValidationType.XDR); } } else { if (Ref.Equal(namespaceURI, base.SchemaNames.NsXsi)) { base.reader.MoveToElement(); return(ValidationType.Schema); } if (Ref.Equal(namespaceURI, base.SchemaNames.QnDtDt.Namespace) && Ref.Equal(localName, base.SchemaNames.QnDtDt.Name)) { base.reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(base.reader.Value); base.reader.MoveToElement(); return(ValidationType.XDR); } } } if (attributeCount > 0) { base.reader.MoveToElement(); } } return(ValidationType.Auto); }