Xml 通过VBA继承父属性的子元素

Xml 通过VBA继承父属性的子元素,xml,vba,excel,namespaces,Xml,Vba,Excel,Namespaces,我正在处理excel 2013的xml输出,我已经设置了对xml v6库的引用,但没有得到预期的结果。 这是我正在使用的代码: Sub testXML() Dim dom, node, attr, PCMS, SendPCMS, header Set dom = CreateDom Set node = dom.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'") dom.appendChild node S

我正在处理excel 2013的xml输出,我已经设置了对xml v6库的引用,但没有得到预期的结果。 这是我正在使用的代码:

Sub testXML()

Dim dom, node, attr, PCMS, SendPCMS, header

Set dom = CreateDom
Set node = dom.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'")
dom.appendChild node
Set node = Nothing

Set PCMS = dom.createElement("PCMS")
Set attr = dom.createAttribute("xmlns")
attr.Value = "MyNamespace"
PCMS.setAttributeNode attr
Set attr = Nothing
dom.appendChild PCMS

Set SendPCMS = dom.createElement("SendPCMSManifest")
PCMS.appendChild SendPCMS
Set header = dom.createElement("header")
PCMS.appendChild header

dom.Save "C:\Temp\DomTest.xml"

End Sub
Private Function CreateDom()
Dim dom
Set dom = New DOMDocument
dom.async = False
dom.validateOnParse = False
dom.resolveExternals = False
dom.preserveWhiteSpace = True
Set CreateDom = dom
End Function
出于某种原因,属性“xmlns”也按照以下输出应用于子元素(但仅应用于属性名称,而不是值):

?xml version="1.0" encoding="UTF-8"?>
PCMS xmlns="MyNamespace">
 SendPCMSManifest xmlns=""/>
 header xmlns=""/>
/PCMS>
谁能告诉我哪里出了问题?元素“sendpcsmanifest”和“header”在节点名称中不应包含“xmlns=”

编辑:尝试获取示例输出xml显示

Sub testXML()

Dim dom, node, PCMS

    Set dom = CreateDom
    Set node = dom.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'")
    dom.appendChild node
    Set node = Nothing

    Set PCMS = dom.createNode(1, "PCMS", "MyNamespace")
    dom.appendChild PCMS

    PCMS.appendChild dom.createNode(1, "SendPCMSManifest", "MyNamespace")
    PCMS.appendChild dom.createNode(1, "header", "MyNamespace")

    Debug.Print dom.XML

End Sub

Private Function CreateDom()
    Dim dom
    Set dom = New DOMDocument
    dom.async = False
    dom.validateOnParse = False
    dom.resolveExternals = False
    dom.preserveWhiteSpace = True
    Set CreateDom = dom
End Function
输出:

<?xml version="1.0"?>
<PCMS xmlns="MyNamespace"><SendPCMSManifest/><header/></PCMS>

类似的问题:嗨,蒂姆-医生点的菜。非常感谢你