creating a xml file using VB

vb6 Grenada
  • 14 years ago

    I want to create a xml file using VB i am using MSXML 4.0 parser.
    anybody plz help me

    my xml should look like this


    <age>some dat</age>
    <name>some data</dat.
    <address>some data<address>

    <age>some dat</age>
    <name>some data</dat.
    <address>some data<address>

    <age>some dat</age>
    <name>some data</dat.
    <address>some data<address>


  • 14 years ago

    You can very well do this, using the DOM (Document Object Model).

    Search examples on DOM, u will surely get some....if not, then let me know...will surely help u out....

  • 14 years ago

    i do able to create an xml file with the following info

    <age>some dat</age>
    <name>some data</dat.
    <address>some data<address>

    problem is i want to add the above info multiple times could u please tell me how to do this

  • 14 years ago
    use the below example....which may help you in doing so

    Private Sub Command1_Click()
        Dim rsXML As New ADODB.Recordset
        Dim sSQL As String, sConn As String
        sSQL = "SELECT customerid, companyname, contactname FROM customers"
        sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Common Files\System\msadc\samples\NWind.mdb"
        rsXML.CursorLocation = adUseClient
        rsXML.Open sSQL, sConn, adOpenStatic

        Dim xDOM As New MSXML.DOMDocument
        Dim x2DOM As New MSXML.DOMDocument
        Dim dataNodeList As IXMLDOMNodeList
        Dim dataNode, rowNode, newNode, newRoot, newNode2 As IXMLDOMNode
        rsXML.Save "C:\temp\rsDOM.xml", adPersistXML
        ' Save Recordset directly into a DOM tree.
        rsXML.Save xDOM, adPersistXML
        Set dataNodeList = xDOM.getElementsByTagName("rs:data")
        Set dataNode = dataNodeList.Item(0)
        ' Create a new Node under new DOM.
        Set newRoot = x2DOM.createNode(NODE_ELEMENT, "recordset", "")
        ' Append root node.
        Set newRoot = x2DOM.appendChild(newRoot)
        i = 0
        ' Loop through all z:row nodes.
        While i < dataNode.childNodes.length
            ' Get to the z:row node.
            Set rowNode = dataNode.childNodes.Item(i)

            Set newNode = x2DOM.createNode(NODE_ELEMENT, "row", "")
            ' Append row node under new root.
            Set newNode = newRoot.appendChild(newNode)
            j = 0
            ' Loop through all attributes of z:row.
            While j < rowNode.Attributes.length
                ' Create new element for column name.
                Set newNode2 = x2DOM.createNode(NODE_ELEMENT, rowNode.Attributes.Item(j).baseName, "")
                ' Assign column value to new node value.
                newNode2.Text = rowNode.Attributes.Item(j).Text
                ' Append new column node under new node.
                Set newNode2 = newNode.appendChild(newNode2)
                j = j + 1
            i = i + 1
        x2DOM.Save "C:\temp\rsCustData.xml"
    End Sub


Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The difference between theory and practice is smaller in theory than in practice.”