XML File in VB.NET

I have tried many different ways to write and read to and from a XML file.

But does anybody have a simple way to do the following?

On startup, I type text into a textbox, I want to be able to save this text to a XML file. I also want to be able to select from three radio buttons. and write this selection to the same XML file but under a different XMLnode.

Then, when I re-run the app, the text box is populated and the radio button is selected to what I had previously set it to.

Any ideas?
LVL 6
cjinsocal581Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cjinsocal581Author Commented:
HEre is my Save to XML function:
_____________________________________________
    Private Sub SaveItemsXML()
        Dim xmlSAVE As New XmlTextWriter(fileName, Encoding.ASCII)

        xmlSAVE.Formatting = Formatting.Indented
        xmlSAVE.WriteStartDocument()
        xmlSAVE.WriteComment("Item List Created With XMLTextWriter")
        xmlSAVE.WriteStartElement("items")
       
        Dim line As String
        If RadioButton11.Checked = True Then
            line = "True"
        Else
            line = "False"
        End If
        xmlSAVE.WriteElementString("radiobuttons", line)
        xmlSAVE.WriteElementString("fromlocation", txtPathLoc.Text)
       
        xmlSAVE.WriteEndElement()
        xmlSAVE.Close()
        MsgBox("Settings Saved to XML File")
    End Sub
_______________________________________________________________
0
cjinsocal581Author Commented:
Oh, and it works the way I need it to.

Now, I just need to read from it, and populate the elements needed.
0
S-TwilleyCommented:
Hi, here's a brief set of lines to get you started on how to read from a file:

Firstly... this is some sample xml that im reading from...

<settings>
    <PresetRules>
         <rule name="Rule1">BLAH BLAH</rule>
         <rule name="Rule2">BLAH BLAH and then some</rule>
         <rule name="Rule3">BLAH BLAH and a bit more</rule>
    </PresetRules>
    <OtherRules>
         <rule name="Rule1">BLAH BLAH</rule>
         <rule name="Rule2">BLAH BLAH and then some</rule>
         <rule name="Rule3">BLAH BLAH and a bit more</rule>
    </OtherRules>

</settings>


            Dim xSettings As New XmlDocument()
            Dim nodeRoot, nodePresets, nodeOther, nodeChild as XMLNode
            xSettings.Load("mysettings.xml")

            nodeRoot = xSettings.SelectSingleNode("//settings")
            nodePresets = nodeRoot.SelectSingleNode("//PresetRules")
            nodeOther = nodeRoot.SelectSingleNode("//OtherRules")

            For each nodeChild in nodePresets
                msgbox(nodeChild.Attributes("name").InnerText)
                msgbox(nodeChild.innerXML)
            Next

            For each nodeChild in nodeOther
                msgbox(nodeChild.Attributes("name").InnerText)
                msgbox(nodeChild.innerXML)
            Next

There are obviously plenty of other bits, but this should help
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

S-TwilleyCommented:
If you need help in interpreting the values so it sets the textbox and radio buttons... or anything else, just ask.
0
S-TwilleyCommented:
           Dim xSettings As New XmlDocument()
            Dim nodeRoot, nodeRadio, nodeFrom as XMLNode
            xSettings.Load(filename)

            nodeRoot = xSettings.SelectSingleNode("//items")
            nodeRadio = nodeRoot.SelectSingleNode("//radiobuttons")
            nodeFrom = nodeRoot.SelectSingleNode("//fromlocation")

            if nodeRadio.innerText = "True" Then
                 RadioButton11.Checked = True
            Else
                 RadioButton11.Checked = False
            End If

            txtPathLoc.Text = nodeFrom.innerText

==============

Now I think that's what would be your "loading".  Just a note... im not sure how the xmlwriter handles writing characters like < >  or other markup characters, whether it escapes them or not, but just take note when writing with certain characters, and when reading them... might find some  differences (although im not sure)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cjinsocal581Author Commented:
Perfect. Thanks!!
0
cjinsocal581Author Commented:
By the way, how should the XML File look now?
0
cjinsocal581Author Commented:
The reason I ask is, I am now getting a system error with the XML library.
0
S-TwilleyCommented:
where are you getting an error?
0
cjinsocal581Author Commented:
Sorry, there was too many references to one XML file.

Everything works correctly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.