public ITransformFixtureInputSetup Message <TSchema>(Stream message, XmlSchemaContentProcessing contentProcessing) where TSchema : SchemaBase, new() { if (message == null) { throw new ArgumentNullException("message"); } var partCount = Messages.Count; var validatingXmlReader = XmlReader.Create( message, Be.Stateless.Xml.ValidatingXmlReaderSettings.Create( contentProcessing, (sender, args) => { throw new XmlSchemaValidationException( string.Format( "Transform's input message #{0} failed '{1}' schema validation for the following reason:{2}{3}: {4}{2}{2}The message's content is:{2}{5}{2}", partCount + 1, typeof(TSchema).Name, Environment.NewLine, args.Severity, args.Message, message.ReadToEnd()), args.Exception); }, new TSchema().CreateResolvedSchema())); Messages.Add(validatingXmlReader.AsStream()); return(this); }
private static void TraverseParticle(XmlSchemaParticle particle, ArrayList elementDeclsInContentModel) { if (particle is XmlSchemaElement) { XmlSchemaElement value = particle as XmlSchemaElement; elementDeclsInContentModel.Add(value); } else if (particle is XmlSchemaGroupBase) { XmlSchemaGroupBase xmlSchemaGroupBase = particle as XmlSchemaGroupBase; XmlSchemaObjectEnumerator enumerator = xmlSchemaGroupBase.Items.GetEnumerator(); try { while (enumerator.MoveNext()) { XmlSchemaParticle particle2 = (XmlSchemaParticle)enumerator.Current; RDLValidatingReader.TraverseParticle(particle2, elementDeclsInContentModel); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else if (particle is XmlSchemaAny) { XmlSchemaAny xmlSchemaAny = particle as XmlSchemaAny; RDLValidatingReader.m_processContent = xmlSchemaAny.ProcessContents; } }
/// <summary> /// Specifies a set of <see cref="XmlReaderSettings"/> features to support XSD validation on the <see cref="XmlReader"/> object created by the <see /// cref="XmlReader.Create(XmlReader,XmlReaderSettings)"/> method or one of its other overloads. /// </summary> /// <param name="contentProcessing"> /// The validation mode of the whole document and not only the any and anyAttribute element replacements. /// </param> /// <param name="schemas"> /// The XSD schemas against which to validate the XML content. /// </param> /// <returns> /// The <see cref="XmlReaderSettings"/> needed by an <see cref="XmlReader"/> instance needs to validate its content against the given XSD <paramref /// name="schemas"/>. /// </returns> /// <remarks> /// <para> /// If <paramref name="contentProcessing"/> is <see cref="XmlSchemaContentProcessing.Lax"/>, the <see cref="XmlReader"/> won't fail the validation if it cannot /// obtain a schema for any of the processed XML namespaces. /// </para> /// <para> /// If the <paramref name="contentProcessing"/> is <see cref="XmlSchemaContentProcessing.Strict"/>, the <see cref="XmlReader"/> will fail the validation if it /// cannot obtain a schema for any of the processed XML namespaces and, more specifically, any reported validation warning (<see /// cref="XmlSchemaValidationFlags.ReportValidationWarnings"/>) will converted into an <see cref="XmlSchemaValidationException"/>. /// </para> /// </remarks> /// <seealso cref="XmlSchemaContentProcessing"/> public static XmlReaderSettings Create(XmlSchemaContentProcessing contentProcessing, params XmlSchema[] schemas) { return(Create( contentProcessing, (o, args) => { throw new XmlSchemaValidationException(string.Format("{0}: {1}", args.Severity, args.Message), args.Exception); }, schemas)); }
public static XmlReader Create <T1, T2, T3>(XmlReader reader, XmlSchemaContentProcessing contentProcessing) where T1 : SchemaBase, new() where T2 : SchemaBase, new() where T3 : SchemaBase, new() { return(XmlReader.Create(reader, ValidatingXmlReaderSettings.Create <T1, T2, T3>(contentProcessing))); }
private object ValidateChildElement() { object particle = null; int errorCode = 0; if (context.NeedValidateChildren) { if (context.IsNill) { SendValidationEvent(Res.Sch_ContentInNill, elementName.ToString()); return(null); } particle = context.ElementDecl.ContentValidator.ValidateElement(elementName, context, out errorCode); if (particle == null) { processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip; if (errorCode == -2) //ContentModel all group error { SendValidationEvent(Res.Sch_AllElement, elementName.ToString()); } XmlSchemaValidator.ElementValidationError(elementName, context, EventHandler, reader, reader.BaseURI, PositionInfo.LineNumber, PositionInfo.LinePosition, null); } } return(particle); }
private void Init() { _nsManager = reader.NamespaceManager !; if (_nsManager == null) { _nsManager = new XmlNamespaceManager(NameTable); _bManageNamespaces = true; } _validationStack = new HWStack(STACK_INCREMENT); textValue = new StringBuilder(); _attPresence = new Hashtable(); schemaInfo = new SchemaInfo(); checkDatatype = false; _processContents = XmlSchemaContentProcessing.Strict; Push(XmlQualifiedName.Empty); //Add common strings to be compared to NameTable _nsXmlNs = NameTable.Add(XmlReservedNs.NsXmlNs); _nsXs = NameTable.Add(XmlReservedNs.NsXs); _nsXsi = NameTable.Add(XmlReservedNs.NsXsi); _xsiType = NameTable.Add("type"); _xsiNil = NameTable.Add("nil"); _xsiSchemaLocation = NameTable.Add("schemaLocation"); _xsiNoNamespaceSchemaLocation = NameTable.Add("noNamespaceSchemaLocation"); _xsdSchema = NameTable.Add("schema"); }
private object ValidateChildElement() { object obj2 = null; int errorCode = 0; if (base.context.NeedValidateChildren) { if (base.context.IsNill) { base.SendValidationEvent("Sch_ContentInNill", base.elementName.ToString()); return(null); } obj2 = base.context.ElementDecl.ContentValidator.ValidateElement(base.elementName, base.context, out errorCode); if (obj2 != null) { return(obj2); } this.processContents = base.context.ProcessContents = XmlSchemaContentProcessing.Skip; if (errorCode == -2) { base.SendValidationEvent("Sch_AllElement", base.elementName.ToString()); } XmlSchemaValidator.ElementValidationError(base.elementName, base.context, base.EventHandler, base.reader, base.reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition, null); } return(obj2); }
/// <summary> /// Loads and validates an XML file against the <typeparamref name="T"/> BizTalk Server schema. /// </summary> /// <param name="filepath"> /// The path of the XML file to load and validate. /// </param> /// <param name="contentProcessing"> /// Validation mode. /// </param> /// <returns> /// An <see cref="XmlDocument"/> that has loaded and validated the content of the XML file. /// </returns> protected XmlDocument ValidateInstanceDocument(string filepath, XmlSchemaContentProcessing contentProcessing) { using (var reader = XmlReader.Create(filepath)) { return(ValidateInstanceDocument(reader, contentProcessing)); } }
public static XmlReader Create <T1, T2, T3>(TextReader input, XmlSchemaContentProcessing contentProcessing = XmlSchemaContentProcessing.Strict) where T1 : XmlSchema, new() where T2 : XmlSchema, new() where T3 : XmlSchema, new() { return(XmlReader.Create(input, ValidatingXmlReaderSettings.Create <T1, T2, T3>(contentProcessing))); }
private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents) { XmlSchemaComplexType type = new XmlSchemaComplexType(); type.SetQualifiedName(DatatypeImplementation.QnAnyType); XmlSchemaAny item = new XmlSchemaAny { MinOccurs = 0M, MaxOccurs = 79228162514264337593543950335M, ProcessContents = processContents }; item.BuildNamespaceList(null); XmlSchemaSequence sequence = new XmlSchemaSequence(); sequence.Items.Add(item); type.SetContentTypeParticle(sequence); type.SetContentType(XmlSchemaContentType.Mixed); type.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl(); type.ElementDecl.SchemaType = type; ParticleContentValidator validator = new ParticleContentValidator(XmlSchemaContentType.Mixed); validator.Start(); validator.OpenGroup(); validator.AddNamespaceList(item.NamespaceList, item); validator.AddStar(); validator.CloseGroup(); ContentValidator validator2 = validator.Finish(true); type.ElementDecl.ContentValidator = validator2; XmlSchemaAnyAttribute attribute = new XmlSchemaAnyAttribute { ProcessContents = processContents }; attribute.BuildNamespaceList(null); type.SetAttributeWildcard(attribute); type.ElementDecl.AnyAttribute = attribute; return type; }
private void Init() { _nsManager = reader.NamespaceManager; if (_nsManager == null) { _nsManager = new XmlNamespaceManager(NameTable); _bManageNamespaces = true; } _validationStack = new HWStack(STACK_INCREMENT); textValue = new StringBuilder(); _attPresence = new Hashtable(); schemaInfo = new SchemaInfo(); checkDatatype = false; _processContents = XmlSchemaContentProcessing.Strict; Push(XmlQualifiedName.Empty); //Add common strings to be compared to NameTable _nsXmlNs = NameTable.Add(XmlReservedNs.NsXmlNs); _nsXs = NameTable.Add(XmlReservedNs.NsXs); _nsXsi = NameTable.Add(XmlReservedNs.NsXsi); _xsiType = NameTable.Add("type"); _xsiNil = NameTable.Add("nil"); _xsiSchemaLocation = NameTable.Add("schemaLocation"); _xsiNoNamespaceSchemaLocation = NameTable.Add("noNamespaceSchemaLocation"); _xsdSchema = NameTable.Add("schema"); }
public static XmlReaderSettings Create <T1, T2, T3>(XmlSchemaContentProcessing contentProcessing = XmlSchemaContentProcessing.Strict) where T1 : XmlSchema, new() where T2 : XmlSchema, new() where T3 : XmlSchema, new() { return(Create(contentProcessing, new T1(), new T2(), new T3())); }
/// <summary> /// Validates an <see cref="XmlDocument"/> against the <typeparamref name="T"/> BizTalk Server schema. /// </summary> /// <param name="document"> /// The <see cref="XmlDocument"/> to validate. /// </param> /// <param name="contentProcessing"> /// Validation mode. /// </param> /// <returns> /// An <see cref="XmlDocument"/> that has loaded and validated the content of the input <see cref="XmlDocument"/>. /// </returns> protected XmlDocument ValidateInstanceDocument(XmlDocument document, XmlSchemaContentProcessing contentProcessing) { using (var reader = new XmlNodeReader(document)) { return(ValidateInstanceDocument(reader, contentProcessing)); } }
public static XmlReaderSettings Create(XmlSchemaContentProcessing contentProcessing, ValidationEventHandler validationEventHandler, params XmlSchema[] schemas) { if (validationEventHandler == null) { throw new ArgumentNullException(nameof(validationEventHandler)); } var readerSettings = new XmlReaderSettings { XmlResolver = null }; if (contentProcessing != XmlSchemaContentProcessing.None) { schemas.ForEach(s => readerSettings.Schemas.Add(s)); readerSettings.ValidationEventHandler += (o, args) => { if (args.Exception != null && contentProcessing != XmlSchemaContentProcessing.Skip) { validationEventHandler(o, args); } }; if (contentProcessing == XmlSchemaContentProcessing.Strict) { readerSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; } readerSettings.ValidationType = ValidationType.Schema; } return(readerSettings); }
public static XmlReaderSettings Create(XmlSchemaContentProcessing contentProcessing, params XmlSchema[] schemas) { return(Create( contentProcessing, (_, args) => throw new XmlSchemaValidationException($"{args.Severity}: {args.Message}", args.Exception), schemas)); }
/// <summary> /// Validates an <see cref="Stream"/> against the <typeparamref name="T"/> BizTalk Server schema. /// </summary> /// <param name="stream"> /// The <see cref="Stream"/> to validate. /// </param> /// <param name="contentProcessing"> /// Validation mode. /// </param> /// <returns> /// An <see cref="XmlDocument"/> that has loaded and validated the content of the XML <see cref="Stream"/>. /// </returns> protected XmlDocument ValidateInstanceDocument(System.IO.Stream stream, XmlSchemaContentProcessing contentProcessing) { using (var reader = XmlReader.Create(stream)) { return(ValidateInstanceDocument(reader, contentProcessing)); } }
public static XmlReaderSettings Create <T1, T2, T3>(XmlSchemaContentProcessing contentProcessing) where T1 : SchemaBase, new() where T2 : SchemaBase, new() where T3 : SchemaBase, new() { return(ValidatingXmlReaderSettingsBase.Create(contentProcessing, new T1().CreateResolvedSchema(), new T2().CreateResolvedSchema(), new T3().CreateResolvedSchema())); }
public static XmlReader Create <T1, T2, T3, T4>(XmlReader reader, XmlSchemaContentProcessing contentProcessing = XmlSchemaContentProcessing.Strict) where T1 : XmlSchema, new() where T2 : XmlSchema, new() where T3 : XmlSchema, new() where T4 : XmlSchema, new() { return(XmlReader.Create(reader, ValidatingXmlReaderSettings.Create <T1, T2, T3, T4>(contentProcessing))); }
public static XmlReader Create <T1, T2, T3, T4>(Stream input, XmlSchemaContentProcessing contentProcessing = XmlSchemaContentProcessing.Strict) where T1 : SchemaBase, new() where T2 : SchemaBase, new() where T3 : SchemaBase, new() where T4 : SchemaBase, new() { return(XmlReader.Create(input, ValidatingXmlReaderSettings.Create <T1, T2, T3, T4>(contentProcessing))); }
/// <summary> /// Initializes a new instance of the <see cref="XmlMessage{TSchemaProvider}"/> class that will validate its XML /// representation. /// </summary> /// <param name="schemaContentProcessing"> /// The <see cref="XmlSchemaContentProcessing"/>, or validation strictness, that will be applied when validating the XML /// representation. /// </param> /// <seealso cref="ValidatingXmlReaderSettings.Create(XmlSchemaContentProcessing,XmlSchema[])"/> /// <seealso cref="XmlSchemaContentProcessing"/> protected XmlMessage(XmlSchemaContentProcessing schemaContentProcessing) { if (_validatingSchema == null) { Interlocked.CompareExchange(ref _validatingSchema, new TSchemaProvider().Schema, null); } _schemaContentProcessing = schemaContentProcessing; }
/// <summary> /// Validates an <see cref="XmlDocument"/> against the <typeparamref name="T"/> and <typeparamref name="T2"/> BizTalk /// Server schemas. /// </summary> /// <typeparam name="T2"> /// A supplementary type of the BizTalk Server schema to validate against. /// </typeparam> /// <param name="document"> /// The <see cref="XmlDocument"/> to validate. /// </param> /// <param name="contentProcessing"> /// Validation mode. /// </param> /// <returns> /// An <see cref="XmlDocument"/> that has loaded and validated the content of the input <see cref="XmlDocument"/>. /// </returns> protected XmlDocument ValidateInstanceDocument <T2>(XmlDocument document, XmlSchemaContentProcessing contentProcessing) where T2 : SchemaBase, new() { using (var reader = new XmlNodeReader(document)) { return(ValidateInstanceDocument <T2>(reader, contentProcessing)); } }
/// <summary> /// Loads and validates an XML file against the <typeparamref name="T"/> and <typeparamref name="T2"/> BizTalk Server /// schemas. /// </summary> /// <typeparam name="T2"> /// A supplementary type of the BizTalk Server schema to validate against. /// </typeparam> /// <param name="filepath"> /// The path of the XML file to load and validate. /// </param> /// <param name="contentProcessing"> /// Validation mode. /// </param> /// <returns> /// An <see cref="XmlDocument"/> that has loaded and validated the content of the XML file. /// </returns> protected XmlDocument ValidateInstanceDocument <T2>(string filepath, XmlSchemaContentProcessing contentProcessing) where T2 : SchemaBase, new() { using (var reader = XmlReader.Create(filepath)) { return(ValidateInstanceDocument <T2>(reader, contentProcessing)); } }
/// <summary> /// Validates an <see cref="Stream"/> against the <typeparamref name="T"/>, <typeparamref name="T2"/> and /// <typeparamref name="T3"/> BizTalk Server schemas. /// </summary> /// <typeparam name="T2"> /// A supplementary type of the BizTalk Server schema to validate against. /// </typeparam> /// <typeparam name="T3"> /// A supplementary type of the BizTalk Server schema to validate against. /// </typeparam> /// <param name="stream"> /// The <see cref="Stream"/> to validate. /// </param> /// <param name="contentProcessing"> /// Validation mode. /// </param> /// <returns> /// An <see cref="XmlDocument"/> that has loaded and validated the content of the XML <see cref="Stream"/>. /// </returns> protected XmlDocument ValidateInstanceDocument <T2, T3>(Stream stream, XmlSchemaContentProcessing contentProcessing) where T2 : SchemaBase, new() where T3 : SchemaBase, new() { using (var reader = XmlReader.Create(stream)) { return(ValidateInstanceDocument <T2, T3>(reader, contentProcessing)); } }
/// <summary> /// Validates an <see cref="XmlReader"/> against the <typeparamref name="T"/> BizTalk Server schema. /// </summary> /// <param name="reader"> /// The <see cref="XmlReader"/> to validate. /// </param> /// <param name="contentProcessing"> /// Validation mode. /// </param> /// <returns> /// An <see cref="XmlDocument"/> that has loaded and validated the content of the <see cref="XmlReader"/>. /// </returns> protected XmlDocument ValidateInstanceDocument(XmlReader reader, XmlSchemaContentProcessing contentProcessing) { using (var validatingReader = ValidatingXmlReader.Create <T>(reader, contentProcessing)) { var document = new XmlDocument(); document.Load(validatingReader); return(document); } }
/// <summary> /// Validates an <see cref="XmlReader"/> against the <typeparamref name="T"/> and <typeparamref name="T2"/> /// BizTalk Server schemas. /// </summary> /// <typeparam name="T2"> /// A supplementary type of the BizTalk Server schema to validate against. /// </typeparam> /// <param name="reader"> /// The <see cref="XmlReader"/> to validate. /// </param> /// <param name="contentProcessing"> /// Validation mode. /// </param> /// <returns> /// An <see cref="XmlDocument"/> that has loaded and validated the content of the <see cref="XmlReader"/>. /// </returns> protected XmlDocument ValidateInstanceDocument <T2>(XmlReader reader, XmlSchemaContentProcessing contentProcessing) where T2 : SchemaBase, new() { using (var validatingReader = ValidatingXmlReader.Create <T, T2>(reader, contentProcessing)) { var xdoc = new XmlDocument(); xdoc.Load(validatingReader); return(xdoc); } }
private void OnSetProcessContents() { XmlSchemaContentProcessing processContents = (XmlSchemaContentProcessing)_processContents; if (_wildcard is XmlSchemaAny xmlAny) xmlAny.ProcessContents = processContents; else if (_wildcard is XmlSchemaAnyAttribute xmlAnyAttribute) xmlAnyAttribute.ProcessContents = processContents; }
public static XmlReaderSettings Create <T1, T2, T3, T4, T5, T6, T7>(XmlSchemaContentProcessing contentProcessing = XmlSchemaContentProcessing.Strict) where T1 : XmlSchema, new() where T2 : XmlSchema, new() where T3 : XmlSchema, new() where T4 : XmlSchema, new() where T5 : XmlSchema, new() where T6 : XmlSchema, new() where T7 : XmlSchema, new() { return(Create(contentProcessing, new T1(), new T2(), new T3(), new T4(), new T5(), new T6(), new T7())); }
public static XmlReader Create <T1, T2, T3, T4, T5, T6, T7>(Stream input, XmlSchemaContentProcessing contentProcessing = XmlSchemaContentProcessing.Strict) where T1 : XmlSchema, new() where T2 : XmlSchema, new() where T3 : XmlSchema, new() where T4 : XmlSchema, new() where T5 : XmlSchema, new() where T6 : XmlSchema, new() where T7 : XmlSchema, new() { return(XmlReader.Create(input, ValidatingXmlReaderSettings.Create <T1, T2, T3, T4, T5, T6, T7>(contentProcessing))); }
private void Pop() { if (_validationStack.Length > 1) { _validationStack.Pop(); if (_startIDConstraint == _validationStack.Length) { _startIDConstraint = -1; } context = (ValidationState)_validationStack.Peek(); _processContents = context.ProcessContents; } }
private void Pop() { if (validationStack.Length > 1) { validationStack.Pop(); if (startIDConstraint == validationStack.Length) { startIDConstraint = -1; } context = (ValidationState)validationStack.Peek(); processContents = context.ProcessContents; } }
private void Pop() { if (this.validationStack.Length > 1) { this.validationStack.Pop(); if (this.startIDConstraint == this.validationStack.Length) { this.startIDConstraint = -1; } base.context = (ValidationState)this.validationStack.Peek(); this.processContents = base.context.ProcessContents; } }
private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents) { XmlSchemaComplexType localAnyType = new XmlSchemaComplexType(); localAnyType.SetQualifiedName(DatatypeImplementation.QnAnyType); XmlSchemaAny anyElement = new XmlSchemaAny(); anyElement.MinOccurs = decimal.Zero; anyElement.MaxOccurs = decimal.MaxValue; anyElement.ProcessContents = processContents; anyElement.BuildNamespaceList(null); XmlSchemaSequence seq = new XmlSchemaSequence(); seq.Items.Add(anyElement); localAnyType.SetContentTypeParticle(seq); localAnyType.SetContentType(XmlSchemaContentType.Mixed); localAnyType.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl(); localAnyType.ElementDecl.SchemaType = localAnyType; //Create contentValidator for Any ParticleContentValidator contentValidator = new ParticleContentValidator(XmlSchemaContentType.Mixed); contentValidator.Start(); contentValidator.OpenGroup(); contentValidator.AddNamespaceList(anyElement.NamespaceList, anyElement); contentValidator.AddStar(); contentValidator.CloseGroup(); ContentValidator anyContentValidator = contentValidator.Finish(true); localAnyType.ElementDecl.ContentValidator = anyContentValidator; XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute(); anyAttribute.ProcessContents = processContents; anyAttribute.BuildNamespaceList(null); localAnyType.SetAttributeWildcard(anyAttribute); localAnyType.ElementDecl.AnyAttribute = anyAttribute; return localAnyType; }
private void Pop() { if (validationStack.Length > 1) { validationStack.Pop(); if (startIDConstraint == validationStack.Length) { startIDConstraint = -1; } context = (ValidationState)validationStack.Peek(); processContents = context.ProcessContents; } }
public void AddWildcardTerminal(SchemaNamespaceList wildcard, XmlSchemaContentProcessing processContents, TypeNode elementType, Member mem) { AddTerminal(new WildcardNode(wildcard, processContents, elementType, mem)); canCompile = false; }
private void CheckXsdContent(ValidationState context, XmlQualifiedName qname, ref XmlSchemaContentProcessing processContents) { ContentNode cnode = context.CurrentNode; Object lookup = symbolTable[qname]; int terminals = symbols.Count; MinMaxNode ln; InternalNode inNode; MinMaxValues mm; int NodeMatched = context.HasNodeMatched; while (true) { switch (cnode.NodeType) { case ContentNode.Type.Any: case ContentNode.Type.Terminal: context.HasNodeMatched = (((InternalNode)cnode.ParentNode).LeftNode == cnode) ? 1 : 2; context.CurrentNode = cnode.ParentNode; context.HasMatched = (cnode.ParentNode == endNode); if (cnode.NodeType == ContentNode.Type.Any) { processContents = ((AnyNode)cnode).ProcessContents; } return; case ContentNode.Type.Sequence: inNode = (InternalNode)cnode; if (NodeMatched == 0) { if (Accepts(inNode.LeftNode, qname, terminals, lookup)) { cnode = inNode.LeftNode; break; } else if (inNode.LeftNode.Nullable()) { NodeMatched = 1; } else { goto error; } } if (NodeMatched == 1) { if (Accepts(inNode.RightNode, qname, terminals, lookup)) { NodeMatched = 0; cnode = inNode.RightNode; break; } else if (inNode.RightNode.Nullable()) { NodeMatched = 2; } else { goto error; } } if (NodeMatched == 2) { if (cnode.ParentNode != null) { if (((InternalNode)cnode.ParentNode).LeftNode == cnode) NodeMatched = 1; cnode = cnode.ParentNode; break; } else { goto error; } } break; case ContentNode.Type.Choice: inNode = (InternalNode)cnode; if (NodeMatched != 0) { NodeMatched = (((InternalNode)cnode.ParentNode).LeftNode == cnode) ? 1 : 2; cnode = cnode.ParentNode; } else if (Accepts(inNode.LeftNode, qname, terminals, lookup)) { NodeMatched = 0; cnode = inNode.LeftNode; } else if (Accepts(inNode.RightNode, qname, terminals, lookup)) { NodeMatched = 0; cnode = inNode.RightNode; } else { goto error; } break; case ContentNode.Type.Qmark: inNode = (InternalNode)cnode; if (NodeMatched != 0) { NodeMatched = (((InternalNode)cnode.ParentNode).LeftNode == cnode) ? 1 : 2; cnode = cnode.ParentNode; } else if (Accepts(inNode.LeftNode, qname, terminals, lookup)) { cnode = inNode.LeftNode; } else { goto error; } break; case ContentNode.Type.Star: case ContentNode.Type.Plus: inNode = (InternalNode)cnode; if (Accepts(inNode.LeftNode, qname, terminals, lookup)) { NodeMatched = 0; cnode = inNode.LeftNode; } else { NodeMatched = (((InternalNode)cnode.ParentNode).LeftNode == cnode) ? 1 : 2; cnode = cnode.ParentNode; } break; case ContentNode.Type.MinMax: inNode = (InternalNode)cnode; ln = (MinMaxNode)cnode; mm = null; if (context.MinMaxValues != null) mm = (MinMaxValues)context.MinMaxValues[ln]; else context.MinMaxValues = new Hashtable(); if (mm == null) { // new minmaxnode and add it to minmaxnodes hashtable mm = new MinMaxValues(ln.Min, ln.Max); context.MinMaxValues.Add(ln, mm); } if (mm.Max == 0) { NodeMatched = (((InternalNode)cnode.ParentNode).LeftNode == cnode) ? 1 : 2; cnode = cnode.ParentNode; mm.Max = ln.Max; mm.Min = ln.Min; } else if (Accepts(inNode.LeftNode, qname, terminals, lookup)) { mm.Max -= 1; mm.Min -= 1; NodeMatched = 0; cnode = inNode.LeftNode; } else { if (mm.Min > 0) goto error; NodeMatched = (((InternalNode)cnode.ParentNode).LeftNode == cnode) ? 1 : 2; cnode = cnode.ParentNode; mm.Max = ln.Max; mm.Min = ln.Min; } break; } // switch } // while (true) error: context.NeedValidateChildren = false; ArrayList v = ExpectedXsdElements(context.CurrentNode, NodeMatched); if (v == null) { throw new XmlSchemaException(Res.Sch_InvalidContent, context.Name.ToString()); } else { throw new XmlSchemaException(Res.Sch_InvalidContentExpecting, new string[] { context.Name.ToString(), v.ToString() }); } }
internal void SetProcessContents (XmlSchemaContentProcessing value) { this.processContents = value; }
private void ThrowDeclNotFoundWarningOrError(bool declFound) { if (declFound) { this.processContents = this.context.ProcessContents = XmlSchemaContentProcessing.Skip; this.context.NeedValidateChildren = false; } else if (this.HasSchema && (this.processContents == XmlSchemaContentProcessing.Strict)) { this.processContents = this.context.ProcessContents = XmlSchemaContentProcessing.Skip; this.context.NeedValidateChildren = false; this.SendValidationEvent("Sch_UndeclaredElement", QNameString(this.context.LocalName, this.context.Namespace)); } else { this.SendValidationEvent("Sch_NoElementSchemaFound", QNameString(this.context.LocalName, this.context.Namespace), XmlSeverityType.Warning); } }
private SchemaElementDecl FastGetElementDecl(XmlQualifiedName elementName, object particle) { SchemaElementDecl elementDecl = null; if (particle != null) { XmlSchemaElement element = particle as XmlSchemaElement; if (element != null) { elementDecl = element.ElementDecl; } else { XmlSchemaAny any = (XmlSchemaAny)particle; processContents = any.ProcessContentsCorrect; } } if (elementDecl == null && processContents != XmlSchemaContentProcessing.Skip) { if (isRoot && partialValidationType != null) { if (partialValidationType is XmlSchemaElement) { XmlSchemaElement element = (XmlSchemaElement)partialValidationType; if (elementName.Equals(element.QualifiedName)) { elementDecl = element.ElementDecl; } else { SendValidationEvent(Res.Sch_SchemaElementNameMismatch, elementName.ToString(), element.QualifiedName.ToString()); } } else if (partialValidationType is XmlSchemaType) { //Element name is wildcard XmlSchemaType type = (XmlSchemaType)partialValidationType; elementDecl = type.ElementDecl; } else { //its XmlSchemaAttribute Debug.Assert(partialValidationType is XmlSchemaAttribute); SendValidationEvent(Res.Sch_ValidateElementInvalidCall, string.Empty); } } else { elementDecl = compiledSchemaInfo.GetElementDecl(elementName); } } return elementDecl; }
private string Write38_XmlSchemaContentProcessing(XmlSchemaContentProcessing v) { switch (v) { case XmlSchemaContentProcessing.Skip: return "skip"; case XmlSchemaContentProcessing.Lax: return "lax"; case XmlSchemaContentProcessing.Strict: return "strict"; } long num = (long) v; throw base.CreateInvalidEnumValueException(num.ToString(CultureInfo.InvariantCulture), "System.Xml.Schema.XmlSchemaContentProcessing"); }
private SchemaElementDecl FastGetElementDecl(object particle) { if (particle != null) { XmlSchemaElement element = particle as XmlSchemaElement; if (element != null) { return element.ElementDecl; } XmlSchemaAny any = (XmlSchemaAny) particle; this.processContents = any.ProcessContentsCorrect; } return null; }
private void Init() { this.nsManager = base.reader.NamespaceManager; if (this.nsManager == null) { this.nsManager = new XmlNamespaceManager(base.NameTable); this.bManageNamespaces = true; } this.validationStack = new HWStack(10); base.textValue = new StringBuilder(); this.attPresence = new Hashtable(); base.schemaInfo = new SchemaInfo(); base.checkDatatype = false; this.processContents = XmlSchemaContentProcessing.Strict; this.Push(XmlQualifiedName.Empty); this.NsXmlNs = base.NameTable.Add("http://www.w3.org/2000/xmlns/"); this.NsXs = base.NameTable.Add("http://www.w3.org/2001/XMLSchema"); this.NsXsi = base.NameTable.Add("http://www.w3.org/2001/XMLSchema-instance"); this.XsiType = base.NameTable.Add("type"); this.XsiNil = base.NameTable.Add("nil"); this.XsiSchemaLocation = base.NameTable.Add("schemaLocation"); this.XsiNoNamespaceSchemaLocation = base.NameTable.Add("noNamespaceSchemaLocation"); this.XsdSchema = base.NameTable.Add("schema"); }
private SchemaElementDecl FastGetElementDecl(object particle) { SchemaElementDecl elementDecl = null; if (particle != null) { XmlSchemaElement element = particle as XmlSchemaElement; if (element != null) { elementDecl = element.ElementDecl; } else { XmlSchemaAny any = (XmlSchemaAny)particle; _processContents = any.ProcessContentsCorrect; } } return elementDecl; }
private static XmlSchemaComplexType CreateAnyType(XmlSchemaContentProcessing processContents) { XmlSchemaComplexType type = new XmlSchemaComplexType(); type.SetQualifiedName(DatatypeImplementation.QnAnyType); XmlSchemaAny item = new XmlSchemaAny { MinOccurs = 0M, MaxOccurs = 79228162514264337593543950335M, ProcessContents = processContents }; item.BuildNamespaceList(null); XmlSchemaSequence sequence = new XmlSchemaSequence(); sequence.Items.Add(item); type.SetContentTypeParticle(sequence); type.SetContentType(XmlSchemaContentType.Mixed); type.ElementDecl = SchemaElementDecl.CreateAnyTypeElementDecl(); type.ElementDecl.SchemaType = type; ParticleContentValidator validator = new ParticleContentValidator(XmlSchemaContentType.Mixed); validator.Start(); validator.OpenGroup(); validator.AddNamespaceList(item.NamespaceList, item); validator.AddStar(); validator.CloseGroup(); ContentValidator validator2 = validator.Finish(true); type.ElementDecl.ContentValidator = validator2; XmlSchemaAnyAttribute attribute = new XmlSchemaAnyAttribute { ProcessContents = processContents }; attribute.BuildNamespaceList(null); type.SetAttributeWildcard(attribute); type.ElementDecl.AnyAttribute = attribute; return type; }
private SchemaElementDecl FastGetElementDecl(XmlQualifiedName elementName, object particle) { SchemaElementDecl elementDecl = null; if (particle != null) { XmlSchemaElement element = particle as XmlSchemaElement; if (element != null) { elementDecl = element.ElementDecl; } else { XmlSchemaAny any = (XmlSchemaAny) particle; this.processContents = any.ProcessContentsCorrect; } } if ((elementDecl != null) || (this.processContents == XmlSchemaContentProcessing.Skip)) { return elementDecl; } if (this.isRoot && (this.partialValidationType != null)) { if (this.partialValidationType is XmlSchemaElement) { XmlSchemaElement partialValidationType = (XmlSchemaElement) this.partialValidationType; if (elementName.Equals(partialValidationType.QualifiedName)) { return partialValidationType.ElementDecl; } this.SendValidationEvent("Sch_SchemaElementNameMismatch", elementName.ToString(), partialValidationType.QualifiedName.ToString()); return elementDecl; } if (this.partialValidationType is XmlSchemaType) { XmlSchemaType type = (XmlSchemaType) this.partialValidationType; return type.ElementDecl; } this.SendValidationEvent("Sch_ValidateElementInvalidCall", string.Empty); return elementDecl; } return this.compiledSchemaInfo.GetElementDecl(elementName); }
public XsdParticleStateManager () { table = new Hashtable (); processContents = XmlSchemaContentProcessing.Strict; // not Lax }
private string Write34_XmlSchemaContentProcessing(XmlSchemaContentProcessing v) { switch (v) { case XmlSchemaContentProcessing.Skip: return "skip"; case XmlSchemaContentProcessing.Lax: return "lax"; case XmlSchemaContentProcessing.Strict: return "strict"; } return null; }
private object ValidateElementContext(XmlQualifiedName elementName, out bool invalidElementInContext) { object particle = null; int errorCode = 0; XmlQualifiedName head; XmlSchemaElement headElement = null; invalidElementInContext = false; if (context.NeedValidateChildren) { if (context.IsNill) { SendValidationEvent(Res.Sch_ContentInNill, QNameString(context.LocalName, context.Namespace)); return null; } ContentValidator contentValidator = context.ElementDecl.ContentValidator; if (contentValidator.ContentType == XmlSchemaContentType.Mixed && context.ElementDecl.Presence == SchemaDeclBase.Use.Fixed) { //Mixed with default or fixed SendValidationEvent(Res.Sch_ElementInMixedWithFixed, QNameString(context.LocalName, context.Namespace)); return null; } head = elementName; bool substitution = false; while (true) { particle = context.ElementDecl.ContentValidator.ValidateElement(head, context, out errorCode); if (particle != null) { //Match found break; } if (errorCode == -2) { //ContentModel all group error SendValidationEvent(Res.Sch_AllElement, elementName.ToString()); invalidElementInContext = true; processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip; return null; } //Match not found; check for substitutionGroup substitution = true; headElement = GetSubstitutionGroupHead(head); if (headElement == null) { break; } else { head = headElement.QualifiedName; } } if (substitution) { XmlSchemaElement matchedElem = particle as XmlSchemaElement; if (matchedElem == null) { //It matched an xs:any in that position particle = null; } else if (matchedElem.RefName.IsEmpty) { //It is not element ref but a local element //If the head and matched particle are not hte same, then this is not substitutable, duped by a localElement with same QName SendValidationEvent(Res.Sch_InvalidElementSubstitution, BuildElementName(elementName), BuildElementName(matchedElem.QualifiedName)); invalidElementInContext = true; processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip; } else { //Correct substitution head found particle = compiledSchemaInfo.GetElement(elementName); //Re-assign correct particle context.NeedValidateChildren = true; //This will be reset to false once member match is not found } } if (particle == null) { ElementValidationError(elementName, context, eventHandler, nsResolver, sourceUriString, positionInfo.LineNumber, positionInfo.LinePosition, schemaSet); invalidElementInContext = true; processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip; } } return particle; }
private void Pop() { if (this.validationStack.Length > 1) { this.validationStack.Pop(); if (this.startIDConstraint == this.validationStack.Length) { this.startIDConstraint = -1; } base.context = (ValidationState) this.validationStack.Peek(); this.processContents = base.context.ProcessContents; } }
private void Pop() { Debug.Assert(validationStack.Length > 1); ValidationState previousContext = (ValidationState)validationStack.Pop(); if (startIDConstraint == validationStack.Length) { startIDConstraint = -1; } context = (ValidationState)validationStack.Peek(); if (previousContext.Validity == XmlSchemaValidity.Invalid) { //Should set current context's validity to that of what was popped now in case of Invalid context.Validity = XmlSchemaValidity.Invalid; } if (previousContext.ValidationSkipped) { context.ValidationSkipped = true; } processContents = context.ProcessContents; }
private object ValidateChildElement() { object obj2 = null; int errorCode = 0; if (base.context.NeedValidateChildren) { if (base.context.IsNill) { base.SendValidationEvent("Sch_ContentInNill", base.elementName.ToString()); return null; } obj2 = base.context.ElementDecl.ContentValidator.ValidateElement(base.elementName, base.context, out errorCode); if (obj2 != null) { return obj2; } this.processContents = base.context.ProcessContents = XmlSchemaContentProcessing.Skip; if (errorCode == -2) { base.SendValidationEvent("Sch_AllElement", base.elementName.ToString()); } XmlSchemaValidator.ElementValidationError(base.elementName, base.context, base.EventHandler, base.reader, base.reader.BaseURI, base.PositionInfo.LineNumber, base.PositionInfo.LinePosition, null); } return obj2; }
private void ThrowDeclNotFoundWarningOrError(bool declFound) { if (declFound) { //But invalid, so discontinue processing of children processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip; context.NeedValidateChildren = false; } else if (HasSchema && processContents == XmlSchemaContentProcessing.Strict) { //Error and skip validation for children processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip; context.NeedValidateChildren = false; SendValidationEvent(Res.Sch_UndeclaredElement, QNameString(context.LocalName, context.Namespace)); } else { SendValidationEvent(Res.Sch_NoElementSchemaFound, QNameString(context.LocalName, context.Namespace), XmlSeverityType.Warning); } }
private object ValidateChildElement() { object particle = null; int errorCode = 0; if (context.NeedValidateChildren) { if (context.IsNill) { SendValidationEvent(SR.Sch_ContentInNill, elementName.ToString()); return null; } particle = context.ElementDecl.ContentValidator.ValidateElement(elementName, context, out errorCode); if (particle == null) { _processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip; if (errorCode == -2) { //ContentModel all group error SendValidationEvent(SR.Sch_AllElement, elementName.ToString()); } XmlSchemaValidator.ElementValidationError(elementName, context, EventHandler, reader, reader.BaseURI, PositionInfo.LineNumber, PositionInfo.LinePosition, null); } } return particle; }
public ValidateExpr (XmlSchemaContentProcessing schemaMode, ExprSequence expr) { this.schemaMode = schemaMode; this.expr = expr; }
private void Pop() { validationStack.Pop(); if (this.startIDConstraint == this.validationStack.Length) { this.startIDConstraint = -1; } if (validationStack.Length > 0) { context = (ValidationState)validationStack[validationStack.Length - 1]; processContents = context.ProcessContents; } else { context = null; } }
private void Pop() { ValidationState state = (ValidationState) this.validationStack.Pop(); if (this.startIDConstraint == this.validationStack.Length) { this.startIDConstraint = -1; } this.context = (ValidationState) this.validationStack.Peek(); if (state.Validity == XmlSchemaValidity.Invalid) { this.context.Validity = XmlSchemaValidity.Invalid; } if (state.ValidationSkipped) { this.context.ValidationSkipped = true; } this.processContents = this.context.ProcessContents; }
internal void CheckContent(ValidationState context, XmlQualifiedName qname, ref XmlSchemaContentProcessing processContents) { #if DEBUG Debug.WriteLineIf(CompModSwitches.XmlSchema.TraceVerbose, String.Format("\t\t\tSchemaContentModel.CheckContent({0}) in \"{1}\"", "\"" + qname.ToString() + "\"", context.Name)); #endif XmlQualifiedName n = qname.IsEmpty ? (schemaNames == null ? XmlQualifiedName.Empty : schemaNames.QnPCData) : qname; Object lookup; if (context.IsNill) { throw new XmlSchemaException(Res.Sch_ContentInNill, context.Name.ToString()); } switch(contentType) { case CompiledContentModel.Type.Any: context.HasMatched = true; return; case CompiledContentModel.Type.Empty: goto error; case CompiledContentModel.Type.Text: if(qname.IsEmpty) return; else goto error; case CompiledContentModel.Type.Mixed: if (qname.IsEmpty) return; break; case CompiledContentModel.Type.ElementOnly: if (qname.IsEmpty) goto error; break; default: break; } if (IsAllElements) { lookup = symbolTable[n]; if (lookup != null) { int index = (int)lookup; if (context.AllElementsSet.Get(index)) { throw new XmlSchemaException(Res.Sch_AllElement, qname.Name); } else { context.AllElementsSet.Set(index); } } else { goto error; } return; } if (!IsCompiled) { CheckXsdContent(context, qname, ref processContents); return; } lookup = symbolTable[n]; if (lookup != null) { int sym = (int)lookup; if (sym != -1 && dtrans != null) { int state = ((int[])dtrans[context.State])[sym]; if (state != -1) { context.State = state; context.HasMatched = ((int[])dtrans[context.State])[symbols.Count] > 0; return; } } } if (IsOpen && context.HasMatched) { // XDR allows any well-formed contents after matched. return; } // // report error // context.NeedValidateChildren = false; error: ArrayList v = null; if (dtrans != null) { v = ExpectedElements(context.State, context.AllElementsSet); } if (v == null || v.Count == 0) { if (!(qname.IsEmpty)) { throw new XmlSchemaException(Res.Sch_InvalidElementContent, new string[] { context.Name.ToString(), n.ToString() }); } else { if (n.Name.Equals("#PCDATA")) { if(contentType == CompiledContentModel.Type.Empty) throw new XmlSchemaException(Res.Sch_InvalidTextWhiteSpace); else throw new XmlSchemaException(Res.Sch_InvalidTextInElement,context.Name.ToString()); } else { throw new XmlSchemaException(Res.Sch_InvalidContent, context.Name.ToString()); } } } else { StringBuilder builder = new StringBuilder(); for (int i = 0; i < v.Count; ++i) { builder.Append(v[i].ToString()); if (i+1 < v.Count) builder.Append(" "); } if (qname.IsEmpty) { if (n.Name.Equals("#PCDATA")) throw new XmlSchemaException(Res.Sch_InvalidTextInElementExpecting, new string[] { context.Name.ToString(), builder.ToString() } ); else throw new XmlSchemaException(Res.Sch_InvalidContentExpecting, new string[] { context.Name.ToString(), builder.ToString() } ); } else { throw new XmlSchemaException(Res.Sch_InvalidElementContentExpecting, new string[] { context.Name.ToString(), n.ToString(), builder.ToString() }); } } }
private object ValidateElementContext(XmlQualifiedName elementName, out bool invalidElementInContext) { object element = null; int errorCode = 0; XmlSchemaElement substitutionGroupHead = null; invalidElementInContext = false; if (!this.context.NeedValidateChildren) { return element; } if (this.context.IsNill) { this.SendValidationEvent("Sch_ContentInNill", QNameString(this.context.LocalName, this.context.Namespace)); return null; } if ((this.context.ElementDecl.ContentValidator.ContentType == XmlSchemaContentType.Mixed) && (this.context.ElementDecl.Presence == SchemaDeclBase.Use.Fixed)) { this.SendValidationEvent("Sch_ElementInMixedWithFixed", QNameString(this.context.LocalName, this.context.Namespace)); return null; } XmlQualifiedName qualifiedName = elementName; bool flag = false; Label_00AA: element = this.context.ElementDecl.ContentValidator.ValidateElement(qualifiedName, this.context, out errorCode); if (element == null) { if (errorCode == -2) { this.SendValidationEvent("Sch_AllElement", elementName.ToString()); invalidElementInContext = true; this.processContents = this.context.ProcessContents = XmlSchemaContentProcessing.Skip; return null; } flag = true; substitutionGroupHead = this.GetSubstitutionGroupHead(qualifiedName); if (substitutionGroupHead != null) { qualifiedName = substitutionGroupHead.QualifiedName; goto Label_00AA; } } if (flag) { XmlSchemaElement element2 = element as XmlSchemaElement; if (element2 == null) { element = null; } else if (element2.RefName.IsEmpty) { this.SendValidationEvent("Sch_InvalidElementSubstitution", BuildElementName(elementName), BuildElementName(element2.QualifiedName)); invalidElementInContext = true; this.processContents = this.context.ProcessContents = XmlSchemaContentProcessing.Skip; } else { element = this.compiledSchemaInfo.GetElement(elementName); this.context.NeedValidateChildren = true; } } if (element == null) { ElementValidationError(elementName, this.context, this.eventHandler, this.nsResolver, this.sourceUriString, this.positionInfo.LineNumber, this.positionInfo.LinePosition, this.schemaSet); invalidElementInContext = true; this.processContents = this.context.ProcessContents = XmlSchemaContentProcessing.Skip; } return element; }
public WildcardNode(SchemaNamespaceList wildcard, XmlSchemaContentProcessing processContents, TypeNode elementType, Member mem ): base(mem, elementType) { this.wildcard = wildcard; this.processContents = processContents; }
string Write34_XmlSchemaContentProcessing(XmlSchemaContentProcessing v) { string s = null; switch (v) { case XmlSchemaContentProcessing.@Skip:s = @"skip"; break; case XmlSchemaContentProcessing.@Lax:s = @"lax"; break; case XmlSchemaContentProcessing.@Strict:s = @"strict"; break; default: break; } return s; }
private void Pop() { if (_validationStack.Length > 1) { _validationStack.Pop(); if (_startIDConstraint == _validationStack.Length) { _startIDConstraint = -1; } context = (ValidationState)_validationStack.Peek(); _processContents = context.ProcessContents; } }