Access
A family of Microsoft relational database management systems designed for ease of use.
400 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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.
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.
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
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