[RESOLVED] Loading XML data into application
Hi Guys,
I can successfully save my application data to an .xml structured file like:
Code:
<?xml version="1.0"?>
<appSaved>
<saved Firstname="Graham" Lastname="McCann" Email="[email protected]" Username="graham23s" />
</appSaved>
I was trying to do the reverse and load the data back into the textbox fields so far i have:
Code:
'Load the saved information back into the textboxes
' 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 URL into the textbox
URL = myNode.Attributes("Firstname").InnerText
firstNameTextBox.Text = URL
I can't seem to find any good tutorials on this, any help would be appreciated.
thanks guys
Graham
Re: Loading XML data into application
Hey,
How have you created the XML file? It is from a serialized class, or have you created it using an XmlWriter, or the equivalent.
For an example of what you could do, have a look at the Serialization CodeBank submission in my signature.
Alternatively, to continue down the route that you are going, you first need to find the node that you want. One way of doing this would be to pass an XPath query to the SelectNode method on the XmlDocument. You can find information on that here:
http://msdn.microsoft.com/en-us/libr...inglenode.aspx
Check my signature for additional information on XPath.
Hope that helps!!
Gary
Re: Loading XML data into application
Hey Gary,
Thanks for that mate i got it in the end lol
cheers mate
Graham
Re: [RESOLVED] Loading XML data into application
Hey,
So that others can benefit, it would be good if you can post your solution :)
Thanks
Gary
Re: [RESOLVED] Loading XML data into application
Hey Gary,
I never even though lol here it is, in 3 lines which took me 3 days to learn lol:
vb Code:
'Create an instance of the XML
Dim XMLDoc As New Xml.XmlDocument
'Find and load the XML file
XMLDoc.Load(myOpenFileDialog.FileName)
'Tell where to look for the data we need
Dim XMLItem As Xml.XmlNode = XMLDoc.SelectSingleNode("AccountInfoSaved/AccountInfo")
Thanks mate
Graham
Re: [RESOLVED] Loading XML data into application
Ha ha, that's always the way though :)
You can be sure that you won't forget it in a hurry!! Thanks for posting back, that just might be the code that someone else is looking for.
Gary