Inheritance: IXmlSchemaInfo
        public void WhitespaceInsideElement()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("ElementOnlyElement", "", info);
            val.ValidateEndOfAttributes(null);

            val.ValidateWhitespace(" \t\r\n");

            val.ValidateElement("child", "", info);
            val.ValidateEndOfAttributes(null);
            val.ValidateEndElement(info);

            val.ValidateWhitespace(" \t\r\n");

            val.ValidateEndElement(info);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);
            Assert.Equal(info.ContentType, XmlSchemaContentType.ElementOnly);

            return;
        }
        public void SanityTestForSimpleType_MultipleCallInOneContext(String param)
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_TEXT);
            CValidationEventHolder holder = new CValidationEventHolder();
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("PatternElement", "", info);
            val.ValidateEndOfAttributes(null);

            if (param == "single")
                val.ValidateText(StringGetter("foo123bar"));
            else
            {
                val.ValidateText(StringGetter("foo"));
                val.ValidateText(StringGetter("123"));
                val.ValidateText(StringGetter("bar"));
            }

            val.ValidateEndElement(info);
            val.EndValidation();

            Assert.True(!holder.IsCalledA);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);
            Assert.Equal(info.ContentType, XmlSchemaContentType.TextOnly);

            return;
        }
Exemple #3
0
        public void DefaultValueForXmlResolver_XmlUrlResolver()
        {
            XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable());

            manager.AddNamespace("t", "uri:tempuri");

            XmlSchemaValidator val = new XmlSchemaValidator(new NameTable(),
                                                            CreateSchemaSetFromXml("<root />"),
                                                            manager,
                                                            AllFlags);
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.XmlResolver = new XmlUrlResolver(); //Adding this as the default resolver is null and not XmlUrlResolver anymore

            val.Initialize();
            val.ValidateElement("foo", "", null, "t:type1", null, "uri:tempuri " + TestData + XSDFILE_TARGET_NAMESPACE, null);
            val.ValidateEndOfAttributes(null);
            val.ValidateElement("bar", "", null);
            val.ValidateEndOfAttributes(null);
            val.ValidateEndElement(null);
            val.ValidateEndElement(info);

            Assert.Equal(info.ContentType, XmlSchemaContentType.ElementOnly);
            Assert.True(info.SchemaType != null);

            return;
        }
Exemple #4
0
        public void PassNull_LocalName_NamespaceUri_Invalid_First_Second_Overload(String type, String overload)
        {
            XmlSchemaValidator val = CreateValidator(CreateSchemaSetFromXml("<root />"));
            string name = "root";
            string ns = "";
            XmlSchemaInfo info = new XmlSchemaInfo();

            if (type == "name")
                name = null;
            else
                ns = null;

            val.Initialize();
            try
            {
                if (overload == "first")
                    val.ValidateElement(name, ns, info);
                else
                    val.ValidateElement(name, ns, info, null, null, null, null);
            }
            catch (ArgumentNullException)
            {
                return;
            }

            Assert.True(false);
        }
        public void CallAtRootLevel_Without_With_PartialValidationSet(bool partialValidation)
        {
            XmlSchemaValidator val;
            XmlSchemaInfo info = new XmlSchemaInfo();
            XmlSchemaSet schemas = CreateSchemaSet("", "<?xml version=\"1.0\"?>\n" +
                                                       "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                       "    <xs:attribute name=\"attr1\" />\n" +
                                                       "    <xs:attribute name=\"attr2\" />\n" +
                                                       "</xs:schema>");
            schemas.Compile();
            val = CreateValidator(schemas);

            if (partialValidation)
            {
                val.Initialize(schemas.GlobalAttributes[new XmlQualifiedName("attr1")]);
                CheckExpectedAttributes(val.GetExpectedAttributes(), new XmlQualifiedName[] { new XmlQualifiedName("attr1") });
            }
            else
            {
                val.Initialize();
                CheckExpectedAttributes(val.GetExpectedAttributes(), new XmlQualifiedName[] { });
            }

            return;
        }
        public void CallForSequence_Between_After_ValidationAllSeqElements(String callOn)
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_PARTICLES);
            XmlSchemaInfo info = new XmlSchemaInfo();

            XmlQualifiedName[] names;

            val.Initialize();
            val.ValidateElement("SequenceElement", "", info);
            val.ValidateAttribute("attr1", "", StringGetter("foo"), info);
            val.ValidateAttribute("attr2", "", StringGetter("foo"), info);
            val.ValidateEndOfAttributes(null);

            val.ValidateElement("elem1", "", info);
            val.SkipToEndElement(info);

            if (callOn == "end")
            {
                val.ValidateElement("elem2", "", info);
                val.SkipToEndElement(info);

                names = new XmlQualifiedName[] { };
            }
            else
            {
                names = new XmlQualifiedName[] { new XmlQualifiedName("elem2") };
            }

            CheckExpectedElements(val.GetExpectedParticles(), names);

            return;
        }
        public void SetXmlNameTableTo_Empty_Full(String nameTableStatus)
        {
            XmlSchemaValidator val;
            ObservedNameTable nt = new ObservedNameTable();
            XmlSchemaInfo info = new XmlSchemaInfo();
            XmlSchemaSet sch = CreateSchemaSetFromXml("<root />");

            if (nameTableStatus == "full")
            {
                nt.Add("root");
                nt.Add("foo");
                nt.IsAddCalled = false;
                nt.IsGetCalled = false;
            }

            val = new XmlSchemaValidator(nt, sch, new XmlNamespaceManager(new NameTable()), AllFlags);
            Assert.NotEqual(val, null);

            val.Initialize();
            val.ValidateElement("root", "", info);

            Assert.True(nt.IsAddCalled);
            Assert.Equal(nt.IsGetCalled, false);

            return;
        }
        public void PassNullXmlSchemaInfo__Valid()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_ATTRIBUTE);
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("OneAttributeElement", "", null);
            val.ValidateAttribute("attr", "", StringGetter("foo"), null);

            return;
        }
Exemple #9
0
        private void ValidateAttribute(XAttribute a)
        {
            XmlSchemaInfo schemaInfo = this.addSchemaInfo ? new XmlSchemaInfo() : null;

            this.source = a;
            this.validator.ValidateAttribute(a.Name.LocalName, a.Name.NamespaceName, a.Value, schemaInfo);
            if (this.addSchemaInfo)
            {
                this.ReplaceSchemaInfo(a, schemaInfo);
            }
        }
        public void CallOnElementWith_Required_Optional_Default_Fixed_FixedRequired_AttributesAfterValidateElement(String attrType)
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_ATTRIBUTES);
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement(attrType + "AttributesElement", "", info);

            CheckExpectedAttributes(val.GetExpectedAttributes(), new XmlQualifiedName[] { new XmlQualifiedName("a1"), new XmlQualifiedName("a2") });

            return;
        }
        public void CallOnElementWithNoAttributesAfterValidateElement()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_ATTRIBUTES);
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("NoAttributesElement", "", info);

            CheckExpectedAttributes(val.GetExpectedAttributes(), new XmlQualifiedName[] { });

            return;
        }
        void ValidateAttribute(XAttribute a)
        {
            IXmlLineInfo  original = SaveLineInfo(a);
            XmlSchemaInfo si       = addSchemaInfo ? new XmlSchemaInfo() : null;

            source = a;
            validator.ValidateAttribute(a.Name.LocalName, a.Name.NamespaceName, a.Value, si);
            if (addSchemaInfo)
            {
                ReplaceSchemaInfo(a, si);
            }
            RestoreLineInfo(original);
        }
		public void XsdAnyToSkipAttributeValidation ()
		{
			// bug #358408
			XmlSchemaSet schemas = new XmlSchemaSet ();
			schemas.Add (null, "Test/XmlFiles/xsd/358408.xsd");
			XmlSchemaValidator v = new XmlSchemaValidator (
				new NameTable (),
				schemas,
				new XmlNamespaceManager (new NameTable ()),
				XmlSchemaValidationFlags.ProcessIdentityConstraints);
			v.Initialize ();
			v.ValidateWhitespace (" ");
			XmlSchemaInfo info = new XmlSchemaInfo ();
			ArrayList list = new ArrayList ();

			v.ValidateElement ("configuration", "", info, null, null, null, null);
			v.GetUnspecifiedDefaultAttributes (list);
			v.ValidateEndOfAttributes (info);

			v.ValidateWhitespace (" ");

			v.ValidateElement ("host", "", info, null, null, null, null);
			v.ValidateAttribute ("auto-start", "", "true", info);
			list.Clear ();
			v.GetUnspecifiedDefaultAttributes (list);
			v.ValidateEndOfAttributes (info);
			v.ValidateEndElement (null);//info);

			v.ValidateWhitespace (" ");

			v.ValidateElement ("service-managers", "", info, null, null, null, null);
			list.Clear ();
			v.GetUnspecifiedDefaultAttributes (list);
			v.ValidateEndOfAttributes (info);

			v.ValidateWhitespace (" ");

			v.ValidateElement ("service-manager", "", info, null, null, null, null);
			list.Clear ();
			v.GetUnspecifiedDefaultAttributes (list);
			v.ValidateEndOfAttributes (info);

			v.ValidateWhitespace (" ");

			v.ValidateElement ("foo", "", info, null, null, null, null);
			v.ValidateAttribute ("bar", "", "", info);
		}
        public void PassNull_LocalName_NameSpace__Invalid(String localName, String nameSpace)
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_ATTRIBUTE);
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("OneAttributeElement", "", null);
            try
            {
                val.ValidateAttribute(localName, nameSpace, StringGetter("foo"), info);
            }
            catch (ArgumentNullException)
            {
                return;
            }

            Assert.True(false);
        }
        public void PassNullValueGetter__Invalid()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_VALIDATE_ATTRIBUTE);
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("OneAttributeElement", "", null);
            try
            {
                val.ValidateAttribute("attr", "", (XmlValueGetter)null, info);
            }
            catch (ArgumentNullException)
            {
                return;
            }

            Assert.True(false);
        }
Exemple #16
0
        private void ReplaceSchemaInfo(XObject o, XmlSchemaInfo schemaInfo)
        {
            schemaInfos ??= new Dictionary <XmlSchemaInfo, XmlSchemaInfo>(new XmlSchemaInfoEqualityComparer());
            XmlSchemaInfo?si = o.Annotation <XmlSchemaInfo>();

            if (si != null)
            {
                if (!schemaInfos.ContainsKey(si))
                {
                    schemaInfos.Add(si, si);
                }
                o.RemoveAnnotations <XmlSchemaInfo>();
            }
            if (!schemaInfos.TryGetValue(schemaInfo, out si))
            {
                si = schemaInfo;
                schemaInfos.Add(si, si);
            }
            o.AddAnnotation(si);
        }
        public void InitializeShouldResetIDConstraints()
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_IDENTITY_CONSTRAINS);
            XmlSchemaInfo info = new XmlSchemaInfo();

            for (int i = 0; i < 2; i++)
            {
                val.Initialize();

                val.ValidateElement("rootIDs", "", info);
                val.ValidateEndOfAttributes(null);
                val.ValidateElement("foo", "", info);
                val.ValidateAttribute("attr", "", StringGetter("a1"), info);
                val.ValidateEndOfAttributes(null);
                val.ValidateEndElement(info);
                val.ValidateEndElement(info);

                val.EndValidation();
            }

            return;
        }
Exemple #18
0
        public void CallAfterValidate_Element_Attribute_EndOfAttributes_ForSequence(String after)
        {
            XmlSchemaValidator val = CreateValidator(XSDFILE_GET_EXPECTED_PARTICLES);
            XmlSchemaInfo info = new XmlSchemaInfo();

            val.Initialize();
            val.ValidateElement("SequenceElement", "", info);

            if (after == "attrib")
                val.ValidateAttribute("attr1", "", StringGetter("foo"), info);

            if (after == "endof")
            {
                val.ValidateAttribute("attr1", "", StringGetter("foo"), info);
                val.ValidateAttribute("attr2", "", StringGetter("foo"), info);
                val.ValidateEndOfAttributes(null);
            }

            CheckExpectedElements(val.GetExpectedParticles(), new XmlQualifiedName[] { new XmlQualifiedName("elem1") });

            return;
        }
        private XmlSchemaInfo GetDefaultAttributeSchemaInfo(XmlSchemaAttribute sa)
        {
            XmlSchemaInfo si = new XmlSchemaInfo();

            si.IsDefault       = true;
            si.IsNil           = false;
            si.SchemaAttribute = sa;
            Debug.Assert(sa.AttributeSchemaType != null);
            XmlSchemaSimpleType st = sa.AttributeSchemaType;

            si.SchemaType = st;
            Debug.Assert(st.Datatype != null);
            if (st.Datatype.Variety == XmlSchemaDatatypeVariety.Union)
            {
                string?value = GetDefaultValue(sa);
                Debug.Assert(st.Content != null);
                foreach (XmlSchemaSimpleType mt in ((XmlSchemaSimpleTypeUnion)st.Content).BaseMemberTypes !)
                {
                    object?typedValue = null;
                    try
                    {
                        Debug.Assert(mt.Datatype != null);
                        Debug.Assert(value != null);
                        typedValue = mt.Datatype.ParseValue(value, schemas.NameTable, namespaceManager);
                    }
                    catch (XmlSchemaException)
                    {
                    }
                    if (typedValue != null)
                    {
                        si.MemberType = mt;
                        break;
                    }
                }
            }
            si.Validity = XmlSchemaValidity.Valid;
            return(si);
        }
Exemple #20
0
        private void ReplaceSchemaInfo(XObject o, XmlSchemaInfo schemaInfo)
        {
            if (this.schemaInfos == null)
            {
                this.schemaInfos = new Dictionary <XmlSchemaInfo, XmlSchemaInfo>(new XmlSchemaInfoEqualityComparer());
            }
            XmlSchemaInfo key = o.Annotation <XmlSchemaInfo>();

            if (key != null)
            {
                if (!this.schemaInfos.ContainsKey(key))
                {
                    this.schemaInfos.Add(key, key);
                }
                o.RemoveAnnotations <XmlSchemaInfo>();
            }
            if (!this.schemaInfos.TryGetValue(schemaInfo, out key))
            {
                key = schemaInfo;
                this.schemaInfos.Add(key, key);
            }
            o.AddAnnotation(key);
        }
Exemple #21
0
        private void ValidateElement(XElement e)
        {
            XmlSchemaInfo schemaInfo = this.addSchemaInfo ? new XmlSchemaInfo() : null;
            string        xsiType    = null;
            string        xsiNil     = null;

            this.PushElement(e, ref xsiType, ref xsiNil);
            this.source = e;
            this.validator.ValidateElement(e.Name.LocalName, e.Name.NamespaceName, schemaInfo, xsiType, xsiNil, null, null);
            this.ValidateAttributes(e);
            this.validator.ValidateEndOfAttributes(schemaInfo);
            this.ValidateNodes(e);
            this.validator.ValidateEndElement(schemaInfo);
            if (this.addSchemaInfo)
            {
                if ((schemaInfo.Validity == XmlSchemaValidity.Valid) && schemaInfo.IsDefault)
                {
                    e.Value = this.GetDefaultValue(schemaInfo.SchemaElement);
                }
                this.ReplaceSchemaInfo(e, schemaInfo);
            }
            this.namespaceManager.PopScope();
        }
Exemple #22
0
        public void CallWith_Null_False_XsiNil(String xsiNil)
        {
            XmlSchemaValidator val;
            XmlSchemaInfo info = new XmlSchemaInfo();

            val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT);

            val.Initialize();
            val.ValidateElement("NillableElement", "", info, null, xsiNil, null, null);
            val.ValidateEndOfAttributes(null);

            try
            {
                val.ValidateEndElement(info);
            }
            catch (XmlSchemaValidationException)
            {
                //XmlExceptionVerifier.IsExceptionOk(e, new object[] { "Sch_IncompleteContentExpecting",
																//	new object[] { "Sch_ElementName", "NillableElement" },
																//	new object[] { "Sch_ElementName", "foo" } });
                return;
            }

            Assert.True(false);
        }
Exemple #23
0
        public void CheckNoNamespaceSchemaLocationIs_UsedWhenSpecified_NotUsedWhenFlagIsSet(XmlSchemaValidationFlags allFlags)
        {
            XmlSchemaValidator val;
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlSchemaInfo info = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:element name=\"root\" />\n" +
                                                              "</xs:schema>")));
            val = CreateValidator(schemas, allFlags);
            val.XmlResolver = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info, "type1", null, null, Path.Combine(TestData, XSDFILE_NO_TARGET_NAMESPACE));

            if ((int)allFlags == (int)AllFlags)
            {
                Assert.True(!holder.IsCalledA);
                Assert.True(info.SchemaType is XmlSchemaComplexType);
            }
            else
            {
                Assert.True(holder.IsCalledA);
                //XmlExceptionVerifier.IsExceptionOk(holder.lastException);
            }

            return;
        }
Exemple #24
0
        public void SanityTestsForNestedElements()
        {
            XmlSchemaValidator val;
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlSchemaInfo info = new XmlSchemaInfo();

            schemas.Add("", Path.Combine(TestData, XSDFILE_VALIDATE_END_ELEMENT));
            schemas.Compile();
            val = CreateValidator(schemas);

            val.Initialize();
            val.ValidateElement("NestedElement", "", info);
            val.ValidateEndOfAttributes(null);
            Assert.Equal(info.SchemaElement.QualifiedName, new XmlQualifiedName("NestedElement"));
            Assert.True(info.SchemaType is XmlSchemaComplexType);

            val.ValidateElement("foo", "", info);
            val.ValidateEndOfAttributes(null);
            Assert.Equal(info.SchemaElement.QualifiedName, new XmlQualifiedName("foo"));
            Assert.True(info.SchemaType is XmlSchemaComplexType);

            val.ValidateElement("bar", "", info);
            Assert.Equal(info.SchemaElement.QualifiedName, new XmlQualifiedName("bar"));
            Assert.True(info.SchemaType is XmlSchemaSimpleType);
            Assert.Equal(info.SchemaType.TypeCode, XmlTypeCode.String);

            return;
        }
Exemple #25
0
        public void CallValidateElementAndCHeckXmlSchemaInfoFOr_Simple_Complex_Empty_Mixed_Element_First_Second_Overload(String elemType, XmlSchemaContentType schemaContentType, String overload)
        {
            XmlSchemaValidator val;
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlSchemaInfo info = new XmlSchemaInfo();
            string name = elemType;

            schemas.Add("", Path.Combine(TestData, XSDFILE_VALIDATE_TEXT));
            schemas.Compile();
            val = CreateValidator(schemas);

            val.Initialize();
            if (overload == "first")
                val.ValidateElement(name, "", info);
            else
                val.ValidateElement(name, "", info, null, null, null, null);

            Assert.Equal(info.ContentType, schemaContentType);
            Assert.Equal(info.Validity, XmlSchemaValidity.NotKnown);
            Assert.Equal(info.SchemaElement, schemas.GlobalElements[new XmlQualifiedName(name)]);
            Assert.Equal(info.IsNil, false);
            Assert.Equal(info.IsDefault, false);
            if (name == "SimpleElement")
                Assert.True(info.SchemaType is XmlSchemaSimpleType);
            else
                Assert.True(info.SchemaType is XmlSchemaComplexType);

            return;
        }
 XmlSchemaInfo GetInfo()
 {
     XmlSchemaInfo i = this.info;
     XmlSchemaInfo copy = new XmlSchemaInfo();
     copy.ContentType = i.ContentType;
     copy.IsDefault = i.IsDefault;
     copy.IsNil = i.IsNil;
     copy.MemberType = i.MemberType;
     copy.SchemaAttribute = i.SchemaAttribute;
     copy.SchemaElement = i.SchemaElement;
     copy.SchemaType = i.SchemaType;
     copy.Validity = i.Validity;
     return copy;
 }
Exemple #27
0
        public void CheckThatWarningOccursWhenInvalidNoNamespaceSchemaLocationIsProvided()
        {
            XmlSchemaValidator val;
            XmlSchemaSet schemas = new XmlSchemaSet();
            XmlSchemaInfo info = new XmlSchemaInfo();
            CValidationEventHolder holder = new CValidationEventHolder();

            schemas.Add("", XmlReader.Create(new StringReader("<?xml version=\"1.0\" ?>\n" +
                                                              "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" +
                                                              "    <xs:complexType name=\"rootType\">\n" +
                                                              "        <xs:sequence />\n" +
                                                              "    </xs:complexType>\n" +
                                                              "</xs:schema>")));
            val = CreateValidator(schemas);
            val.XmlResolver = new XmlUrlResolver();
            val.ValidationEventHandler += new ValidationEventHandler(holder.CallbackA);

            val.Initialize();
            val.ValidateElement("root", "", info, "rootType", null, null, Path.Combine(TestData, "__NonExistingFile__.xsd"));

            Assert.True(holder.IsCalledA);
            Assert.Equal(holder.lastSeverity, XmlSeverityType.Warning);
            //XmlExceptionVerifier.IsExceptionOk(holder.lastException, "Sch_CannotLoadSchema", new string[] { "", null });

            return;
        }
Exemple #28
0
        public void CallWithXsiNilTrue()
        {
            XmlSchemaValidator val;
            XmlSchemaInfo info = new XmlSchemaInfo();

            val = CreateValidator(XSDFILE_VALIDATE_END_ELEMENT);

            val.Initialize();
            val.ValidateElement("NillableElement", "", info, null, "true", null, null);
            val.ValidateEndOfAttributes(null);

            val.ValidateEndElement(info);
            Assert.Equal(info.Validity, XmlSchemaValidity.Valid);

            return;
        }
Exemple #29
0
        public void ProvideValidXsiType()
        {
            XmlSchemaValidator val;
            XmlSchemaInfo info = new XmlSchemaInfo();
            XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
            XmlSchemaSet schemas = new XmlSchemaSet();

            schemas.Add("uri:tempuri", Path.Combine(TestData, XSDFILE_TARGET_NAMESPACE));
            val = CreateValidator(schemas, ns, 0);
            ns.AddNamespace("t", "uri:tempuri");

            val.Initialize();
            val.ValidateElement("foo", "uri:tempuri", null, "t:type1", null, null, null);

            return;
        }
 public object ValidateEndElement(XmlSchemaInfo schemaInfo, object typedValue)
 {
     if (typedValue == null)
     {
         throw new ArgumentNullException("typedValue");
     }
     if (this.textValue.Length > 0)
     {
         throw new InvalidOperationException(Res.GetString("Sch_InvalidEndElementCall"));
     }
     return this.InternalValidateEndElement(schemaInfo, typedValue);
 }
Exemple #31
0
        public void ProvideInvalidXsiType()
        {
            XmlSchemaValidator val;
            XmlSchemaInfo info = new XmlSchemaInfo();
            XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
            XmlSchemaSet schemas = new XmlSchemaSet();

            schemas.Add("uri:tempuri", Path.Combine(TestData, XSDFILE_TARGET_NAMESPACE));
            val = CreateValidator(schemas, ns, 0);
            ns.AddNamespace("t", "uri:tempuri");

            val.Initialize();

            try
            {
                val.ValidateElement("foo", "uri:tempuri", null, "type1", null, null, null);
            }
            catch (XmlSchemaValidationException)
            {
                //XmlExceptionVerifier.IsExceptionOk(e, "Sch_XsiTypeNotFound", new string[] { "type1" });
                return;
            }
            Assert.True(false);
        }
 public void ValidateEndOfAttributes(XmlSchemaInfo schemaInfo)
 {
     this.CheckStateTransition(ValidatorState.EndOfAttributes, MethodNames[6]);
     SchemaElementDecl elementDecl = this.context.ElementDecl;
     if ((elementDecl != null) && elementDecl.HasRequiredAttribute)
     {
         this.context.CheckRequiredAttribute = false;
         this.CheckRequiredAttributes(elementDecl);
     }
     if (schemaInfo != null)
     {
         schemaInfo.Validity = this.context.Validity;
     }
 }
Exemple #33
0
        public void StringPassedToValidateEndElementDoesNotSatisfyIdentityConstraints()
        {
            Initialize();
            string xsd =
                "<xs:schema targetNamespace='http://tempuri.org/XMLSchema.xsd' elementFormDefault='qualified' xmlns='http://tempuri.org/XMLSchema.xsd' xmlns:mstns='http://tempuri.org/XMLSchema.xsd' xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
                    "<xs:element name='root'>" +
                        "<xs:complexType> <xs:sequence> <xs:element name='B' type='mstns:B'/> </xs:sequence> </xs:complexType>" +
                        "<xs:unique name='pNumKey'><xs:selector xpath='mstns:B/mstns:part'/><xs:field xpath='.'/></xs:unique>" +
                    "</xs:element>" +
                    "<xs:complexType name='B'><xs:sequence><xs:element name='part' maxOccurs='unbounded' type='xs:string'></xs:element></xs:sequence></xs:complexType>" +
                "</xs:schema>";

            XmlSchemaSet ss = new XmlSchemaSet();
            ss.Add(XmlSchema.Read(new StringReader(xsd), ValidationCallback));
            ss.Compile();

            string ns = "http://tempuri.org/XMLSchema.xsd";
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(ss.NameTable);
            XmlSchemaValidator val = new XmlSchemaValidator(ss.NameTable, ss, nsmgr, XmlSchemaValidationFlags.ProcessIdentityConstraints);
            val.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            val.Initialize();
            XmlSchemaInfo si = new XmlSchemaInfo();
            val.ValidateElement("root", ns, si);
            val.ValidateEndOfAttributes(si);
            val.ValidateElement("B", ns, si);
            val.ValidateEndOfAttributes(si);

            val.ValidateElement("part", ns, si);
            val.ValidateEndOfAttributes(si);
            val.ValidateText("1");
            val.ValidateEndElement(si);

            val.ValidateElement("part", ns, si);
            val.ValidateEndOfAttributes(si);
            val.ValidateEndElement(si, "1");

            val.ValidateElement("part", ns, si);
            val.ValidateEndOfAttributes(si);
            val.ValidateText("1");
            val.ValidateEndElement(si);

            val.ValidateEndElement(si);
            val.ValidateEndElement(si);

            Assert.Equal(warningCount, 0);
            Assert.Equal(errorCount, 2);
            return;
        }
        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 ValidateContext(XmlCache xcache)
        {
            this.cache = xcache;
            if (string.IsNullOrEmpty(cache.FileName)) {
                baseUri = null;
            } else {
                baseUri = new Uri(new Uri(xcache.FileName), new Uri(".", UriKind.Relative));
            }
            ValidationEventHandler handler = new ValidationEventHandler(OnValidationEvent);
            SchemaResolver resolver = xcache.SchemaResolver as SchemaResolver;
            resolver.Handler = handler;
            XmlDocument doc = xcache.Document;
            this.info = new XmlSchemaInfo();
            this.nsResolver = new MyXmlNamespaceResolver(doc.NameTable);
            XmlSchemaSet set = new XmlSchemaSet();
            // Make sure the SchemaCache is up to date with document.
            SchemaCache sc = xcache.SchemaCache;
            foreach (XmlSchema s in doc.Schemas.Schemas()) {
                sc.Add(s);
            }

            if (LoadSchemas(doc, set, resolver)) {
                set.ValidationEventHandler += handler;
                set.Compile();
            }

            this.validator = new XmlSchemaValidator(doc.NameTable, set, nsResolver,
                XmlSchemaValidationFlags.AllowXmlAttributes |
                XmlSchemaValidationFlags.ProcessIdentityConstraints |
                XmlSchemaValidationFlags.ProcessInlineSchema);

            this.validator.ValidationEventHandler += handler;
            this.validator.XmlResolver = resolver;
            this.validator.Initialize();

            this.nsResolver.Context = doc;
            ValidateContent(doc);
            this.nsResolver.Context = doc;

            this.validator.EndValidation();
        }
 internal AttributePSVIInfo() {
     attributeSchemaInfo = new XmlSchemaInfo();
 }