|
-
Aug 26th, 2009, 07:24 AM
#1
Thread Starter
Hyperactive Member
Reading An XML File
Hi GUys,
i have my .xml files written like:
vb.net Code:
<?xml version="1.0" encoding="utf-8"?>
<hiddenFields>
<hiddenFieldsIDNumber0>sta</hiddenFieldsIDNumber0>
<hiddenFieldsIDNumber1>mand</hiddenFieldsIDNumber1>
</hiddenFields>
I'm trying to read the values but i'm not having much luck, i have this:
vb.net Code:
Function functionLoadHiddenFields(ByVal fileLocation As String)
Try
'// Check if the file exists
If File.Exists(fileLocation) Then
'// Load the xml document
Dim XMLDoc As New Xml.XmlDocument
'// Find and load the XML file
XMLDoc.Load(fileLocation)
'// Tell where to look for the data we need
Dim XMLItem As Xml.XmlNode = XMLDoc.SelectSingleNode("hiddenFields/")
Else
'// oops, the file is missing or wasn't written!
MessageBox.Show("A file is missing that we need to use!, please restart the program", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
Return False
End Try
End Function
i'm not to sure how to get the individual values, any help would be great!
thanks guys
Graham
Last edited by graham23s; Aug 26th, 2009 at 07:28 AM.
-
Aug 26th, 2009, 07:39 AM
#2
Re: Reading An XML File
To read an xml file, you want to use the XmlReader class instead of the XmlDocument class.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Aug 26th, 2009, 11:19 AM
#3
Hyperactive Member
Re: Reading An XML File
You can find a entry in the VB.NET codebank about reader/writing xml.
-
Aug 26th, 2009, 11:56 AM
#4
Re: Reading An XML File
look at the .hasChildren property as well as the .firstChild one...
-tg
-
Aug 26th, 2009, 02:49 PM
#5
Re: Reading An XML File
Here are a couple XPATH samples
Code:
'get hiddenFields node
Dim xmlItem = XMLDoc.SelectSingleNode("hiddenFields")
'get hiddenFields child nodes
For Each xmlItem In XMLDoc.SelectNodes("hiddenFields/*")
Next
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|