abstract private ParseValue ( string s, |
||
s | string | |
typDest | ||
nameTable | ||
nsmgr | IXmlNamespaceResolver | |
return | object |
public static object ReadTypedValue(XmlReader reader, object type, XmlNamespaceManager nsResolver, StringBuilder tmpBuilder) #endif { if (tmpBuilder == null) { tmpBuilder = new StringBuilder(); } XmlSchemaDatatype dt = type as XmlSchemaDatatype; XmlSchemaSimpleType st = type as XmlSchemaSimpleType; if (st != null) { dt = st.Datatype; } if (dt == null) { return(null); } switch (reader.NodeType) { case XmlNodeType.Element: if (reader.IsEmptyElement) { return(null); } tmpBuilder.Length = 0; bool loop = true; do { reader.Read(); switch (reader.NodeType) { case XmlNodeType.SignificantWhitespace: case XmlNodeType.Text: case XmlNodeType.CDATA: tmpBuilder.Append(reader.Value); break; case XmlNodeType.Comment: break; default: loop = false; break; } } while (loop && !reader.EOF && reader.ReadState == ReadState.Interactive); return(dt.ParseValue(tmpBuilder.ToString(), reader.NameTable, nsResolver)); case XmlNodeType.Attribute: return(dt.ParseValue(reader.Value, reader.NameTable, nsResolver)); } return(null); }
public static void SetDefaultTypedValue( SchemaAttDef attdef, IDtdParserAdapter readerAdapter ) { try { string value = attdef.DefaultValueExpanded; XmlSchemaDatatype dtype = attdef.Datatype; if (dtype == null) { return; // no reason to check } if (dtype.TokenizedType != XmlTokenizedType.CDATA) { value = value.Trim(); } attdef.DefaultValueTyped = dtype.ParseValue(value, readerAdapter.NameTable, readerAdapter.NamespaceResolver); } #if DEBUG catch (XmlSchemaException ex) { Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message); #else catch (Exception) { #endif IValidationEventHandling eventHandling = ((IDtdParserAdapterWithValidation)readerAdapter).ValidationEventHandling; if (eventHandling != null) { XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString()); eventHandling.SendEvent(e, XmlSeverityType.Error); } } }
public static void SetDefaultTypedValue(SchemaAttDef attdef, IDtdParserAdapter readerAdapter) { try { string defaultValueExpanded = attdef.DefaultValueExpanded; XmlSchemaDatatype datatype = attdef.Datatype; if (datatype != null) { if (datatype.TokenizedType != XmlTokenizedType.CDATA) { defaultValueExpanded = defaultValueExpanded.Trim(); } attdef.DefaultValueTyped = datatype.ParseValue(defaultValueExpanded, readerAdapter.NameTable, readerAdapter.NamespaceResolver); } } catch (Exception) { IValidationEventHandling validationEventHandling = ((IDtdParserAdapterWithValidation)readerAdapter).ValidationEventHandling; if (validationEventHandling != null) { XmlSchemaException exception = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString()); validationEventHandling.SendEvent(exception, XmlSeverityType.Error); } } }
private void CheckValue(string value, SchemaAttDef attdef) { try { base.reader.TypedValueObject = null; bool flag = attdef != null; XmlSchemaDatatype datatype = flag ? attdef.Datatype : base.context.ElementDecl.Datatype; if (datatype != null) { object pVal = datatype.ParseValue(value, base.NameTable, this.nsManager, true); switch (datatype.TokenizedType) { case XmlTokenizedType.ENTITY: case XmlTokenizedType.ID: case XmlTokenizedType.IDREF: if (datatype.Variety == XmlSchemaDatatypeVariety.List) { string[] strArray = (string[])pVal; for (int i = 0; i < strArray.Length; i++) { this.ProcessTokenizedType(datatype.TokenizedType, strArray[i]); } } else { this.ProcessTokenizedType(datatype.TokenizedType, (string)pVal); } break; } SchemaDeclBase base2 = flag ? ((SchemaDeclBase)attdef) : ((SchemaDeclBase)base.context.ElementDecl); if (!base2.CheckValue(pVal)) { if (flag) { base.SendValidationEvent("Sch_FixedAttributeValue", attdef.Name.ToString()); } else { base.SendValidationEvent("Sch_FixedElementValue", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace)); } } if (datatype.Variety == XmlSchemaDatatypeVariety.Union) { pVal = this.UnWrapUnion(pVal); } base.reader.TypedValueObject = pVal; } } catch (XmlSchemaException) { if (attdef != null) { base.SendValidationEvent("Sch_AttributeValueDataType", attdef.Name.ToString()); } else { base.SendValidationEvent("Sch_ElementValueDataType", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace)); } } }
public static void CheckDefaultValue(string value, SchemaAttDef attdef, SchemaInfo sinfo, XmlNamespaceManager nsManager, XmlNameTable NameTable, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNo, int linePos) { try { XmlSchemaDatatype datatype = attdef.Datatype; if (datatype != null) { if (datatype.TokenizedType != XmlTokenizedType.CDATA) { value = value.Trim(); } if (value.Length != 0) { object pVal = datatype.ParseValue(value, NameTable, nsManager); XmlTokenizedType tokenizedType = datatype.TokenizedType; if (tokenizedType == XmlTokenizedType.ENTITY) { if (datatype.Variety == XmlSchemaDatatypeVariety.List) { string[] strArray = (string[])pVal; for (int i = 0; i < strArray.Length; i++) { BaseValidator.ProcessEntity(sinfo, strArray[i], sender, eventhandler, baseUri, lineNo, linePos); } } else { BaseValidator.ProcessEntity(sinfo, (string)pVal, sender, eventhandler, baseUri, lineNo, linePos); } } else if ((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(pVal)) { XmlSchemaException ex = new XmlSchemaException("Sch_EnumerationValue", pVal.ToString(), baseUri, lineNo, linePos); if (eventhandler == null) { throw ex; } eventhandler(sender, new ValidationEventArgs(ex)); } attdef.DefaultValueTyped = pVal; } } } catch { XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString(), baseUri, lineNo, linePos); if (eventhandler == null) { throw exception2; } eventhandler(sender, new ValidationEventArgs(exception2)); } }
internal override int Validate(ValidationEventHandler h, XmlSchema schema) { if (base.IsValidated(schema.ValidationId)) { return(this.errorCount); } if (this.SchemaType != null) { this.SchemaType.Validate(h, schema); this.attributeType = this.SchemaType; } else if (this.SchemaTypeName != null && this.SchemaTypeName != XmlQualifiedName.Empty) { XmlSchemaType xmlSchemaType = schema.FindSchemaType(this.SchemaTypeName); if (xmlSchemaType is XmlSchemaComplexType) { base.error(h, "An attribute can't have complexType Content"); } else if (xmlSchemaType != null) { this.errorCount += xmlSchemaType.Validate(h, schema); this.attributeType = xmlSchemaType; } else if (this.SchemaTypeName == XmlSchemaComplexType.AnyTypeName) { this.attributeType = XmlSchemaComplexType.AnyType; } else if (XmlSchemaUtil.IsBuiltInDatatypeName(this.SchemaTypeName)) { this.attributeType = XmlSchemaDatatype.FromName(this.SchemaTypeName); if (this.attributeType == null) { base.error(h, "Invalid xml schema namespace datatype was specified."); } } else if (!schema.IsNamespaceAbsent(this.SchemaTypeName.Namespace)) { base.error(h, "Referenced schema type " + this.SchemaTypeName + " was not found in the corresponding schema."); } } if (this.RefName != null && this.RefName != XmlQualifiedName.Empty) { this.referencedAttribute = schema.FindAttribute(this.RefName); if (this.referencedAttribute != null) { this.errorCount += this.referencedAttribute.Validate(h, schema); } else if (!schema.IsNamespaceAbsent(this.RefName.Namespace)) { base.error(h, "Referenced attribute " + this.RefName + " was not found in the corresponding schema."); } } if (this.attributeType == null) { this.attributeType = XmlSchemaSimpleType.AnySimpleType; } if (this.defaultValue != null || this.fixedValue != null) { XmlSchemaDatatype xmlSchemaDatatype = this.attributeType as XmlSchemaDatatype; if (xmlSchemaDatatype == null) { xmlSchemaDatatype = ((XmlSchemaSimpleType)this.attributeType).Datatype; } if (xmlSchemaDatatype.TokenizedType == XmlTokenizedType.QName) { base.error(h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values."); } else { try { if (this.defaultValue != null) { this.validatedDefaultValue = xmlSchemaDatatype.Normalize(this.defaultValue); xmlSchemaDatatype.ParseValue(this.validatedDefaultValue, null, null); } } catch (Exception innerException) { XmlSchemaObject.error(h, "The Attribute's default value is invalid with its type definition.", innerException); } try { if (this.fixedValue != null) { this.validatedFixedValue = xmlSchemaDatatype.Normalize(this.fixedValue); this.validatedFixedTypedValue = xmlSchemaDatatype.ParseValue(this.validatedFixedValue, null, null); } } catch (Exception innerException2) { XmlSchemaObject.error(h, "The Attribute's fixed value is invalid with its type definition.", innerException2); } } } if (this.Use == XmlSchemaUse.None) { this.validatedUse = XmlSchemaUse.Optional; } else { this.validatedUse = this.Use; } if (this.attributeType != null) { this.attributeSchemaType = (this.attributeType as XmlSchemaSimpleType); if (this.attributeType == XmlSchemaSimpleType.AnySimpleType) { this.attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType; } if (this.attributeSchemaType == null) { this.attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType(this.SchemaTypeName); } } this.ValidationId = schema.ValidationId; return(this.errorCount); }
private void CheckValue( string value, SchemaAttDef attdef ) { try { reader.TypedValueObject = null; bool isAttn = attdef != null; XmlSchemaDatatype dtype = isAttn ? attdef.Datatype : context.ElementDecl.Datatype; if (dtype == null) { return; // no reason to check } object typedValue = dtype.ParseValue(value, NameTable, nsManager, true); // Check special types XmlTokenizedType ttype = dtype.TokenizedType; if (ttype == XmlTokenizedType.ENTITY || ttype == XmlTokenizedType.ID || ttype == XmlTokenizedType.IDREF) { if (dtype.Variety == XmlSchemaDatatypeVariety.List) { string[] ss = (string[])typedValue; for (int i = 0; i < ss.Length; ++i) { ProcessTokenizedType(dtype.TokenizedType, ss[i]); } } else { ProcessTokenizedType(dtype.TokenizedType, (string)typedValue); } } SchemaDeclBase decl = isAttn ? (SchemaDeclBase)attdef : (SchemaDeclBase)context.ElementDecl; if (!decl.CheckValue(typedValue)) { if (isAttn) { SendValidationEvent(Res.Sch_FixedAttributeValue, attdef.Name.ToString()); } else { SendValidationEvent(Res.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace)); } } if (dtype.Variety == XmlSchemaDatatypeVariety.Union) { typedValue = UnWrapUnion(typedValue); } reader.TypedValueObject = typedValue; } catch (XmlSchemaException) { if (attdef != null) { SendValidationEvent(Res.Sch_AttributeValueDataType, attdef.Name.ToString()); } else { SendValidationEvent(Res.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace)); } } }
private void ProcessXsiAttributes(out XmlQualifiedName xsiType, out string xsiNil) { string[] xsiSchemaLocation = null; string xsiNoNamespaceSchemaLocation = null; xsiType = XmlQualifiedName.Empty; xsiNil = null; if (reader.Depth == 0) { //Load schema for empty namespace LoadSchema(string.Empty, null); //Should load schemas for namespaces already added to nsManager foreach (string ns in nsManager.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml).Values) { LoadSchema(ns, null); } } if (reader.MoveToFirstAttribute()) { do { string objectNs = reader.NamespaceURI; string objectName = reader.LocalName; if (Ref.Equal(objectNs, NsXmlNs)) { LoadSchema(reader.Value, null); if (bManageNamespaces) { nsManager.AddNamespace(reader.Prefix.Length == 0 ? string.Empty : reader.LocalName, reader.Value); } } else if (Ref.Equal(objectNs, NsXsi)) { if (Ref.Equal(objectName, XsiSchemaLocation)) { xsiSchemaLocation = (string[])dtStringArray.ParseValue(reader.Value, NameTable, nsManager); } else if (Ref.Equal(objectName, XsiNoNamespaceSchemaLocation)) { xsiNoNamespaceSchemaLocation = reader.Value; } else if (Ref.Equal(objectName, XsiType)) { xsiType = (XmlQualifiedName)dtQName.ParseValue(reader.Value, NameTable, nsManager); } else if (Ref.Equal(objectName, XsiNil)) { xsiNil = reader.Value; } } } while(reader.MoveToNextAttribute()); reader.MoveToElement(); } if (xsiNoNamespaceSchemaLocation != null) { LoadSchema(string.Empty, xsiNoNamespaceSchemaLocation); } if (xsiSchemaLocation != null) { for (int i = 0; i < xsiSchemaLocation.Length - 1; i += 2) { LoadSchema((string)xsiSchemaLocation[i], (string)xsiSchemaLocation[i + 1]); } } }
private void CheckValue(string value, SchemaAttDef attdef) { try { base.reader.TypedValueObject = null; bool flag = attdef != null; XmlSchemaDatatype datatype = flag ? attdef.Datatype : base.context.ElementDecl.Datatype; if (datatype != null) { if (datatype.TokenizedType != XmlTokenizedType.CDATA) { value = value.Trim(); } if (value.Length != 0) { object pVal = datatype.ParseValue(value, base.NameTable, this.nsManager); base.reader.TypedValueObject = pVal; switch (datatype.TokenizedType) { case XmlTokenizedType.ENTITY: case XmlTokenizedType.ID: case XmlTokenizedType.IDREF: if (datatype.Variety == XmlSchemaDatatypeVariety.List) { string[] strArray = (string[])pVal; for (int i = 0; i < strArray.Length; i++) { this.ProcessTokenizedType(datatype.TokenizedType, strArray[i]); } } else { this.ProcessTokenizedType(datatype.TokenizedType, (string)pVal); } break; } SchemaDeclBase base2 = flag ? ((SchemaDeclBase)attdef) : ((SchemaDeclBase)base.context.ElementDecl); if ((base2.MaxLength != 0xffffffffL) && (value.Length > base2.MaxLength)) { base.SendValidationEvent("Sch_MaxLengthConstraintFailed", value); } if ((base2.MinLength != 0xffffffffL) && (value.Length < base2.MinLength)) { base.SendValidationEvent("Sch_MinLengthConstraintFailed", value); } if ((base2.Values != null) && !base2.CheckEnumeration(pVal)) { if (datatype.TokenizedType == XmlTokenizedType.NOTATION) { base.SendValidationEvent("Sch_NotationValue", pVal.ToString()); } else { base.SendValidationEvent("Sch_EnumerationValue", pVal.ToString()); } } if (!base2.CheckValue(pVal)) { if (flag) { base.SendValidationEvent("Sch_FixedAttributeValue", attdef.Name.ToString()); } else { base.SendValidationEvent("Sch_FixedElementValue", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace)); } } } } } catch (XmlSchemaException) { if (attdef != null) { base.SendValidationEvent("Sch_AttributeValueDataType", attdef.Name.ToString()); } else { base.SendValidationEvent("Sch_ElementValueDataType", XmlSchemaValidator.QNameString(base.context.LocalName, base.context.Namespace)); } } }
/// <summary> /// Schema Component: /// QName, SimpleType, Scope, Default|Fixed, annotation /// </summary> internal override int Validate(ValidationEventHandler h, XmlSchema schema) { if (IsValidated(schema.ValidationId)) { return(errorCount); } // -- Attribute Declaration Schema Component -- // {name}, {target namespace} -> QualifiedName. Already Compile()d. // {type definition} -> attributeType. From SchemaType or SchemaTypeName. // {scope} -> ParentIsSchema | isRedefineChild. // {value constraint} -> ValidatedFixedValue, ValidatedDefaultValue. // {annotation} // -- Attribute Use Schema Component -- // {required} // {attribute declaration} // {value constraint} // First, fill type information for type reference if (SchemaType != null) { SchemaType.Validate(h, schema); attributeType = SchemaType; } else if (SchemaTypeName != null && SchemaTypeName != XmlQualifiedName.Empty) { // If type is null, then it is missing sub components . XmlSchemaType type = schema.FindSchemaType(SchemaTypeName); if (type is XmlSchemaComplexType) { error(h, "An attribute can't have complexType Content"); } else if (type != null) // simple type { errorCount += type.Validate(h, schema); attributeType = type; } else if (SchemaTypeName == XmlSchemaComplexType.AnyTypeName) { attributeType = XmlSchemaComplexType.AnyType; } else if (XmlSchemaUtil.IsBuiltInDatatypeName(SchemaTypeName)) { attributeType = XmlSchemaDatatype.FromName(SchemaTypeName); if (attributeType == null) { error(h, "Invalid xml schema namespace datatype was specified."); } } // otherwise, it might be missing sub components. else if (!schema.IsNamespaceAbsent(SchemaTypeName.Namespace)) { error(h, "Referenced schema type " + SchemaTypeName + " was not found in the corresponding schema."); } } // Then, fill type information for the type references for the referencing attributes if (RefName != null && RefName != XmlQualifiedName.Empty) { referencedAttribute = schema.FindAttribute(RefName); // If el is null, then it is missing sub components . if (referencedAttribute != null) { errorCount += referencedAttribute.Validate(h, schema); } // otherwise, it might be missing sub components. else if (!schema.IsNamespaceAbsent(RefName.Namespace)) { error(h, "Referenced attribute " + RefName + " was not found in the corresponding schema."); } } if (attributeType == null) { attributeType = XmlSchemaSimpleType.AnySimpleType; } // Validate {value constraints} if (defaultValue != null || fixedValue != null) { XmlSchemaDatatype datatype = attributeType as XmlSchemaDatatype; if (datatype == null) { datatype = ((XmlSchemaSimpleType)attributeType).Datatype; } if (datatype.TokenizedType == XmlTokenizedType.QName) { error(h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values."); } else { try { if (defaultValue != null) { validatedDefaultValue = datatype.Normalize(defaultValue); datatype.ParseValue(validatedDefaultValue, null, null); } } catch (Exception ex) { // FIXME: This is not a good way to handle exception. error(h, "The Attribute's default value is invalid with its type definition.", ex); } try { if (fixedValue != null) { validatedFixedValue = datatype.Normalize(fixedValue); validatedFixedTypedValue = datatype.ParseValue(validatedFixedValue, null, null); } } catch (Exception ex) { // FIXME: This is not a good way to handle exception. error(h, "The Attribute's fixed value is invalid with its type definition.", ex); } } } if (Use == XmlSchemaUse.None) { validatedUse = XmlSchemaUse.Optional; } else { validatedUse = Use; } #if NET_2_0 if (attributeType != null) { attributeSchemaType = attributeType as XmlSchemaSimpleType; if (attributeType == XmlSchemaSimpleType.AnySimpleType) { attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType; } if (attributeSchemaType == null) { attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType(SchemaTypeName); } } #endif ValidationId = schema.ValidationId; return(errorCount); }
public static void CheckDefaultValue( string value, SchemaAttDef attdef, SchemaInfo sinfo, XmlNamespaceManager nsManager, XmlNameTable NameTable, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNo, int linePos ) { try { XmlSchemaDatatype dtype = attdef.Datatype; if (dtype == null) { return; // no reason to check } if (dtype.TokenizedType != XmlTokenizedType.CDATA) { value = value.Trim(); } if (value.Length == 0) { return; // don't need to check } object typedValue = dtype.ParseValue(value, NameTable, nsManager); // Check special types XmlTokenizedType ttype = dtype.TokenizedType; if (ttype == XmlTokenizedType.ENTITY) { if (dtype.Variety == XmlSchemaDatatypeVariety.List) { string[] ss = (string[])typedValue; for (int i = 0; i < ss.Length; ++i) { ProcessEntity(sinfo, ss[i], sender, eventhandler, baseUri, lineNo, linePos); } } else { ProcessEntity(sinfo, (string)typedValue, sender, eventhandler, baseUri, lineNo, linePos); } } else if (ttype == XmlTokenizedType.ENUMERATION) { if (!attdef.CheckEnumeration(typedValue)) { XmlSchemaException e = new XmlSchemaException(SR.Sch_EnumerationValue, typedValue.ToString(), baseUri, lineNo, linePos); if (eventhandler != null) { eventhandler(sender, new ValidationEventArgs(e)); } else { throw e; } } } attdef.DefaultValueTyped = typedValue; } #if DEBUG catch (XmlSchemaException ex) { Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message); #else catch { #endif XmlSchemaException e = new XmlSchemaException(SR.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos); if (eventhandler != null) { eventhandler(sender, new ValidationEventArgs(e)); } else { throw e; } } }
private void CheckValue( string value, SchemaAttDef attdef ) { try { reader.TypedValueObject = null; bool isAttn = attdef != null; XmlSchemaDatatype dtype = isAttn ? attdef.Datatype : context.ElementDecl.Datatype; if (dtype == null) { return; // no reason to check } if (dtype.TokenizedType != XmlTokenizedType.CDATA) { value = value.Trim(); } if (value.Length == 0) { return; // don't need to check } object typedValue = dtype.ParseValue(value, NameTable, _nsManager); reader.TypedValueObject = typedValue; // Check special types XmlTokenizedType ttype = dtype.TokenizedType; if (ttype == XmlTokenizedType.ENTITY || ttype == XmlTokenizedType.ID || ttype == XmlTokenizedType.IDREF) { if (dtype.Variety == XmlSchemaDatatypeVariety.List) { string[] ss = (string[])typedValue; for (int i = 0; i < ss.Length; ++i) { ProcessTokenizedType(dtype.TokenizedType, ss[i]); } } else { ProcessTokenizedType(dtype.TokenizedType, (string)typedValue); } } SchemaDeclBase decl = isAttn ? (SchemaDeclBase)attdef : (SchemaDeclBase)context.ElementDecl; if (decl.MaxLength != uint.MaxValue) { if (value.Length > decl.MaxLength) { SendValidationEvent(SR.Sch_MaxLengthConstraintFailed, value); } } if (decl.MinLength != uint.MaxValue) { if (value.Length < decl.MinLength) { SendValidationEvent(SR.Sch_MinLengthConstraintFailed, value); } } if (decl.Values != null && !decl.CheckEnumeration(typedValue)) { if (dtype.TokenizedType == XmlTokenizedType.NOTATION) { SendValidationEvent(SR.Sch_NotationValue, typedValue.ToString()); } else { SendValidationEvent(SR.Sch_EnumerationValue, typedValue.ToString()); } } if (!decl.CheckValue(typedValue)) { if (isAttn) { SendValidationEvent(SR.Sch_FixedAttributeValue, attdef.Name.ToString()); } else { SendValidationEvent(SR.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace)); } } } catch (XmlSchemaException) { if (attdef != null) { SendValidationEvent(SR.Sch_AttributeValueDataType, attdef.Name.ToString()); } else { SendValidationEvent(SR.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace)); } } }
private void ProcessXsiAttributes(out XmlQualifiedName xsiType, out string xsiNil) { string[] strArray = null; string url = null; xsiType = XmlQualifiedName.Empty; xsiNil = null; if (base.reader.Depth == 0) { this.LoadSchema(string.Empty, null); foreach (string str2 in this.nsManager.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml).Values) { this.LoadSchema(str2, null); } } if (base.reader.MoveToFirstAttribute()) { do { string namespaceURI = base.reader.NamespaceURI; string localName = base.reader.LocalName; if (Ref.Equal(namespaceURI, this.NsXmlNs)) { this.LoadSchema(base.reader.Value, null); if (this.bManageNamespaces) { this.nsManager.AddNamespace((base.reader.Prefix.Length == 0) ? string.Empty : base.reader.LocalName, base.reader.Value); } } else if (Ref.Equal(namespaceURI, this.NsXsi)) { if (Ref.Equal(localName, this.XsiSchemaLocation)) { strArray = (string[])dtStringArray.ParseValue(base.reader.Value, base.NameTable, this.nsManager); } else if (Ref.Equal(localName, this.XsiNoNamespaceSchemaLocation)) { url = base.reader.Value; } else if (Ref.Equal(localName, this.XsiType)) { xsiType = (XmlQualifiedName)dtQName.ParseValue(base.reader.Value, base.NameTable, this.nsManager); } else if (Ref.Equal(localName, this.XsiNil)) { xsiNil = base.reader.Value; } } }while (base.reader.MoveToNextAttribute()); base.reader.MoveToElement(); } if (url != null) { this.LoadSchema(string.Empty, url); } if (strArray != null) { for (int i = 0; i < (strArray.Length - 1); i += 2) { this.LoadSchema(strArray[i], strArray[i + 1]); } } }
public static object ReadTypedValue(XmlReader reader, object type, IXmlNamespaceResolver nsResolver, StringBuilder tmpBuilder) { if (tmpBuilder == null) { tmpBuilder = new StringBuilder(); } XmlSchemaDatatype xmlSchemaDatatype = type as XmlSchemaDatatype; XmlSchemaSimpleType xmlSchemaSimpleType = type as XmlSchemaSimpleType; if (xmlSchemaSimpleType != null) { xmlSchemaDatatype = xmlSchemaSimpleType.Datatype; } if (xmlSchemaDatatype == null) { return(null); } XmlNodeType nodeType = reader.NodeType; if (nodeType != XmlNodeType.Element) { if (nodeType != XmlNodeType.Attribute) { return(null); } return(xmlSchemaDatatype.ParseValue(reader.Value, reader.NameTable, nsResolver)); } else { if (reader.IsEmptyElement) { return(null); } tmpBuilder.Length = 0; bool flag = true; for (;;) { reader.Read(); XmlNodeType nodeType2 = reader.NodeType; switch (nodeType2) { case XmlNodeType.Text: case XmlNodeType.CDATA: goto IL_9E; default: if (nodeType2 == XmlNodeType.SignificantWhitespace) { goto IL_9E; } flag = false; break; case XmlNodeType.Comment: break; } IL_BC: if (!flag || reader.EOF || reader.ReadState != ReadState.Interactive) { break; } continue; IL_9E: tmpBuilder.Append(reader.Value); goto IL_BC; } return(xmlSchemaDatatype.ParseValue(tmpBuilder.ToString(), reader.NameTable, nsResolver)); } }