Xml Xsd Validation Fails (xs:anyType)

BoRoU

New Member
I have this XML file\[code\]<bookstore> <test> <test2/> </test></bookstore>\[/code\]and this XSD schema\[code\]<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="bookstore" type="bookstoreType"/> <xsd:complexType name="bookstoreType"> <xsd:sequence maxOccurs="unbounded"> <xsd:element name="test" type="xsd:anyType" /> </xsd:sequence> </xsd:complexType></xsd:schema>\[/code\]I intend to validate xml file from C# code.There is a method that validate XML file:\[code\] // validate xml private void ValidateXml() { _isValid = true; // Get namespace from xml file var defaultNamespace = XDocument.Load(XmlFileName).Root.GetDefaultNamespace().NamespaceName; // Set the validation settings. XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; settings.Schemas.Add(defaultNamespace, XsdFileName); settings.ValidationEventHandler += OnValidationEventHandler; // Create the XmlReader object. using(XmlReader reader = XmlReader.Create(XmlFileName, settings)) { // Parse the file. while (reader.Read()) ; } } private void OnValidationEventHandler(object s, ValidationEventArgs e) { if (_isValid) _isValid = false; if (e.Severity == XmlSeverityType.Warning) MessageBox.Show("Warning: " + e.Message); else MessageBox.Show("Validation Error: " + e.Message); }\[/code\]I know, this XML file is valid. But my code reterns this Error:\[code\]Validation Error: Could not find schema information for the element 'test2'\[/code\]Where is my mistake?Thanks!!!
 
Back
Top