Microsoft KB Archive/296492

= PRB: Namespace Prefixes Are Declared as FIXED Attributes in an XML DTD =

Article ID: 296492

Article Last Modified on 10/12/2001

-

APPLIES TO


 * Microsoft XML Core Services 4.0
 * Microsoft XML Parser 3.0 Service Pack 1
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q296492



SYMPTOMS
The Microsoft XML (MSXML) parser does not interpret namespace prefixes that are declared as FIXED attributes in an XML Document Type Definition (DTD). If you use a FIXED value attribute in a DTD to declare a namespace prefix, and if you use the namespace prefix to qualify element or attribute names without explicitly declaring the prefix in an XML document that references the DTD, you may receive the following error message when the MSXML parser tries to load the XML:

Reference to undeclared namespace prefix: 

This error occurs whether you program the MSXML Document Object Model (DOM) through code or open the XML document in Microsoft Internet Explorer.



CAUSE
This problem occurs because XML Language and Namespace specifications do not define how DTDs and namespaces should interact with each other.



RESOLUTION
To work around this problem, explicitly declare the namespace prefix in the XML document before you use it to qualify element and/or attribute names. For more information and sample code, see the &quot;More Information&quot; section.



MORE INFORMATION
Some third party XML parsers may be able to interpret and load XML documents that use namespace prefixes that are defined in a referenced DTD as a FIXED value attribute without explicitly declaring them. However, this does not mean that the behavior of such parsers is always correct. The correct behavior of an XML parser is defined by the World Wide Web Consortium (W3C) XML specifications. Currently, the XML Language and Namespace specifications do not define how DTDs and namespaces should interact with each other.

Steps to Reproduce Behavior
To create an XML document with an inline DTD and reproduce this behavior, follow these steps:  In Notepad, open a new text file.  Copy and paste the following XML code:  <!DOCTYPE Books [ <!ELEMENT Books (Book+)> <!ATTLIST Books xmlns:Bookns CDATA    #FIXED &quot;http://myserver/books&quot; > <!ELEMENT Book EMPTY> <!ATTLIST Book Bookns:ISBN  CDATA    #REQUIRED Bookns:TITLE CDATA    #REQUIRED > ]>      Save this file as Books.xml.</li> In Internet Explorer, open Books.xml. The MSXML parser generates the following error message:

Reference to undeclared namespace prefix: 'Bookns'. Line 14, Position 81

</li> Program the MSXML DOM to load Books.xml. Notice that you receive the same error message. To access the error message, use the reason property of the parseError object property of the MSXML DOMDocument object.</li></ol>

Workaround
This error occurs because the namespace prefix Bookns is used to prefix the ISBN and TITLE attributes of the Book element and is not explicitly declared in the XML portion of the document. The sample document that you created in Step 2 contains an inline DTD that defines the Bookns namespace prefix as a FIXED attribute of the Books element. However, this declaration alone is not sufficient for the MSXML parser to correctly interpret and load the XML. You must explicitly declare the namespace prefix in the XML document before you can use it to qualify element and/or attribute names.

To work around this behavior, replace the opening  element in the XML with the following line of code to explicitly declare the Bookns namespace prefix attribute as specified in the DTD: <Books xmlns:Bookns=&quot;http://myserver/books&quot;> Save the change to Books.xml, and then open Books.xml in Internet Explorer. Notice that the browser loads and displays the XML correctly.

NOTE This behavior also occurs in an XML document that references an external DTD.

Keywords: kbprb KB296492

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.