Sub inimuuring() Set XMLDoc = CreateObject("MSXML.DomDocument") XMLDoc.Load "c:\temp\inimesed.xml" Debug.Print XMLDoc.documentelement.childnodes(0). _ childnodes(2).Text Debug.Print "Inimesi kokku: " & XMLDoc.documentelement. _ childnodes.Length ' trüki kõikide inimeste eesnimed For nr = 0 To XMLDoc.documentelement.childnodes.Length - 1 MsgBox XMLDoc.documentelement. _ childnodes(nr).childnodes(0).Text Next nr 'Esimese inimese kõik andmed: Set esimene = XMLDoc.documentelement.childnodes(0) For nr = 0 To esimene.childnodes.Length - 1 MsgBox esimene.childnodes(nr).Text Next nr End Sub 'Loe XML-failist andmed Exceli tabelisse Sub tabelisse() Set XMLDoc = CreateObject("MSXML.DomDocument") XMLDoc.Load "c:\temp\inimesed.xml" Sheet1.Cells.Clear For i = 0 To XMLDoc.documentelement.childnodes.Length - 1 For j = 0 To XMLDoc.documentelement.childnodes(i). _ childnodes.Length - 1 Sheet1.Cells(i + 1, j + 1) = XMLDoc.documentelement. _ childnodes(i).childnodes(j).Text Next j Next i End Sub 'Loe andmed XML-failist Accessi baasi Sub baasi() Dim cn As New ADODB.Connection Dim cm As New ADODB.Command Dim lause As String cn.Open "jaagup1" lause = "INSERT INTO inimesed (eesnimi, perekonnanimi) " & _ "VALUES (?, ?)" Set cm.ActiveConnection = cn cm.CommandText = lause cm.CommandType = adCmdText cm.Parameters.Append cm.CreateParameter("eesnimi", _ adVarChar, adParamInput, 50) cm.Parameters.Append cm.CreateParameter("perekonnanimi", _ adVarChar, adParamInput, 50) Set XMLDoc = CreateObject("MSXML.DomDocument") XMLDoc.Load "c:\temp\inimesed.xml" For i = 0 To XMLDoc.documentelement.childnodes.Length - 1 cm.Parameters("eesnimi").Value = XMLDoc.documentelement. _ childnodes(i).childnodes(0).Text cm.Parameters("perekonnanimi").Value = _ XMLDoc.documentelement. _ childnodes(i).childnodes(1).Text cm.Execute Next i cn.Close End Sub Sub teeXML() Set XMLDoc = CreateObject("MSXML.DomDocument") Set juur = XMLDoc.createNode(1, "eesnimed", "") XMLDoc.documentelement = juur Set nimeelement = XMLDoc.createNode(1, "eesnimi", "") nimeelement.Text = "Juku" juur.appendChild nimeelement Set nimeelement = XMLDoc.createNode(1, "eesnimi", "") nimeelement.Text = "Kati" juur.appendChild nimeelement Set nimeelement = XMLDoc.createNode(1, "eesnimi", "") nimeelement.Text = "Mati" juur.appendChild nimeelement MsgBox XMLDoc.xml Open "c:\temp\nimed2.xml" For Output As #1 Print #1, "" Print #1, XMLDoc.xml Close #1 End Sub 'Kirjutage töölehel leiduvad eesnimed ja perekonnanimed 'XML-faili Sub leheltFaili() Set XMLDoc = CreateObject("MSXML.DomDocument") Set juur = XMLDoc.createNode(1, "inimesed", "") XMLDoc.documentelement = juur reanr = 1 While Len(Cells(reanr, 1)) > 0 Set inelem = XMLDoc.createNode(1, "inimene", "") juur.appendChild inelem Set enimi = XMLDoc.createNode(1, "eesnimi", "") inelem.appendChild enimi enimi.Text = Cells(reanr, 1) Set pnimi = XMLDoc.createNode(1, "perekonnanimi", "") inelem.appendChild pnimi pnimi.Text = Cells(reanr, 2) reanr = reanr + 1 Wend Open "c:\temp\nimed3.xml " For Output As #1 Print #1, "" Print #1, XMLDoc.xml Close #1 End Sub