2 Replies - 10403 Views - Last Post: 12 March 2012 - 10:32 AM Rate Topic: -----

#1 m_wylie85   User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Searching an xml file

Posted 12 March 2012 - 09:47 AM

Hi all i have an xml file that looks like so:

<?xml version="1.0" encoding="utf-8" ?>
- <Details>
- <userName>
<userName>user</userName>
<Password>pass</Password>
</userName>
<Details />
- <Details>
<UserName>user</UserName>
<Password>password</Password>
</Details>
</Details>

I want to be able to search the above and check if <userName> and <Password> equals a value i input from a textbox.

my code so far:
        Dim fileName As String = "C:\Documents and Settings\mwyli005\Desktop\PasswordDetails.xml"
        Dim doc As New XmlDocument
        Dim nodes As XmlNode
        doc.Load(fileName)
        ' Scroll through the nodes
        For Each nodes In doc.SelectNodes("Details")

            ' this is where i am not sure what i should be doing

        Next

any advice would be great thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Searching an xml file

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14089
  • View blog
  • Posts: 56,441
  • Joined: 12-June 08

Re: Searching an xml file

Posted 12 March 2012 - 09:59 AM

Investigate linq to xml?

http://www.dotnetcur...cle.aspx?ID=490
Was This Post Helpful? 2
  • +
  • -

#3 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: Searching an xml file

Posted 12 March 2012 - 10:32 AM

Dim fileName As String = "C:\Documents and Settings\mwyli005\Desktop\PasswordDetails.xml"
Dim doc As New XmlDocument
Dim nodes As XmlNode
doc.Load(fileName)
' Scroll through the nodes
For Each nodes In doc.SelectNodes("Details")
'each nodes is a Detail element
node.ChildNodes(0).InnerText 'username
node.ChildNodes(1).InnerText 'password
Next


I like modi's example too.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1