473,503 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read XML file

This is my xml file content:

<?xml version="1.0"?>
<server>
<mssqlChicago>
<host>www.chicagoserver.com</host>
<user>managerA</user>
<password>ceoman</password>
<db>dbCEO</db>
</mssqlChicago>
<mssqlLA>
<host>www.LAserver.com</host>
<user>managerB</user>
<password>laman </password>
<db>dbLAWork</db>
</mssqlLA>
</server>

Any sample code to read these 2 nodes from the xml file?
Feb 7 '07 #1
3 1662
Hi there is a solution reading xml file to add dataset (i think u want
that)

private XmlDocument myDoc = new XmlDocument();
private DataSet myDs;

//Using XmlElement you can access
//host ,user etc. values
//just write myElemet.GetAttribute("host"); or whatever u want to take
private XmlElement myElemet;
private void LoadDataGrid()
{
myDs = new DataSet();
myDs.ReadXml("myXML.xml");
dataGrid1.DataSource = myDs.Tables[0];
}
private void LoadXML(){
myDoc.Load("your_file.xml");
}
private void Form1_Load(object sender, System.EventArgs e){
LoadDataGrid();
LoadXML();
}
Alan T yazdi:
This is my xml file content:

<?xml version="1.0"?>
<server>
<mssqlChicago>
<host>www.chicagoserver.com</host>
<user>managerA</user>
<password>ceoman</password>
<db>dbCEO</db>
</mssqlChicago>
<mssqlLA>
<host>www.LAserver.com</host>
<user>managerB</user>
<password>laman </password>
<db>dbLAWork</db>
</mssqlLA>
</server>

Any sample code to read these 2 nodes from the xml file?
Feb 7 '07 #2
Try something like this:

XmlDocument xdoc = new XmlDocument();
xdoc.Load(Application.StartupPath + "\\xml.xml");
XmlNodeList nodes = xdoc.SelectNodes("server");

foreach(XmlNode node in nodes)
{
//print node["mssqlChicago"].ChildNodes["host"].InnerText)
//print node["mssqlChicago"].ChildNodes["user"].InnerText)
//print
node["mssqlChicago"].ChildNodes["password"].InnerText)
//print node["mssqlChicago"].ChildNodes["db"].InnerText)
}
--

Tiago Salgado

http://weblogs.pontonetpt.com/tiagosalgado
http://www.foruns.org
http://www.portugal-a-programar.org
http://www.revista-programar.info

"Alan T" <al*************@yahoo.com.auwrote in message
news:ON**************@TK2MSFTNGP04.phx.gbl...
This is my xml file content:

<?xml version="1.0"?>
<server>
<mssqlChicago>
<host>www.chicagoserver.com</host>
<user>managerA</user>
<password>ceoman</password>
<db>dbCEO</db>
</mssqlChicago>
<mssqlLA>
<host>www.LAserver.com</host>
<user>managerB</user>
<password>laman </password>
<db>dbLAWork</db>
</mssqlLA>
</server>

Any sample code to read these 2 nodes from the xml file?

Feb 7 '07 #3
You could also get by tag name if you really wanted.

JJ
Feb 7 '07 #4

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

Similar topics

10
5302
by: Yang Li Ke | last post by:
Hi guys! I have some datas that I must check everytime a visitor comes to my site What is better to do: 1- Read data from a file or 2- Read data from a mysql db Thank you
10
2258
by: ZafT | last post by:
Thanks in advance for any tips that might get me going in the right direction. I am working on a simple exercise for school that is supposed to use read to read a file (about 10 MB). I am...
1
6721
by: cnu | last post by:
My program generates a log file for every event that happens in the program. So, I open the file and keep it open till the end. This is how I open the file for writing: <CODE> public...
4
2711
by: ESPN Lover | last post by:
Below is two snippets of code from MSDN showing how to read a file. Is one way preferred over the other and why? Thanks. using System; using System.IO; class Test { public static void...
8
23884
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
5
3282
by: lovecreatesbea... | last post by:
The condition at line 31 is added to check if the program finished to read the whole file. Is it needed and correct? Thank you. #include <fstream> #include <iostream> #include <string> using...
0
5750
by: lovecarole | last post by:
hi, i am the student who should write a program about reading wav file and do the DFT. actually i don't know how to read data of the wav song and save it into the array... if i want to read...
6
32845
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
9
7365
by: flebber | last post by:
I was working at creating a simple program that would read the content of a playlist file( in this case *.k3b") and write it out . the compressed "*.k3b" file has two file and the one I was trying...
2
5439
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
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
7322
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...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.