Results 1 to 3 of 3

Thread: XML Class to read & write

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2011
    Posts
    182

    XML Class to read & write

    Hi.
    I am wondering if anyone has a drop in class that is easy to read & write nested xml files. Ive seen and got a few that read very basic xml files.
    but i am not good enough to make it read & write nested tags.

    ie
    Code:
    <config>
       <Screen>
            <Size>10</Size>
            <somethingelse>blah blah</somethingelse>
       <Screen>
       <Next setting>test</Next setting>
       <Anotherone>xxxxxxx</Anotherone>
    </config>
    tks
    Last edited by dday9; Apr 12th, 2021 at 08:13 AM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,190

    Re: XML Class to read & write

    Moved from codebank and added [code][/code] tags.

  3. #3
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,419

    Re: XML Class to read & write

    Menu option "Project" -> "References"
    Create a reference to "Microsoft XML, v6.0"

    Code:
    Private Sub Command1_Click()
      Dim oXML As MSXML2.DOMDocument60
      Dim oNode As MSXML2.IXMLDOMElement
      Dim oRoot As MSXML2.IXMLDOMElement
      
      Set oXML = New MSXML2.DOMDocument60
      Set oRoot = oXML.appendChild(oXML.createElement("config"))
      Set oNode = oRoot.appendChild(oXML.createElement("screen"))
      oNode.appendChild(oXML.createElement("Size")).Text = "10"
      oNode.appendChild(oXML.createElement("somethingelse")).Text = "blah"
      oRoot.appendChild(oXML.createElement("NextSetting")).Text = "test"
      oRoot.appendChild(oXML.createElement("Anotherone")).Text = "xxxxxxx"
      
    ' A call to Replace() to print the nodes a new line
      Debug.Print Replace(oXML.xml, "><", ">" & vbCrLf & "<")
    End Sub
    Output:
    <config>
    <screen>
    <Size>10</Size>
    <somethingelse>blah</somethingelse>
    </screen>
    <NextSetting>test</NextSetting>
    <Anotherone>xxxxxxx</Anotherone>
    </config>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width