Io ho proceduto come segue:
' inzia a creare l'XML
' create dom document
Set objDoc = XMLCreateDoc
' Create a processing instruction targeted for xml.
XMLCreateProcessingInstruction objDoc, "xml", "version='1.0' encoding='UTF-8'"
' <p:FatturaElettronica>
Set objNodeRoot = XMLCreateNode(objDoc, Nothing, "ns2:FatturaElettronica")
' <versione>
XMLCreateAttribute objDoc, objNodeRoot, "versione", XMLInvoiceType
' <xmlns:ds>
XMLCreateAttribute objDoc, objNodeRoot, "xmlns:ds", "http://www.w3.org/2000/09/xmldsig#"
' <xmlns:p>
XMLCreateAttribute objDoc, objNodeRoot, "xmlns:ns2", "http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
' <xmlns:xsi>
XMLCreateAttribute objDoc, objNodeRoot, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
' <xsi:schemaLocation>
XMLCreateAttribute objDoc, objNodeRoot, "xsi:schemaLocation", "http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 fatturaordinaria_v1.2.xsd "
' ---- XML header ----
' <FatturaElettronicaHeader>
Set objNodeHeader = XMLCreateNode(objDoc, objNodeRoot, "FatturaElettronicaHeader")
' <DatiTrasmissione>
Set objNode1 = XMLCreateNode(objDoc, objNodeHeader, "DatiTrasmissione")
' <IdTrasmittente>
Set objNode2 = XMLCreateNode(objDoc, objNode1, "IdTrasmittente")
XMLCreateNode objDoc, objNode2, "IdPaese", dbField2Var(ADOrsXMLM1.Fields("ISOStato"), dbCTString)
XMLCreateNode objDoc, objNode2, "IdCodice", dbField2Var(ADOrsXMLM1.Fields("CodFisc"), dbCTString)
' <ProgressivoInvio>
Set objNode2 = XMLCreateNode(objDoc, objNode1, "ProgressivoInvio", ConvStr(IDFatturaPA, 5))
' <FormatoTrasmissione>
Set objNode2 = XMLCreateNode(objDoc, objNode1, "FormatoTrasmissione", XMLInvoiceType)
' <CodiceDestinatario>
Set objNode2 = XMLCreateNode(objDoc, objNode1, "CodiceDestinatario", dbField2Var(ADOrsFPA.Fields("GovCodiceDestinatario"), dbCTString))
' <ContattiTrasmittente>
Set objNode2 = XMLCreateNode(objDoc, objNode1, "ContattiTrasmittente")
XMLCreateNode objDoc, objNode2, "Telefono", GetNum(dbField2Var(ADOrsXMLM1.Fields("Telefono1"), dbCTString))
XMLCreateNode objDoc, objNode2, "Email", dbField2Var(ADOrsXMLM1.Fields("Email"), dbCTString)
' <PECDestinatario>
If dbField2Var(ADOrsFPA.Fields("GovCodiceDestinatario"), dbCTString) = "0000000" Then
Set objNode2 = XMLCreateNode(objDoc, objNode1, "PECDestinatario", dbField2Var(ADOrsFPA.Fields("PEC"), dbCTString))
End If
...
...
...
' ------------------------------------------------
' sub per creazione file XML
' testate e funzionanti - 23 ago 2014
'
' http://www.vbforums.com/showthread.php?538334-Child-Elements-(XML-with-VB6)
'
Private Function XMLCreateDoc()
' crea il documento XML
Dim objDoc
Set objDoc = New DOMDocument60
objDoc.async = False
objDoc.validateOnParse = False
objDoc.resolveExternals = False
objDoc.preserveWhiteSpace = True
Set XMLCreateDoc = objDoc
End Function
Private Sub XMLCreateProcessingInstruction(XMLDoc As DOMDocument60, InstrName As String, InstrValue As String)
Dim objNode As IXMLDOMProcessingInstruction
Set objNode = XMLDoc.createProcessingInstruction(InstrName, InstrValue)
XMLDoc.appendChild objNode
Set objNode = Nothing
End Sub
Private Sub XMLCreateComment(XMLDoc As DOMDocument60, ByVal CommentText As String)
Dim objComment As IXMLDOMComment
Set objComment = XMLDoc.createComment(CommentText)
XMLDoc.appendChild objComment
Set objComment = Nothing
End Sub
Private Function XMLCreateNode(XMLDoc As DOMDocument60, ParentNode As IXMLDOMNode, NodeName As String, Optional NodeValue As String = "") As IXMLDOMNode
' crea un nodo nel documento XML
Dim objNode As IXMLDOMNode
'Create the node
Set objNode = XMLDoc.createElement(NodeName)
'Add the text if it has any
If NodeValue <> "" Then
objNode.text = NodeValue
End If
'Add the node to the document
If ParentNode Is Nothing Then
XMLDoc.appendChild objNode
Else
ParentNode.appendChild objNode
End If
Set XMLCreateNode = objNode
Set objNode = Nothing
End Function
Private Sub XMLCreateAttribute(XMLDoc As DOMDocument60, oNode As IXMLDOMNode, AttribName As String, AttribValue As String)
Dim oElement As IXMLDOMElement
Set oElement = oNode
oElement.setAttribute AttribName, AttribValue
Set oElement = Nothing
End Sub
Private Sub XMLFormatDoc(ByVal xml_doc As DOMDocument60)
' Add formatting to the document.
XMLFormatNode xml_doc.documentElement, 0
End Sub
Private Sub XMLFormatNode(ByVal node As IXMLDOMNode, ByVal indent As Integer)
' Add formatting to this element. Indent it and add a
' carriage return before its children. Then recursively
' format the children with increased indentation.
Dim child As IXMLDOMNode
Dim text_only As Boolean
' Do nothing if this is a text node.
If TypeOf node Is IXMLDOMText Then Exit Sub
' See if this node contains only text.
text_only = True
If node.hasChildNodes Then
For Each child In node.childNodes
If Not (TypeOf child Is IXMLDOMText) Then
text_only = False
Exit For
End If
Next child
End If
' Process child nodes.
If node.hasChildNodes Then
' Add a carriage return before the children.
If Not text_only Then
node.insertBefore node.ownerDocument.createTextNode(vbCrLf), node.firstChild
End If
' Format the children.
For Each child In node.childNodes
XMLFormatNode child, indent + 2
Next child
End If
' Format this element.
If indent > 0 Then
' Indent before this element.
node.ParentNode.insertBefore node.ownerDocument.createTextNode(Space$(indent)), node
' Indent after the last child node.
If Not text_only Then node.appendChild node.ownerDocument.createTextNode(Space$(indent))
' Add a carriage return after this node.
If node.nextSibling Is Nothing Then
node.ParentNode.appendChild node.ownerDocument.createTextNode(vbCrLf)
Else
node.ParentNode.insertBefore node.ownerDocument.createTextNode(vbCrLf), node.nextSibling
End If
End If
End Sub
' ---------------------------------------