Microsoft Knowledge Base Email Alertz

KBAlertz.com: (828928) - When you add the XML namespace attribute (xmlns) to the root node of an XML document, an XML namespace attribute with an empty value is created for the child nodes of the root node.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 828928 - Last Review: August 18, 2005 - Revision: 1.1

PRB: MSXML 4.0 Sets the XML Namespace Attribute to an Empty Value for Child Nodes

On This Page

SYMPTOMS

When you add the XML namespace attribute (xmlns) to the root node of an XML document, an XML namespace attribute with an empty value is created for the child nodes of the root node.

CAUSE

You cannot add, modify, or delete an XML namespace definition in an instance of an XML document after the document has been loaded into the XML Document Object Model (XMLDOM) parser. The XML nodes that are used to represent data in the XML document are created when the document is loaded into the XMLDOM parser. These nodes are permanently bound to their XML namespace attributes when they are created. Therefore, the empty XML namespace declaration (xmlns = "") is appended to the child nodes of these nodes to preserve the default XML namespace attribute of these nodes.

WORKAROUND

To work around this problem, specify XML namespace declarations before you load an XML document.

STATUS

This behavior is by design.

MORE INFORMATION

The behavior that is mentioned in the "Symptoms" section of this article is the expected behavior in the MSXML 4.0 Document Object Model (DOM). This behavior also complies with the World Wide Web Consortium (W3C) specifications. The MSXML 4.0 DOM specifies the following clauses:
  • XML namespace definitions are specified at the load time of an XML document.
  • Microsoft does not recommend that you programmatically create or append XML namespace attributes because this may result in inconsistent behavior.
  • The XML nodes that are used to represent data in an XML document are created when the document is loaded into the XMLDOM parser. These XML nodes are permanently bound to their XML namespace attributes when they are created.
  • Adding a default XML namespace attribute to a root node after data is loaded into the XMLDOM parser does not automatically associate all child nodes with the default XML namespace.
  • To dynamically add an element or an attribute node to the XML tree, pass the XML namespace attribute as the third parameter to the CreateNode method.

Steps to Reproduce the Behavior

  1. Paste the following XML code in Notepad, and then save the file as book.xml:
    <?xml version='1.0'?>
    <Collection>
    <Book>
    <Science>
    <Title>Lover Birds</Title>
    <Author>Cynthia Randall</Author>
    <Publisher>Lucerne Publishing</Publisher>
    </Science>
    </Book>
    </Collection>
    
  2. Start Visual Basic 6.0.
  3. Create a Standard EXE project. By default, Form1 is created.
  4. On the Project menu, click References.
  5. In the References - Project1 dialog box, click to select Microsoft XML, v4.0 under Available References, and then click OK.
  6. Add a command button to Form1, and then set the Caption property of the command button to XMLApp.
  7. Add the following code to the Click event of the XMLApp command button:
    Dim xmldom3 As New DOMDocument30
    Dim xmldom4 As New DOMDocument40
    
    xmldom3.Load ("c:\book.xml")
    xmldom3.documentElement.setAttribute "xmlns", "x-schema:books"
    MsgBox ("msxml 3 : " + xmldom3.xml)
    
    xmldom4.Load ("c:\book.xml")
    xmldom4.documentElement.setAttribute "xmlns", "x-schema:books"
    MsgBox ("msxml 4 : " + xmldom4.xml)
    
  8. On the Run menu, click Start. Form1 is displayed.
  9. On the Form1 form, click XMLApp.

    You receive a message box that contains the following content:

    msxml 3 : <?xml version="1.0"?>
    <Collection xmlns="x-schema:books">
    <Book>
    <Science>
    <Title>Lover Birds</Title>
    <Author>Cynthia Randall</Author>
    <Publisher>Lucerne Publishing</Publisher>
    </Science>
    </Book>
    </Collection>
    The content that is displayed is the output from the MSXML 3.0 parser. Notice that the XML namespace attribute(xmlns = "") is not applied to the child node of the root node.
  10. Click OK to close this message box.

    You receive another message box that contains the following content:

    msxml 4: <?xml version="1.0"?>
    <Collection xmlns="x-schema:books">
    <Book xmlns="">
    <Science>
    <Title>Lover Birds</Title>
    <Author>Cynthia Randall</Author>
    <Publisher>Lucerne Publishing</Publisher>
    </Science>
    </Book>
    </Collection>
    The content that is displayed is the output from the MSXML 4.0 parser. Notice that the XML namespace attribute (xmlns = "") is applied to the child node of the root node.
  11. Click OK to close this message box.

REFERENCES

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
290485  (http://kbalertz.com/Feedback.aspx?kbNumber=290485/ ) DOMDocument.CreateNode() Method Appends an Empty Namespace Declaration
For more information about XML namespaces, visit the following W3C Web site:
http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#Namespaces-Considerations (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#Namespaces-Considerations)

APPLIES TO
  • Microsoft XML Core Services 4.0
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 6.0 Professional Edition
Keywords: 
kbnamespace kbxml kbprb KB828928
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please