BUG: Schema Object Model Does Not Recognize Valid Prefix Inside XPath Selector (317440)



The information in this article applies to:

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

This article was previously published under Q317440
The following .NET Framework Class Library namespaces are referenced in this article:

System.XML
System.XML.Schema

SYMPTOMS

When you use the Extensible Markup Language (XML) Schema Object Model (SOM) to create and to compile a schema from the very beginning, the SOM does not recognize a valid prefix inside an XML Path Language (XPath) selector. The prefix is added through the XmlSchema.Namespaces property.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start Visual Studio .NET.
  2. Create a new Windows application in Microsoft Visual C# .NET. Form1 is added to the project by default.
  3. Verify that your project contains a reference to the System.Data namespace. If it does not, add a reference to this namespace.
  4. Drag a Button control from the toolbox onto Form1. In the Properties window, change the Name property of the button to btnTest.
  5. Use the using statement on the System.Xml and the System.Xml.Schema namespaces so that you are not required to qualify declarations in those namespaces later in your code. Add the following code to the "General Declarations" section of Form1:
    using System.Xml;
    using System.Xml.Schema;
    					
  6. Add the following code in the btnTest_Click event:
    XmlSchema schema = new XmlSchema();
    schema.Namespaces.Add("r", "nsp");
    schema.Namespaces.Add("xs", "http://www.w3.org/2001/XMLSchema");
    schema.ElementFormDefault = XmlSchemaForm.Qualified;
    schema.TargetNamespace = "nsp";
    
    XmlSchemaElement element = new XmlSchemaElement();
    element.Name = "root";
    
    XmlSchemaKey element_key = new XmlSchemaKey();
    element_key.Name = "pNumKey";
    
    XmlSchemaXPath element_key_selector = new XmlSchemaXPath();
    element_key_selector.XPath = "r:part";
    element_key.Selector = element_key_selector;
    
    XmlSchemaXPath field = new XmlSchemaXPath();
    field.XPath = "@number";
    element_key.Fields.Add(field);
    element.Constraints.Add(element_key);
    
    schema.Items.Add(element);
    schema.Compile(new ValidationEventHandler(ValidationCallBack));
    schema.Write(Console.Out);
    					
  7. Add the following code immediately after the btnTest_Click event:
    public void ValidationCallBack(object sender, ValidationEventArgs args) 
    {
        Console.WriteLine(args.Message);
        Console.WriteLine(args.Exception);
    }
    					
  8. Save your project. On the Debug menu, click Start to run your project. You receive the following error message in the output window:
    The prefix 'r' in Xpath is unresolvable.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

313651 INFO: Roadmap for XML in the .NET Framework


Modification Type:MajorLast Reviewed:9/15/2003
Keywords:kbbug kbnofix KB317440