473,656 Members | 2,756 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.chica goserver.com</host>
<user>manager A</user>
<password>ceoma n</password>
<db>dbCEO</db>
</mssqlChicago>
<mssqlLA>
<host>www.LAser ver.com</host>
<user>manager B</user>
<password>lam an </password>
<db>dbLAWork</db>
</mssqlLA>
</server>

Any sample code to read these 2 nodes from the xml file?
Feb 7 '07 #1
3 1672
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.GetAtt ribute("host"); or whatever u want to take
private XmlElement myElemet;
private void LoadDataGrid()
{
myDs = new DataSet();
myDs.ReadXml("m yXML.xml");
dataGrid1.DataS ource = myDs.Tables[0];
}
private void LoadXML(){
myDoc.Load("you r_file.xml");
}
private void Form1_Load(obje ct sender, System.EventArg s e){
LoadDataGrid();
LoadXML();
}
Alan T yazdi:
This is my xml file content:

<?xml version="1.0"?>
<server>
<mssqlChicago >
<host>www.chica goserver.com</host>
<user>manager A</user>
<password>ceoma n</password>
<db>dbCEO</db>
</mssqlChicago>
<mssqlLA>
<host>www.LAser ver.com</host>
<user>manager B</user>
<password>lam an </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(Appli cation.StartupP ath + "\\xml.xml" );
XmlNodeList nodes = xdoc.SelectNode s("server");

foreach(XmlNode node in nodes)
{
//print node["mssqlChica go"].ChildNodes["host"].InnerText)
//print node["mssqlChica go"].ChildNodes["user"].InnerText)
//print
node["mssqlChica go"].ChildNodes["password"].InnerText)
//print node["mssqlChica go"].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.auw rote in message
news:ON******** ******@TK2MSFTN GP04.phx.gbl...
This is my xml file content:

<?xml version="1.0"?>
<server>
<mssqlChicago >
<host>www.chica goserver.com</host>
<user>manager A</user>
<password>ceoma n</password>
<db>dbCEO</db>
</mssqlChicago>
<mssqlLA>
<host>www.LAser ver.com</host>
<user>manager B</user>
<password>lam an </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
5317
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
2274
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 supposed to change the buffer size and see how this affects the read time. In other words, the buffer is supposed to limit how much of the file gets read per call, and cause some change in speed. I am supposed to do the same with fread as well, but...
1
6739
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 CLogHandler() { this.m_fsLog = new FileStream(strTodaysLogFile, System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read); this.m_swLog = new StreamWriter(this.m_fsLog);
4
2733
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 Main()
8
23899
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
3300
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 namespace std; int read(string filename, int last_pos) {
0
5778
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 17640 every times., and i set byte read=new byte, i have the wav format paper, but i don't know how to read the data correctly into the byte array, and used for doing DFT.... here's my code, and i am little hurry...thanks for the helps first~
6
32881
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). Is there some way to burst read the whole file and later "extract" each line? Thanks in advance, Thomas Kowalski
9
7381
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 to read was maindata.xml . I cannot however seem to use the gzip module correctly. Have tried the program 2 ways for no success, any ideas would be appreciated. Attempt 1 #!/usr/bin/python
2
5446
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 is several GB in size. When it comes time to read the 5+GB file from inside the zip file, it fails with the following error: File "...\zipfile.py", line 491, in read bytes = self.fp.read(zinfo.compress_size) OverflowError: long it too large to...
0
8297
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8498
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8600
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1600
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.