Reading from an XML in VB.Net - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Reading from an XML in VB.Net

DenKainDenKain Posts: 17Member
Okay all I want to do is read from one line on the XML....JUST ONE LINE. *sigh* I can't find a tut anywhere on the internet they tells me how to use the read function to do this. What I really want to do is to compare user inputted data from a text box to one element in the XML. EX: The user enters the name John; I hash that value using MD5 then check to see if the value is the same in the XML. Something like

[Semi-Pseudo code]
Dim user as HashValue (txtUser.txt)
If user = element name Then
Blah, blah, blah, etc...
[/Semi-Pseudo code]

But I can't read just on element. Help please.

Comments

  • tpwellstpwells Posts: 15Member
    : Okay all I want to do is read from one line on the XML....JUST ONE LINE. *sigh* I can't find a tut anywhere on the internet they tells me how to use the read function to do this. What I really want to do is to compare user inputted data from a text box to one element in the XML. EX: The user enters the name John; I hash that value using MD5 then check to see if the value is the same in the XML. Something like
    :
    : [Semi-Pseudo code]
    : Dim user as HashValue (txtUser.txt)
    : If user = element name Then
    : Blah, blah, blah, etc...
    : [/Semi-Pseudo code]
    :
    : But I can't read just on element. Help please.
    :

    Right off I cant think of how to pull one line only out of an XML file without reading the file or at least the file up to the point that the line is encountered. Although there is probably a way in the System.Xml Namespace somewhere.

    I think I heard or read somewhere that .NET 2005 will support a feature like that where you could query an xml like you do a database. I am not sure of this or not, but to my knowledge in the current .NET versions XML Files need to be loaded and read through either by an XML parser or your code to get data from it. Unless you are wanting to do something like a FileStream and ReadLine() until you get to the right one but using a XmlTextReader would be faster and make it easier to read the data.

    My advice appears to be the same as others you have described use the System.Xml.XmlTextReader to perform this

    Dim xr as New System.Xml.Xml.TextReader(YourXmlFile)'or load XmlFragment
    do while xr.read
    If xr.NodeType=System.Xml.XmlNodeType.Element Then
    If xr.Name==user Then
    Dim input As String = xr.ReadString()
    'Do your code MD5 Comparison
    Exit Loop ' so you stop reading the file and no extra processing is done
    End If
    End If
    loop
    xr.Close


    Hope this helps, sorry if it doesn't
Sign In or Register to comment.