Source: SaveDOM.frm
In this demonstration, we first create a DOM object and fill in the content by calling the loadXML
method on the object. Then, we save the object to a file named "saved.xml".
Visual Basic Source File (SaveDOM.frm)
Private Sub Form_Load() Dim doc As New DOMDocument50 doc.async = False doc.validateOnParse = False doc.resolveExternals = False doc.loadXML _ "<?xml version='1.0'?>" + vbNewLine + _ "<doc title='test'>" + vbNewLine + _ " <page num='1'>" + vbNewLine + _ " <para title='Saved at last'>" + vbNewLine + _ " This XML data is finally saved." + vbNewLine + _ " </para>" + vbNewLine + _ " </page>" + vbNewLine + _ " <page num='2'>" + vbNewLine + _ " <para>" + vbNewLine + _ " This page is intentionally left blank." + vbNewLine + _ " </para>" + vbNewLine + _ " </page>" + vbNewLine + _ "</doc>" + vbNewLine Path = App.Path + "\saved.xml" doc.save Path End Sub
To add SaveDOM.frm to the project
- Copy the code listing above. Paste it into the Visual Basic code editor as the form_load subroutine, replacing any code fragments that are already there.
Next, run the project. The result should be the output shown in the following topic.