Print Page | Close Window

Reading XML

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=1799
Printed Date: 28 March 2026 at 2:24am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Reading XML
Posted By: Stevo
Subject: Reading XML
Date Posted: 13 April 2003 at 8:40am

Hi there!

Just wondering if anyone can help me out here... I am trying to read XML using an ASP.NET page.  Basically, the XML file stores a whole heap of values, and we want to read them in to allow for easy updates.  Trouble is, i am having trouble finding much info on reading xml into variables.  Most examples use datagrid, and from what i've seen of that, it looks pretty limited - more for just outputting to the screen.

If anyone can shed any light, or point me to a good source of info on the net, that would be really great and muchas appreciated.

Thanks heaps,
Steve




Replies:
Posted By: michael
Date Posted: 13 April 2003 at 9:32am

Simple. Lets say you got an xml file as follows:
<?xml version="1.0" encoding="utf-8" ?>
<myroot>
<myvalue1 value="Whatever" />
<myvalue2 value="not sure" />
</myroot>

You can read the value of myvalue1 into a variable as follows:

Dim reader As XmlTextReader = New XmlTextReader("c:\xmlfile.xml")
        While reader.Read()
            If XmlNodeType.Element Then
                If reader.Name = "myvalue1" Then
                    reader.MoveToAttribute("value")
                    myvar = reader.Value                'Make sure to declare
                    reader.Close()
                End If
            End If
        End While



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Stevo
Date Posted: 16 April 2003 at 2:45am

Thanks Michael,

That looks great.  I haven't had a chance to try it yet, as i am doing another sub-project right at the moment, but i will give it a go as soon as i can and let you know.  Hopefully, i will be able to get my brain around it for a multiple tiered XML file.

Many thanks,
Steve
Smile




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net