FIX: Unexpected Validation Error on xsd:any processContents="skip" (317353)



The information in this article applies to:

  • Microsoft XML Classes (included with the .NET Framework 1.0)

This article was previously published under Q317353

SYMPTOMS

If you define a complex type with a xsd:any declaration and an attribute of processContents="skip"; for example
<xsd:schema id="test1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsd:element name="root">
	    <xsd:complexType>
		    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
			    <xsd:any namespace="##any" processContents="skip" />
		    </xsd:sequence>
	    </xsd:complexType>
	</xsd:element>
</xsd:schema>
				
When you use an XmlValidatingReader(System.Xml namespace) call to validate the following XML data against the above schema
<root><this that="somevalue"/></root>
				
the following error is returned:
Severity:Warning Message : Could not find schema information for the element 'this'. An error occurred at (x, y).
Severity:Error Message : The 'that' attribute is not declared . An error occurred at (x, y).

STATUS

This bug was corrected in Microsoft .NET Framework Class Libraries. However, a similar problem where you may have xsi or xsd attributes continues to occur. This problem is also a bug and is not fixed in the .NET Framework Class Libraries 1.1.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Save the following XML data as test.xml on drive C:
    <root><this that="somevalue"/></root>
    						
    Save the following XSD schema as test.xsd on drive C:
    <xsd:schema id="test1" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    	<xsd:element name="root">
    	    <xsd:complexType>
    		    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
    			    <xsd:any namespace="##any" processContents="skip" />
    		    </xsd:sequence>
    	    </xsd:complexType>
    	</xsd:element>
    </xsd:schema>
    					
  2. Create a Microsoft C# Console Application. Replace the code in Class1.cs with the following:
    using System;
    using System.Xml;
    using System.Xml.Schema;
    using System.IO;
    
    namespace Test
    {
    	/// <summary>
    	/// Summary description for Class1.
    	/// </summary>
    	class Class1
    	{
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		[STAThread]
    		static void Main(string[] args)
    		{
    			Class1 cls= new Class1();
    			cls.validateXml();
    		}
    		public void validateXml()
    		{
    			//Hard-coded path doesn't work either.
    			FileStream stream = new FileStream("c:\\test.xml", FileMode.Open);
    			try
    			{
    				XmlValidatingReader reader= new XmlValidatingReader(stream, XmlNodeType.Document, null);
    			
    				//Set the schema type as XSD schema.
    				reader.ValidationType = ValidationType.Schema;
    
    				//Add the XSD to reader's schema collection.
    				XmlSchemaCollection schemaCollection = reader.Schemas;
    				schemaCollection.Add("","c:\\test.xsd");
    			
    				//Set the event handler.
    				reader.ValidationEventHandler += new ValidationEventHandler (ValidationHandler);
    
    				while(reader.Read());
    				System.Console.WriteLine("Validation finished");
    			}
    			catch(XmlException ex)
    			{
    				System.Console.WriteLine("XmlException : {0}", ex.ToString());
    			}
                            System.Console.Read();
    		}
    		public static void ValidationHandler(object sender, ValidationEventArgs args)
    		{
    			System.Console.WriteLine( "***Validation error Severity:{0} Message : {1}", args.Severity, args.Message);
    		}
    	}
    }
    					
  3. Compile and then run the application. In the console window, the following error is returned:
    Severity:Warning Message : Could not find schema information for the element 'this'. An error occurred at (1, 8).
    Severity:Error Message : The 'that' attribute is not declared . An error occurred at (1, 12).

Modification Type:MajorLast Reviewed:9/18/2003
Keywords:kbBug kbnofix KB317353