Loading XML data into TextBox... Help Requested :(

Trying to load an XML entry into a textbox...

Page 1 of 1

1 Replies - 18487 Views - Last Post: 04 January 2009 - 10:26 AM Rate Topic: -----

#1 fr4gory  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 03-January 09

Loading XML data into TextBox... Help Requested :(

Post icon  Posted 04 January 2009 - 08:12 AM

I have an webbrowser, and I want to save the start page into an XML file...

I have a textbox where I can input the start page url and an "apply" button, I got the apply button to work, and the URL saves into my_start_url.xml.

With this code [that works perfect]
 ' The XmlTextWriter that will build the XML file
		Dim myXmlWriter As New Xml.XmlTextWriter(Application.StartupPath + "\my_start_url.xml", Nothing)

		' Start writing the document
		' Add the root node

		myXmlWriter.WriteAttributeString("string", Nothing, Me.HomeUrl.Text)

		' Write the end elements and finish writing the document

So I can save the text box input in the XML file, but now I'm working on displaying the XML data into the text box.
And it's not going so well :( What I actually want to achieve is that the same text box used to make the my_start_url.xml can load the xml entry into the text box when the Options form loads. If any questions regarding this, then please feel free to ask.

I used the following code [wich doesn't work right, see the File Attachment]
	Private Sub Options_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		' Create a new instance of XmlDocument
		Dim myXmlDocument As Xml.XmlDocument = New Xml.XmlDocument()

		' This will handle XML nodes in the XML file
		Dim myNode As Xml.XmlNode

		' This will contain the URL from the XML attribute
		Dim URL As String

		' Load the XML document
		myXmldocument.Load(Application.StartupPath + "\my_start_url.xml")

		' Load the URL into the textbox.

		URL = myNode.Attributes("string").InnerText
		HomeUrl.Text = URL

	End Sub

Here's the XML file "my_start_url.xml"
  <?xml version="1.0" ?> 
- <urls>
  <url string="http://www.cilisoft.tk" /> 

Can anyone help me please? I would really appreciate that loads! Thank you

Attached image(s)

  • Attached Image
  • Attached Image

This post has been edited by fr4gory: 04 January 2009 - 08:39 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Loading XML data into TextBox... Help Requested :(

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 782
  • View blog
  • Posts: 5,101
  • Joined: 08-December 08

Re: Loading XML data into TextBox... Help Requested :(

Posted 04 January 2009 - 10:26 AM

Before you can use the XML node and actually read a string from one of its attributes, you have to select the node. In this case, if you need to select only one node and assign it to myNode, you should use this code:

		myNode = myXmldocument.SelectSingleNode("/urls/url")

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1