Creating an XML document using DOMDocument60 with the use of the xmlns attribute

jacky Perpète 41 Reputation points
2023-03-06T08:40:52.5866667+00:00

Hello,

With Access 2021, I am trying to create an XML document using DOMDocument60.

After creating the first element with the <xmlns> attribute and its value, I see that the added child element also has the attribute name.

xmlns

If I change the <xmlns> attribute name to another value or if the namespace is followed in prefix (xmlns:abc), I don't have this problem.

Attribut

How to solve this problem?

Is this the correct way to handle the <xmlns> attribute for the first element?

Here is my test code.

Private Sub cmdEssai_Click()

Dim xmlDomRuban As New DOMDocument60
Dim xmlElement1 As IXMLDOMElement
Dim xmlElement2 As IXMLDOMElement

Set xmlElement1 = xmlDomRuban.createElement("customUI")
xmlDomRuban.appendChild xmlElement1
xmlElement1.setAttribute "xmlns", "http://schemas.microsoft.com/office/2009/07/customui"

Set xmlElement2 = xmlDomRuban.createElement("ribbon")
xmlElement1.appendChild xmlElement2

Debug.Print xmlDomRuban.XML

End Sub
Access
Access
A family of Microsoft relational database management systems designed for ease of use.
389 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,895 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 117.2K Reputation points
    2023-03-06T11:17:57.8+00:00

    Try this:

    Private Function CreateElement(ByVal doc As DOMDocument60, ByVal name As String) As IXMLDOMElement
        
        Set CreateElement = doc.createNode(tagDOMNodeType.NODE_ELEMENT, name, "http://schemas.microsoft.com/office/2009/07/customui")
    
    End Function
    
    Private Sub cmdEssai_Click()
    
        Dim xmlDomRuban As New DOMDocument60
        Dim xmlElement1 As IXMLDOMElement
        Dim xmlElement2 As IXMLDOMElement
        
        Set xmlElement1 = CreateElement(xmlDomRuban, "customUI")
        xmlDomRuban.appendChild xmlElement1
    
        Set xmlElement2 = CreateElement(xmlDomRuban, "ribbon")
        xmlElement1.appendChild xmlElement2
        
        Debug.Print xmlDomRuban.XML
    
    End Sub
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.