0

On load my program executes the following code to establish if an XML file already exists, and if not, creates one:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If IO.File.Exists("Dictionary.xml") = False Then

        Dim Dictionary As XDocument = <?xml version="1.0" encoding="utf-8"?>
                                      <Root></Root>

            MessageBox.Show("XML dictionary file created.")
    End If
End Sub

I'm then trying to get user input from 4 textboxes to be appended to this xml file for each word. I've got so far, but can't find a good example of how to do this.

    Private Sub Save_Data_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save_Data.Click

    Dim Dictionary As XDocument = XDocument.Load("Dictionary.xml")
    Dictionary.Add
    <Word>
        <English>Textbox1.Text</English>
        <Transcription>Textbox2.Text</Transcription>
        <Meaning>Textbox3.Text</Meaning>
        <Sound>Textbox4.Text</Sound>
    </Word>

End Sub

1 Answer 1

1
Dictionary.Root.Add( _
    New XElement("Word",Textbox1.Text, _
        New XElement("English",Textbox1.Text), _
        New XElement("Transcription",Textbox2.Text), _ 
        New XElement("Meaning",Textbox3.Text), _ 
        New XElement("Sound",Textbox4.Text))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.