VB & XML

  • 11 years ago

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


    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
    objDOMPeople.createElement("PERSON")
     objPerson.setAttribute "PERSONID", 1


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


    End Sub



    Thanks.

  • 11 years ago

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

  • 11 years ago

    Object variable or With Block Variable not set.



  • 11 years ago

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

  • 11 years ago

    Make the following change to your code:


    Code:

    m_objDOMPeople.documentElement.appendChild objPerson


    changes to...


    Code:

    Set m_objDOMPeople.documentElement = objPerson

Post a reply

Enter your message below

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

Contribute

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.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook