xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
Go Back  Xtreme Visual Basic Talk > > > xmlns Attributes on Child Nodes


Reply
 
Thread Tools Display Modes
  #1  
Old 02-25-2015, 05:31 PM
Pizzor2000's Avatar
Pizzor2000 Pizzor2000 is offline
Centurion
 
Join Date: Jan 2004
Location: Midland, TX
Posts: 106
Default xmlns Attributes on Child Nodes


I am trying to create an XML document using MSXML6. I want the root node to have an XML namespace specified.

This is my code:
Code:
    Dim xmlDocument As New DOMDocument60
    Dim xmlRoot As IXMLDOMElement
    Dim xmlChild1 As IXMLDOMElement
    Dim xmlChild2 As IXMLDOMElement
    
    'Root element.
    Set xmlRoot = xmlDocument.createElement("File")
    xmlDocument.appendChild xmlRoot
    
    'Set xmlns attribute on root element.
    xmlRoot.setAttribute "xmlns", "https://AddressOfRootElement"
    
    'First child element.
    Set xmlChild1 = xmlDocument.createElement("FirstChildNode")
    xmlRoot.appendChild xmlChild1
    
    'Second child element.
    Set xmlChild2 = xmlDocument.createElement("SecondChildNode")
    xmlRoot.appendChild xmlChild2
    
    xmlDocument.save "c:\temp\test.xml"
When I look at the test.xml created with this code, it adds a blank xmlns attribute to the child nodes:
Code:
<File xmlns="https://AddressOfRootElement">
    <FirstChildNode xmlns=""/>
    <SecondChildNode xmlns=""/>
</File>
I googled this and determined that I'm not the only one having this problem, but I haven't found anything addressing this problem or a solution in VB6.

Is there a way to stop the system from creating the xmlns entries on the child nodes?
Reply With Quote
  #2  
Old 02-26-2015, 11:13 AM
dilettante's Avatar
dilettantexmlns Attributes on Child Nodes dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,524
Default

You don't want to fiddle and faddle with IXMLDOMElement. Instead you will find using IXMLDOMNode a far more useful approach:

Code:
    Const NAMESPACE As String = "https://a.b.c.d"
    Dim xmlRoot As IXMLDOMNode
    
    With New MSXML2.DOMDocument
        Set xmlRoot = .appendChild(.createNode(NODE_ELEMENT, "Doc", NAMESPACE))
        xmlRoot.appendChild .createNode(NODE_ELEMENT, "Child", NAMESPACE)
        xmlRoot.appendChild .createNode(NODE_ELEMENT, "Child", NAMESPACE)
        Text1.Text = PrettyPrint(.xml)
    End With
See PRB: DOMDocument.CreateNode() Method Appends an Empty Namespace Declaration, which states:

Quote:
This behavior is by design.
Attached Files
File Type: zip Create XML Namespace.zip (2.4 KB, 7 views)
Reply With Quote
Reply

Tags
xml, xmlns


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
 
xmlns Attributes on Child Nodes
xmlns Attributes on Child Nodes
 
-->