• 15 years ago

    I want to create a simple XML file. What is wrong with this code :


    Option Explicit
    Public mobjDOMPeople As DOMDocument
    Public m
    blnItemClicked As Boolean
    Public m_strXmlPath As String

    Sub Form_Load()

     Dim objPerson As IXMLDOMElement
     Dim objNewChild As IXMLDOMElement

     Set mobjDOMPeople = New DOMDocument
     Set objPerson = m
     objPerson.setAttribute "PERSONID", 1

     mobjDOMPeople.documentElement.appendChild objPerson
     Set objNewChild = m
     objNewChild.Text = "Your Name"
     objPerson.appendChild objNewChild
     Set objNewChild = mobjDOMPeople.createElement("ADDRESS")
     objNewChild.Text = "Your Address"
     objPerson.appendChild objNewChild
     Set objNewChild = m
     objNewChild.Text = "Your Phone"
     objPerson.appendChild objNewChild
     Set objNewChild = mobjDOMPeople.createElement("FAX")
     objNewChild.Text = "Your Fax"
     objPerson.appendChild objNewChild
     Set objNewChild = m
     objNewChild.Text = "Your Email"
     objPerson.appendChild objNewChild
     m_objDOMPeople.save ("c:\test\test.xml")
     Set objPerson = Nothing
     Set objNewChild = Nothing

    End Sub


  • 15 years ago

    What happens when you run it?  Does it give you an error message or just unexpected output?

  • 15 years ago

    Object variable or With Block Variable not set.

  • 15 years ago

    I cant see the problem sorry, but you can download sample code from here

  • 15 years ago

    Make the following change to your code:


    m_objDOMPeople.documentElement.appendChild objPerson

    changes to...


    Set m_objDOMPeople.documentElement = objPerson

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.

“Programs must be written for people to read, and only incidentally for machines to execute.”