Results 1 to 6 of 6

Thread: [RESOLVED] Loading XML data into application

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Resolved [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

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Re: Loading XML data into application

    Hey Gary,

    Thanks for that mate i got it in the end lol

    cheers mate

    Graham

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    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:
    1. 'Create an instance of the XML
    2.                 Dim XMLDoc As New Xml.XmlDocument
    3.  
    4.                 'Find and load the XML file
    5.                 XMLDoc.Load(myOpenFileDialog.FileName)
    6.  
    7.                 'Tell where to look for the data we need
    8.                 Dim XMLItem As Xml.XmlNode = XMLDoc.SelectSingleNode("AccountInfoSaved/AccountInfo")

    Thanks mate

    Graham

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width