473,388 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Need help coding vb.net XML file lookup

I have an XML file that contains values that my application needs, so it
knows which database to connect to. It also contains a configuration option
so that I can specify which node to return values from. For example, the XML
file is meant to return the values from node"config2", because the
"configoption" node's value is that.

I'm extremely new to XML and the code that accesses it, but from what I
could gather from materials read, I got this to work, which correctly
returns the database/server values from the XML file into VB.Net variables.

I'm glad I was able to get it to work, but surely there must be a better way
to write vb.net code to do this (?). Can anybody please help me with better
vb.net code to query the xml file? There's a real business need for the
"configoption" part, but the vb.net code and rest of the xml file is fair
game and can be modified as you see fit.

For example, I'm using the InnerText property...that's can't be the best way
right? From the help file, it says it returns the concatenated values of the
node and all its children. Since that node has only 1 child, this works for
now. But this is where I need help...and some better coding help which I
hope will help me to better understand. Thanks for any assistance, as I am a
total newbie to XML and I believe that sample code, within the context of a
real world need, is a great learning tool. Any suggestions are welcome.
Thanks.

Here's the XML file...

<?xml version="1.0" encoding="utf-8" ?>
<config>
<configoption>config2</configoption>
<config1>
<SQLServer>Server1</SQLServer>
<SQLDatabase>Database1</SQLDatabase>
</config1>
<config2>
<SQLServer>Server2</SQLServer>
<SQLDatabase>Database2</SQLDatabase>
</config2>
</config>

Sub SampleXMLGetValues()

' Return the connection string info from the XML file
Dim strSqlServer As String
Dim strSqlDatabase As String
Dim szXMLFile As String = "D:\_Test\SqlConfig.xml"
' Load the XML file
Dim oXMLDoc As New System.XML.XmlDocument
Dim oNode As XmlNode
oXMLDoc.Load (szXMLFile)
oNode = oXMLDoc.GetElementsByTagName("config").Item(0)

' Based on the configuration option value, decide which node to retrieve
values from
Dim strConfigOption As String
Dim n As XmlNode
For Each n In oNode
If Strings.StrComp(n.Name, "configoption", CompareMethod.Text) = 0
Then
strConfigOption = n.InnerText
End If
Next

' Set the SQL database values
For Each n In oNode
If Strings.StrComp(n.Name, strConfigOption, CompareMethod.Text) = 0
Then
' Return the values within each relevant node of the config
option
strSqlServer = n.Item("SQLServer").InnerText
strSqlDatabase = n.Item("SQLDatabase").InnerText
End If
Next

End Sub
Feb 7 '07 #1
2 2434
Have you looked at using dataset(s) with DataSet.ReadXML(path) ? I
just used this with great success in my first XML-enabled program.
Very simple to get your arms around.

Feb 7 '07 #2
Good point! However I'm hoping someone will help show me the way to do this
by direct query.
Thanks.

"Michael_R_Banks" <mi***********@satx.rr.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Have you looked at using dataset(s) with DataSet.ReadXML(path) ? I
just used this with great success in my first XML-enabled program.
Very simple to get your arms around.

Feb 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting...
12
by: teoryn | last post by:
I've been spending today learning python and as an exercise I've ported a program I wrote in java that unscrambles a word. Before describing the problem, here's the code: *--beginning of file--*...
7
by: Shyguy | last post by:
I have an option group with about 30 options. I would like to have the Option Labels get their text from a table. Is this possible, and if so how? Also, is it possible to embad a font into a...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
1
by: bhups | last post by:
hi, i am doing a lookup using hash table. I have a pipe delimited file that i have to search for a new invocie number field by checking of an old invoice number-customer number key combination...
22
by: mrkafk | last post by:
Hello everyone, I have written this small utility function for transforming legacy file to Python dict: def lookupdmo(domain): lines = open('/etc/virtual/domainowners','r').readlines()...
6
by: mathieu | last post by:
Hi there I am trying to provide a lookup from two 'int's into a char array, something like this: template <int g, int estruct Lookup; template <struct Lookup<0,0{ // some typedef + enums...
1
by: Constantine AI | last post by:
I am wanting to import CSV files into Access, which isn't a problem at the moment the code i have is as follows: Dim strSQL As String Dim CSVTable As String Dim FilePath As String ...
3
by: Eric_Dexter | last post by:
I am trying to take some data in file that looks like this command colnum_1 columnum_2 and look for the command and then cange the value in the collum(word) number indicated. I am under...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.