im usin "DOMDocument60" with VB6, i need to generate a XML file, but i'm having a problem trying to add "Attibutes" to a subnode. This is the file that generates my code:
<myroot>
<MyNode SIZE="10">
<SubNode/>
</MyNode>
</myroot>
And this is what i need:
<myroot>
<MyNode SIZE="10">
**<SubNode CODE="0000" ID="XXX" OTHER="XXX"/>**
</MyNode>
</myroot>
This is the code (is based in http://msdn.microsoft.com/en-us/library/ms760231%28v=vs.85%29.aspx):
Private Function CrearDOM() Dim dom Set dom = New DOMDocument60 dom.async = False dom.validateOnParse = False dom.resolveExternals = False dom.preserveWhiteSpace = True Set CrearDOM = dom End Function
Public Sub Crear_XML()
Set dom = CrearDOM
' Encabezado de XML
Set node = dom.createProcessingInstruction("xml", "version='1.0' encoding='iso-8859-1'")
dom.appendChild node
Set node = Nothing
Dim MyRoot
Set MyRoot = dom.createElement("MasRequest")
MyRoot.appendChild dom.createTextNode(vbNewLine + vbTab)
Set node = dom.createElement("MyNode")
Set attr = dom.createAttribute("SIZE")
attr.Value = 10
node.setAttributeNode attr
Set attr = Nothing
Set Nodo_Sub = dom.createDocumentFragment
Nodo_Sub.appendChild dom.createTextNode(vbNewLine + vbTab + vbTab)
Nodo_Sub.appendChild dom.createElement("SubNode")
node.appendChild Nodo_Droga
MyRoot.appendChild node
End Sub
Thanks for the help.