/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// xmlvaluegetter.BeginInvoke(callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this XmlValueGetter xmlvaluegetter, AsyncCallback callback) { if (xmlvaluegetter == null) { throw new ArgumentNullException("xmlvaluegetter"); } return(xmlvaluegetter.BeginInvoke(callback, null)); }
XsElement element; // ... xsinfo.Element? #endregion public XmlSchemaValidatingReader(XmlReader reader, XmlReaderSettings settings) { IXmlNamespaceResolver nsResolver = reader as IXmlNamespaceResolver; if (nsResolver == null) { // throw new ArgumentException ("Argument XmlReader must implement IXmlNamespaceResolver."); nsResolver = new XmlNamespaceManager(reader.NameTable); } XmlSchemaSet schemas = settings.Schemas; if (schemas == null) { schemas = new XmlSchemaSet(); } options = settings.ValidationFlags; this.reader = reader; v = new XmlSchemaValidator( reader.NameTable, schemas, nsResolver, options); readerLineInfo = reader as IXmlLineInfo; startDepth = reader.Depth; getter = delegate() { return(Value); }; xsinfo = new XmlSchemaInfo(); // transition cache v.LineInfoProvider = this; v.ValidationEventSender = reader; this.nsResolver = nsResolver; #if !NON_MONO ValidationEventHandler += delegate(object o, ValidationEventArgs e) { settings.OnValidationError(o, e); }; if (settings != null && settings.Schemas != null) { v.XmlResolver = settings.Schemas.XmlResolver; } else { v.XmlResolver = new XmlUrlResolver(); } #else v.XmlResolver = new XmlUrlResolver(); #endif v.Initialize(); }
public XmlSchemaValidatingReader(XmlReader reader, XmlReaderSettings settings) { XmlSchemaValidatingReader <> f__this = this; IXmlNamespaceResolver xmlNamespaceResolver = reader as IXmlNamespaceResolver; if (xmlNamespaceResolver == null) { xmlNamespaceResolver = new XmlNamespaceManager(reader.NameTable); } XmlSchemaSet xmlSchemaSet = settings.Schemas; if (xmlSchemaSet == null) { xmlSchemaSet = new XmlSchemaSet(); } this.options = settings.ValidationFlags; this.reader = reader; this.v = new XmlSchemaValidator(reader.NameTable, xmlSchemaSet, xmlNamespaceResolver, this.options); if (reader.BaseURI != string.Empty) { this.v.SourceUri = new Uri(reader.BaseURI); } this.readerLineInfo = (reader as IXmlLineInfo); this.getter = delegate() { if (< > f__this.v.CurrentAttributeType != null) { return(< > f__this.v.CurrentAttributeType.ParseValue(< > f__this.Value, <> f__this.NameTable, <> f__this)); } return(< > f__this.Value); }; this.xsinfo = new XmlSchemaInfo(); this.v.LineInfoProvider = this; this.v.ValidationEventSender = reader; this.nsResolver = xmlNamespaceResolver; this.ValidationEventHandler += delegate(object o, ValidationEventArgs e) { settings.OnValidationError(o, e); }; if (settings != null && settings.Schemas != null) { this.v.XmlResolver = settings.Schemas.XmlResolver; } else { this.v.XmlResolver = new XmlUrlResolver(); } this.v.Initialize(); }
public DocumentSchemaValidator(XmlDocument ownerDocument, XmlSchemaSet schemas, ValidationEventHandler eventHandler) { this.schemas = schemas; this.eventHandler = eventHandler; this.document = ownerDocument; this.internalEventHandler = new ValidationEventHandler(this.InternalValidationCallBack); this.nameTable = this.document.NameTable; this.nsManager = new XmlNamespaceManager(this.nameTable); this.nodeValueGetter = new XmlValueGetter(this.GetNodeValue); this.psviAugmentation = true; this.NsXmlNs = this.nameTable.Add("http://www.w3.org/2000/xmlns/"); this.NsXsi = this.nameTable.Add("http://www.w3.org/2001/XMLSchema-instance"); this.XsiType = this.nameTable.Add("type"); this.XsiNil = this.nameTable.Add("nil"); }
XsElement element; // ... xsinfo.Element? #endregion public XmlSchemaValidatingReader (XmlReader reader, XmlReaderSettings settings) { IXmlNamespaceResolver nsResolver = reader as IXmlNamespaceResolver; if (nsResolver == null) // throw new ArgumentException ("Argument XmlReader must implement IXmlNamespaceResolver."); nsResolver = new XmlNamespaceManager (reader.NameTable); XmlSchemaSet schemas = settings.Schemas; if (schemas == null) schemas = new XmlSchemaSet (); options = settings.ValidationFlags; this.reader = reader; v = new XmlSchemaValidator ( reader.NameTable, schemas, nsResolver, options); if (reader.BaseURI != String.Empty) v.SourceUri = new Uri (reader.BaseURI); readerLineInfo = reader as IXmlLineInfo; getter = delegate () { if (v.CurrentAttributeType != null) return v.CurrentAttributeType.ParseValue (Value, NameTable, this); else return Value; }; xsinfo = new XmlSchemaInfo (); // transition cache v.LineInfoProvider = this; v.ValidationEventSender = reader; this.nsResolver = nsResolver; #if !NON_MONO ValidationEventHandler += delegate (object o, ValidationEventArgs e) { settings.OnValidationError (o, e); }; if (settings != null && settings.Schemas != null) v.XmlResolver = settings.Schemas.XmlResolver; else v.XmlResolver = new XmlUrlResolver (); #else v.XmlResolver = new XmlUrlResolver (); #endif v.Initialize (); }
public DocumentSchemaValidator(XmlDocument ownerDocument, XmlSchemaSet schemas, ValidationEventHandler eventHandler) { this.schemas = schemas; this.eventHandler = eventHandler; document = ownerDocument; this.internalEventHandler = new ValidationEventHandler(InternalValidationCallBack); this.nameTable = document.NameTable; nsManager = new XmlNamespaceManager(nameTable); Debug.Assert(schemas != null && schemas.Count > 0); nodeValueGetter = new XmlValueGetter(GetNodeValue); psviAugmentation = true; //Add common strings to be compared to NameTable NsXmlNs = nameTable.Add(XmlReservedNs.NsXmlNs); NsXsi = nameTable.Add(XmlReservedNs.NsXsi); XsiType = nameTable.Add("type"); XsiNil = nameTable.Add("nil"); }
public DocumentSchemaValidator(XmlDocument ownerDocument, XmlSchemaSet schemas, ValidationEventHandler eventHandler) { _schemas = schemas; _eventHandler = eventHandler; _document = ownerDocument; _internalEventHandler = new ValidationEventHandler(InternalValidationCallBack); _nameTable = _document.NameTable; _nsManager = new XmlNamespaceManager(_nameTable); Debug.Assert(schemas != null && schemas.Count > 0); _nodeValueGetter = new XmlValueGetter(GetNodeValue); _psviAugmentation = true; //Add common strings to be compared to NameTable _nsXmlNs = _nameTable.Add(XmlReservedNs.NsXmlNs); _nsXsi = _nameTable.Add(XmlReservedNs.NsXsi); _xsiType = _nameTable.Add("type"); _xsiNil = _nameTable.Add("nil"); }
// 3.2.4 Attribute Locally Valid and 3.4.4 private object AssessAttributeLocallyValid (XsAttribute attr, XmlSchemaInfo info, XmlValueGetter getter) { if (info != null) { info.SchemaAttribute = attr; info.SchemaType = attr.AttributeSchemaType; } // 2. - 4. if (attr.AttributeType == null) HandleError ("Attribute type is missing for " + attr.QualifiedName); XsDatatype dt = attr.AttributeType as XsDatatype; if (dt == null) dt = ((SimpleType) attr.AttributeType).Datatype; object parsedValue = null; // It is a bit heavy process, so let's omit as long as possible ;-) if (dt != SimpleType.AnySimpleType || attr.ValidatedFixedValue != null) { try { CurrentAttributeType = dt; parsedValue = getter (); } catch (Exception ex) { // It is inevitable and bad manner. HandleError (String.Format ("Attribute value is invalid against its data type {0}", dt != null ? dt.TokenizedType : default (XmlTokenizedType)), ex); } // check part of 3.14.4 StringValid SimpleType st = attr.AttributeSchemaType; if (st != null) { string xav = null; try { xav = new XmlAtomicValue (parsedValue, attr.AttributeSchemaType).Value; } catch (Exception ex) { HandleError (String.Format ("Failed to convert attribute value to type {0}", st.QualifiedName), ex); } if (xav != null) ValidateRestrictedSimpleTypeValue (st, ref dt, xav); } if (attr.ValidatedFixedValue != null) { if (!XmlSchemaUtil.AreSchemaDatatypeEqual (attr.AttributeSchemaType, attr.ValidatedFixedTypedValue, attr.AttributeSchemaType, parsedValue)) HandleError (String.Format ("The value of the attribute {0} does not match with its fixed value '{1}' in the space of type {2}", attr.QualifiedName, attr.ValidatedFixedValue, dt)); parsedValue = attr.ValidatedFixedTypedValue; } } #region ID Constraints if (!IgnoreIdentity) { string error = idManager.AssessEachAttributeIdentityConstraint (dt, parsedValue, ((QName) elementQNameStack [elementQNameStack.Count - 1]).Name); if (error != null) HandleError (error); } #endregion #region Key Constraints if (!IgnoreIdentity) ValidateKeyFieldsAttribute (attr, parsedValue); #endregion return parsedValue; }
// TextDeriv. It should do the same as ValidateText() in our actual implementation (whitespaces are conditioned). public void ValidateWhitespace (XmlValueGetter getter) { ValidateText (getter); }
private object AssessAttributeElementLocallyValidType (string localName, string ns, XmlValueGetter getter, XmlSchemaInfo info) { ComplexType cType = Context.ActualType as ComplexType; XmlQualifiedName qname = new XmlQualifiedName (localName, ns); // including 3.10.4 Item Valid (Wildcard) XmlSchemaObject attMatch = XmlSchemaUtil.FindAttributeDeclaration (ns, schemas, cType, qname); if (attMatch == null) HandleError ("Attribute declaration was not found for " + qname); XsAttribute attdecl = attMatch as XsAttribute; if (attdecl != null) { AssessAttributeLocallyValidUse (attdecl); return AssessAttributeLocallyValid (attdecl, info, getter); } // otherwise anyAttribute or null. return null; }
// I guess this weird XmlValueGetter is for such case that // value might not be required (and thus it improves // performance in some cases. Doh). // The return value is typed primitive, if possible. // AttDeriv public object ValidateAttribute ( string localName, string ns, XmlValueGetter attributeValue, XmlSchemaInfo info) { if (localName == null) throw new ArgumentNullException ("localName"); if (ns == null) throw new ArgumentNullException ("ns"); if (attributeValue == null) throw new ArgumentNullException ("attributeValue"); SetCurrentInfo (info); try { bool wasInitial = initial; if (initial) initial = false; else CheckState (Transition.StartTag); QName qname = new QName (localName, ns); if (occuredAtts.Contains (qname)) throw new InvalidOperationException (String.Format ("Attribute '{0}' has already been validated in the same element.", qname)); occuredAtts.Add (qname); if (ns == XmlNamespaceManager.XmlnsXmlns) return null; if (schemas.Count == 0) return null; if (wasInitial) { var xa = startType as XmlSchemaAttribute; if (xa == null) return null; return AssessAttributeLocallyValid (xa, info, attributeValue); } if (Context.Element != null && Context.XsiType == null) { // 3.3.4 Element Locally Valid (Type) - attribute if (Context.ActualType is ComplexType) return AssessAttributeElementLocallyValidType (localName, ns, attributeValue, info); else HandleError ("Current simple type cannot accept attributes other than schema instance namespace."); } return null; } finally { current_info = null; } }
// TextDeriv ... without text. Maybe typed check is done by // ValidateAtomicValue(). public void ValidateText (XmlValueGetter getter) { if (getter == null) throw new ArgumentNullException ("getter"); CheckState (Transition.Content); if (schemas.Count == 0) return; if (skipValidationDepth >= 0 && depth > skipValidationDepth) return; ComplexType ct = Context.ActualType as ComplexType; if (ct != null) { switch (ct.ContentType) { case XmlSchemaContentType.Empty: HandleError ("Not allowed character content was found."); break; case XmlSchemaContentType.ElementOnly: string s = storedCharacters.ToString (); if (s.Length > 0 && !XmlChar.IsWhitespace (s)) HandleError ("Not allowed character content was found."); break; } } ValidateCharacters (getter); }
public object ValidateAttribute(string localName, string namespaceUri, XmlValueGetter attributeValue, XmlSchemaInfo schemaInfo) { }
private void ValidateWhitespace(string elementStringValue, XmlValueGetter elementValueGetter) { ValidatorState toState = validationStack.Length > 1 ? ValidatorState.Whitespace : ValidatorState.TopLevelTextOrWS; CheckStateTransition(toState, MethodNames[(int)toState]); if (context.NeedValidateChildren) { if (context.IsNill) { SendValidationEvent(Res.Sch_ContentInNill, QNameString(context.LocalName, context.Namespace)); } XmlSchemaContentType contentType = context.ElementDecl.ContentValidator.ContentType; switch (contentType) { case XmlSchemaContentType.Empty: SendValidationEvent(Res.Sch_InvalidWhitespaceInEmpty, string.Empty); break; case XmlSchemaContentType.TextOnly: if (elementValueGetter != null) { SaveTextValue(elementValueGetter()); } else { SaveTextValue(elementStringValue); } break; case XmlSchemaContentType.Mixed: if (context.ElementDecl.DefaultValueTyped != null) { if (elementValueGetter != null) { SaveTextValue(elementValueGetter()); } else { SaveTextValue(elementStringValue); } } break; default: break; } } }
private void ValidateWhitespace(string elementStringValue, XmlValueGetter elementValueGetter) { ValidatorState toState = (this.validationStack.Length > 1) ? ValidatorState.Whitespace : ValidatorState.TopLevelTextOrWS; this.CheckStateTransition(toState, MethodNames[(int) toState]); if (this.context.NeedValidateChildren) { if (this.context.IsNill) { this.SendValidationEvent("Sch_ContentInNill", QNameString(this.context.LocalName, this.context.Namespace)); } switch (this.context.ElementDecl.ContentValidator.ContentType) { case XmlSchemaContentType.TextOnly: if (elementValueGetter == null) { this.SaveTextValue(elementStringValue); return; } this.SaveTextValue(elementValueGetter()); return; case XmlSchemaContentType.Empty: this.SendValidationEvent("Sch_InvalidWhitespaceInEmpty", string.Empty); return; case XmlSchemaContentType.ElementOnly: break; case XmlSchemaContentType.Mixed: if (this.context.ElementDecl.DefaultValueTyped == null) { break; } if (elementValueGetter == null) { this.SaveTextValue(elementStringValue); break; } this.SaveTextValue(elementValueGetter()); return; default: return; } } }
public void ValidateText(XmlValueGetter elementValue) { }
public object ValidateAttribute(string localName, string namespaceUri, XmlValueGetter attributeValue, XmlSchemaInfo schemaInfo) { if (attributeValue == null) { throw new ArgumentNullException("attributeValue"); } return this.ValidateAttribute(localName, namespaceUri, attributeValue, null, schemaInfo); }
private void ValidateText(string elementStringValue, XmlValueGetter elementValueGetter) { ValidatorState toState = (this.validationStack.Length > 1) ? ValidatorState.Text : ValidatorState.TopLevelTextOrWS; this.CheckStateTransition(toState, MethodNames[(int) toState]); if (this.context.NeedValidateChildren) { if (this.context.IsNill) { this.SendValidationEvent("Sch_ContentInNill", QNameString(this.context.LocalName, this.context.Namespace)); } else { switch (this.context.ElementDecl.ContentValidator.ContentType) { case XmlSchemaContentType.TextOnly: if (elementValueGetter == null) { this.SaveTextValue(elementStringValue); return; } this.SaveTextValue(elementValueGetter()); return; case XmlSchemaContentType.Empty: this.SendValidationEvent("Sch_InvalidTextInEmpty", string.Empty); return; case XmlSchemaContentType.ElementOnly: { string str = (elementValueGetter != null) ? elementValueGetter().ToString() : elementStringValue; if (!this.xmlCharType.IsOnlyWhitespace(str)) { ArrayList expected = this.context.ElementDecl.ContentValidator.ExpectedParticles(this.context, false, this.schemaSet); if ((expected == null) || (expected.Count == 0)) { this.SendValidationEvent("Sch_InvalidTextInElement", BuildElementName(this.context.LocalName, this.context.Namespace)); return; } this.SendValidationEvent("Sch_InvalidTextInElementExpecting", new string[] { BuildElementName(this.context.LocalName, this.context.Namespace), PrintExpectedElements(expected, true) }); return; } return; } case XmlSchemaContentType.Mixed: if (this.context.ElementDecl.DefaultValueTyped == null) { break; } if (elementValueGetter == null) { this.SaveTextValue(elementStringValue); break; } this.SaveTextValue(elementValueGetter()); return; default: return; } } } }
// Extra for XmlSchemaValidtingReader // (not in XsdValidatingReader) //XsElement element; // ... xsinfo.Element? #endregion public XmlSchemaValidatingReader (XmlReader reader, XmlReaderSettings settings) { IXmlNamespaceResolver nsResolver = reader as IXmlNamespaceResolver; if (nsResolver == null) // throw new ArgumentException ("Argument XmlReader must implement IXmlNamespaceResolver."); nsResolver = new XmlNamespaceManager (reader.NameTable); XmlSchemaSet schemas = settings.Schemas; if (schemas == null) schemas = new XmlSchemaSet (); options = settings.ValidationFlags; this.reader = reader; v = new XmlSchemaValidator ( reader.NameTable, schemas, nsResolver, options); if (reader.BaseURI != String.Empty && Uri.IsWellFormedUriString(reader.BaseURI, UriKind.Absolute)) v.SourceUri = new Uri (reader.BaseURI); readerLineInfo = reader as IXmlLineInfo; getter = delegate () { if (v.CurrentAttributeType != null) return v.CurrentAttributeType.ParseValue (Value, NameTable, this); else return Value; }; xsinfo = new XmlSchemaInfo (); // transition cache v.LineInfoProvider = this; v.ValidationEventSender = reader; this.nsResolver = nsResolver; #if !NON_MONO ValidationEventHandler += delegate (object o, ValidationEventArgs e) { settings.OnValidationError (o, e); }; if (settings != null && settings.Schemas != null) v.XmlResolver = settings.Schemas.XmlResolver; else v.XmlResolver = new XmlUrlResolver (); #else v.XmlResolver = new XmlUrlResolver (); #endif v.Initialize (); }
public void ValidateWhitespace(XmlValueGetter elementValue) { }
// Utility for missing validation completion related to child items. private void ValidateCharacters (XmlValueGetter getter) { if (xsiNilDepth >= 0 && xsiNilDepth < depth) HandleError ("Element item appeared, while current element context is nil."); if (shouldValidateCharacters) { CurrentAttributeType = null; storedCharacters.Append (getter ()); } }
private void ValidateText(string elementStringValue, XmlValueGetter elementValueGetter) { ValidatorState toState = validationStack.Length > 1 ? ValidatorState.Text : ValidatorState.TopLevelTextOrWS; CheckStateTransition(toState, MethodNames[(int)toState]); if (context.NeedValidateChildren) { if (context.IsNill) { SendValidationEvent(Res.Sch_ContentInNill, QNameString(context.LocalName, context.Namespace)); return; } XmlSchemaContentType contentType = context.ElementDecl.ContentValidator.ContentType; switch(contentType) { case XmlSchemaContentType.Empty: SendValidationEvent(Res.Sch_InvalidTextInEmpty, string.Empty); break; case XmlSchemaContentType.TextOnly: if (elementValueGetter != null) { SaveTextValue(elementValueGetter()); } else { SaveTextValue(elementStringValue); } break; case XmlSchemaContentType.ElementOnly: string textValue = elementValueGetter != null ? elementValueGetter().ToString() : elementStringValue; if(xmlCharType.IsOnlyWhitespace(textValue)) { break; } ArrayList names = context.ElementDecl.ContentValidator.ExpectedParticles(context, false, schemaSet); if (names == null || names.Count == 0) { SendValidationEvent(Res.Sch_InvalidTextInElement, BuildElementName(context.LocalName, context.Namespace)); } else { Debug.Assert(names.Count > 0); SendValidationEvent(Res.Sch_InvalidTextInElementExpecting, new string[] { BuildElementName(context.LocalName, context.Namespace), PrintExpectedElements(names, true) }); } break; case XmlSchemaContentType.Mixed: if (context.ElementDecl.DefaultValueTyped != null) { if (elementValueGetter != null) { SaveTextValue(elementValueGetter()); } else { SaveTextValue(elementStringValue); } } break; } } }
private void Init() { this.validationState = ValidatingReaderState.Init; this.defaultAttributes = new ArrayList(); this.currentAttrIndex = -1; this.attributePSVINodes = new AttributePSVIInfo[8]; this.valueGetter = new XmlValueGetter(this.GetStringValue); TypeOfString = typeof(string); this.xmlSchemaInfo = new XmlSchemaInfo(); this.NsXmlNs = this.coreReaderNameTable.Add("http://www.w3.org/2000/xmlns/"); this.NsXs = this.coreReaderNameTable.Add("http://www.w3.org/2001/XMLSchema"); this.NsXsi = this.coreReaderNameTable.Add("http://www.w3.org/2001/XMLSchema-instance"); this.XsiType = this.coreReaderNameTable.Add("type"); this.XsiNil = this.coreReaderNameTable.Add("nil"); this.XsiSchemaLocation = this.coreReaderNameTable.Add("schemaLocation"); this.XsiNoNamespaceSchemaLocation = this.coreReaderNameTable.Add("noNamespaceSchemaLocation"); this.XsdSchema = this.coreReaderNameTable.Add("schema"); }
private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo) { if (lName == null) { throw new ArgumentNullException("localName"); } if (ns == null) { throw new ArgumentNullException("namespaceUri"); } ValidatorState toState = (this.validationStack.Length > 1) ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute; this.CheckStateTransition(toState, MethodNames[(int) toState]); object typedValue = null; this.attrValid = true; XmlSchemaValidity notKnown = XmlSchemaValidity.NotKnown; XmlSchemaAttribute schemaAttribute = null; XmlSchemaSimpleType xmlType = null; ns = this.nameTable.Add(ns); if (Ref.Equal(ns, this.NsXmlNs)) { return null; } SchemaAttDef def = null; SchemaElementDecl elementDecl = this.context.ElementDecl; XmlQualifiedName key = new XmlQualifiedName(lName, ns); if (this.attPresence[key] != null) { this.SendValidationEvent("Sch_DuplicateAttribute", key.ToString()); if (schemaInfo != null) { schemaInfo.Clear(); } return null; } if (Ref.Equal(ns, this.NsXsi)) { lName = this.nameTable.Add(lName); if ((Ref.Equal(lName, this.xsiTypeString) || Ref.Equal(lName, this.xsiNilString)) || (Ref.Equal(lName, this.xsiSchemaLocationString) || Ref.Equal(lName, this.xsiNoNamespaceSchemaLocationString))) { this.attPresence.Add(key, SchemaAttDef.Empty); } else { this.attrValid = false; this.SendValidationEvent("Sch_NotXsiAttribute", key.ToString()); } } else { AttributeMatchState state2; object obj4; XmlSchemaObject partialValidationType = (this.currentState == ValidatorState.TopLevelAttribute) ? this.partialValidationType : null; def = this.compiledSchemaInfo.GetAttributeXsd(elementDecl, key, partialValidationType, out state2); switch (state2) { case AttributeMatchState.AttributeFound: break; case AttributeMatchState.AnyIdAttributeFound: if (this.wildID != null) { this.SendValidationEvent("Sch_MoreThanOneWildId", string.Empty); } else { this.wildID = def; XmlSchemaComplexType schemaType = elementDecl.SchemaType as XmlSchemaComplexType; if (!schemaType.ContainsIdAttribute(false)) { break; } this.SendValidationEvent("Sch_AttrUseAndWildId", string.Empty); } goto Label_0409; case AttributeMatchState.UndeclaredElementAndAttribute: def = this.CheckIsXmlAttribute(key); if (def != null) { break; } if (((elementDecl != null) || (this.processContents != XmlSchemaContentProcessing.Strict)) || ((key.Namespace.Length == 0) || !this.compiledSchemaInfo.Contains(key.Namespace))) { if (this.processContents != XmlSchemaContentProcessing.Skip) { this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning); } } else { this.attrValid = false; this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString()); } goto Label_0409; case AttributeMatchState.UndeclaredAttribute: def = this.CheckIsXmlAttribute(key); if (def != null) { break; } this.attrValid = false; this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString()); goto Label_0409; case AttributeMatchState.AnyAttributeLax: this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning); goto Label_0409; case AttributeMatchState.ProhibitedAnyAttribute: def = this.CheckIsXmlAttribute(key); if (def != null) { break; } this.attrValid = false; this.SendValidationEvent("Sch_ProhibitedAttribute", key.ToString()); goto Label_0409; case AttributeMatchState.ProhibitedAttribute: this.attrValid = false; this.SendValidationEvent("Sch_ProhibitedAttribute", key.ToString()); goto Label_0409; case AttributeMatchState.AttributeNameMismatch: this.attrValid = false; this.SendValidationEvent("Sch_SchemaAttributeNameMismatch", new string[] { key.ToString(), ((XmlSchemaAttribute) partialValidationType).QualifiedName.ToString() }); goto Label_0409; case AttributeMatchState.ValidateAttributeInvalidCall: this.currentState = ValidatorState.Start; this.attrValid = false; this.SendValidationEvent("Sch_ValidateAttributeInvalidCall", string.Empty); goto Label_0409; default: goto Label_0409; } schemaAttribute = def.SchemaAttribute; if (elementDecl != null) { this.attPresence.Add(key, def); } if (attributeValueGetter != null) { obj4 = attributeValueGetter(); } else { obj4 = attributeStringValue; } typedValue = this.CheckAttributeValue(obj4, def); XmlSchemaDatatype dtype = def.Datatype; if ((dtype.Variety == XmlSchemaDatatypeVariety.Union) && (typedValue != null)) { XsdSimpleValue value2 = typedValue as XsdSimpleValue; xmlType = value2.XmlType; dtype = value2.XmlType.Datatype; typedValue = value2.TypedValue; } this.CheckTokenizedTypes(dtype, typedValue, true); if (this.HasIdentityConstraints) { this.AttributeIdentityConstraints(key.Name, key.Namespace, typedValue, obj4.ToString(), dtype); } } Label_0409: if (!this.attrValid) { notKnown = XmlSchemaValidity.Invalid; } else if (def != null) { notKnown = XmlSchemaValidity.Valid; } if (schemaInfo != null) { schemaInfo.SchemaAttribute = schemaAttribute; schemaInfo.SchemaType = (schemaAttribute == null) ? null : schemaAttribute.AttributeSchemaType; schemaInfo.MemberType = xmlType; schemaInfo.IsDefault = false; schemaInfo.Validity = notKnown; } if (this.ProcessSchemaHints && (this.validatedNamespaces[ns] == null)) { this.validatedNamespaces.Add(ns, ns); } return typedValue; }
public void ValidateWhitespace(XmlValueGetter elementValue) { if (elementValue == null) { throw new ArgumentNullException("elementValue"); } this.ValidateWhitespace(null, elementValue); }
private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo) { if (lName == null) { throw new ArgumentNullException("localName"); } if (ns == null) { throw new ArgumentNullException("namespaceUri"); } ValidatorState toState = validationStack.Length > 1 ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute; CheckStateTransition(toState, MethodNames[(int)toState]); object typedVal = null; attrValid = true; XmlSchemaValidity localValidity = XmlSchemaValidity.NotKnown; XmlSchemaAttribute localAttribute = null; XmlSchemaSimpleType localMemberType = null; ns = nameTable.Add(ns); if(Ref.Equal(ns,NsXmlNs)) { return null; } SchemaAttDef attributeDef = null; SchemaElementDecl currentElementDecl = context.ElementDecl; XmlQualifiedName attQName = new XmlQualifiedName(lName, ns); if (attPresence[attQName] != null) { //this attribute already checked as it is duplicate; SendValidationEvent(Res.Sch_DuplicateAttribute, attQName.ToString()); if (schemaInfo != null) { schemaInfo.Clear(); } return null; } if (!Ref.Equal(ns,NsXsi)) { // XmlSchemaObject pvtAttribute = currentState == ValidatorState.TopLevelAttribute ? partialValidationType : null; AttributeMatchState attributeMatchState; attributeDef = compiledSchemaInfo.GetAttributeXsd(currentElementDecl, attQName, pvtAttribute, out attributeMatchState); switch (attributeMatchState) { case AttributeMatchState.UndeclaredElementAndAttribute: if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { //Try for xml attribute goto case AttributeMatchState.AttributeFound; } if (currentElementDecl == null && processContents == XmlSchemaContentProcessing.Strict && attQName.Namespace.Length != 0 && compiledSchemaInfo.Contains(attQName.Namespace) ) { attrValid = false; SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString()); } else if (processContents != XmlSchemaContentProcessing.Skip) { SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning); } break; case AttributeMatchState.UndeclaredAttribute: if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { goto case AttributeMatchState.AttributeFound; } else { attrValid = false; SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString()); } break; case AttributeMatchState.ProhibitedAnyAttribute: if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { goto case AttributeMatchState.AttributeFound; } else { attrValid = false; SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString()); } break; case AttributeMatchState.ProhibitedAttribute: attrValid = false; SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString()); break; case AttributeMatchState.AttributeNameMismatch: attrValid = false; SendValidationEvent(Res.Sch_SchemaAttributeNameMismatch, new string[] { attQName.ToString(), ((XmlSchemaAttribute)pvtAttribute).QualifiedName.ToString()}); break; case AttributeMatchState.ValidateAttributeInvalidCall: Debug.Assert(currentState == ValidatorState.TopLevelAttribute); //Re-set state back to start on error with partial validation type currentState = ValidatorState.Start; attrValid = false; SendValidationEvent(Res.Sch_ValidateAttributeInvalidCall, string.Empty); break; case AttributeMatchState.AnyIdAttributeFound: if (wildID == null) { wildID = attributeDef; Debug.Assert(currentElementDecl != null); XmlSchemaComplexType ct = currentElementDecl.SchemaType as XmlSchemaComplexType; Debug.Assert(ct != null); if (ct.ContainsIdAttribute(false)) { SendValidationEvent(Res.Sch_AttrUseAndWildId, string.Empty); } else { goto case AttributeMatchState.AttributeFound; } } else { //More than one attribute per element cannot match wildcard if both their types are derived from ID SendValidationEvent(Res.Sch_MoreThanOneWildId, string.Empty); } break; case AttributeMatchState.AttributeFound: Debug.Assert(attributeDef != null); localAttribute = attributeDef.SchemaAttribute; if (currentElementDecl != null) { //Have to add to hashtable to check whether to add default attributes attPresence.Add(attQName, attributeDef); } object attValue; if (attributeValueGetter != null) { attValue = attributeValueGetter(); } else { attValue = attributeStringValue; } typedVal = CheckAttributeValue(attValue, attributeDef); XmlSchemaDatatype datatype = attributeDef.Datatype; if (datatype.Variety == XmlSchemaDatatypeVariety.Union && typedVal != null) { //Unpack the union XsdSimpleValue simpleValue = typedVal as XsdSimpleValue; Debug.Assert(simpleValue != null); localMemberType = simpleValue.XmlType; datatype = simpleValue.XmlType.Datatype; typedVal = simpleValue.TypedValue; } CheckTokenizedTypes(datatype, typedVal, true); if (HasIdentityConstraints) { AttributeIdentityConstraints(attQName.Name, attQName.Namespace, typedVal, attValue.ToString(), datatype); } break; case AttributeMatchState.AnyAttributeLax: SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning); break; case AttributeMatchState.AnyAttributeSkip: break; default: break; } } else { //Attribute from xsi namespace lName = nameTable.Add(lName); if (Ref.Equal(lName, xsiTypeString) || Ref.Equal(lName, xsiNilString) || Ref.Equal(lName, xsiSchemaLocationString) || Ref.Equal(lName, xsiNoNamespaceSchemaLocationString)) { attPresence.Add(attQName, SchemaAttDef.Empty); } else { attrValid = false; SendValidationEvent(Res.Sch_NotXsiAttribute, attQName.ToString()); } } if (!attrValid) { localValidity = XmlSchemaValidity.Invalid; } else if (attributeDef != null) { localValidity = XmlSchemaValidity.Valid; } if (schemaInfo != null) { schemaInfo.SchemaAttribute = localAttribute; schemaInfo.SchemaType = localAttribute == null ? null : localAttribute.AttributeSchemaType; schemaInfo.MemberType = localMemberType; schemaInfo.IsDefault = false; schemaInfo.Validity = localValidity; } if (ProcessSchemaHints) { if (validatedNamespaces[ns] == null) { validatedNamespaces.Add(ns, ns); } } return typedVal; }
private void Init() { validationState = ValidatingReaderState.Init; defaultAttributes = new ArrayList(); currentAttrIndex = -1; attributePSVINodes = new AttributePSVIInfo[InitialAttributeCount]; valueGetter = new XmlValueGetter(GetStringValue); TypeOfString = typeof(System.String); xmlSchemaInfo = new XmlSchemaInfo(); //Add common strings to be compared to NameTable NsXmlNs = coreReaderNameTable.Add(XmlReservedNs.NsXmlNs); NsXs = coreReaderNameTable.Add(XmlReservedNs.NsXs); NsXsi = coreReaderNameTable.Add(XmlReservedNs.NsXsi); XsiType = coreReaderNameTable.Add("type"); XsiNil = coreReaderNameTable.Add("nil"); XsiSchemaLocation = coreReaderNameTable.Add("schemaLocation"); XsiNoNamespaceSchemaLocation = coreReaderNameTable.Add("noNamespaceSchemaLocation"); XsdSchema = coreReaderNameTable.Add("schema"); }
public void ValidateText(XmlValueGetter elementValue) { if (elementValue == null) { throw new ArgumentNullException("elementValue"); } ValidateText(null, elementValue); }