473,385 Members | 1,867 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,385 software developers and data experts.

Reading an XML file into a collection

Hello

I've created the following XML file:
<?xml version="1.0" encoding="utf-8"?>
<Company>
<Languages>
<Language>
<Name>English</Name>
<Code>1234</Code>
<Connect>54</Flag>
</Language>
<Language>
<Name>French</Name>
<Code>4567</Code>
</Language>
</Languages>
</Company>

I've also created a Language class that has the following properties
- string Name
- int Code
- int Connect

And a Language collection class called LanguageCollection.

Can someone please tell me what is the easiest / best way is to read the
values from the XML file and store them in a collection of Language of
objects.

Please note that not ever Language will be fully populated in the XML file.
For example, the French language doesn't have a Connect value in the above
XML file
Thank you for your help.
Jan 18 '08 #1
2 4613
Mark Collard <Ma*********@discussions.microsoft.comwrote:

<snip>
Can someone please tell me what is the easiest / best way is to read the
values from the XML file and store them in a collection of Language of
objects.
Which version of .NET are you using? With .NET 3.5 you can use LINQ to
XML, which will make life *much* easier.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 18 '08 #2
Create XML-Serializable classes. Use the XML format which they produce when
serialized. Then you can just deserialize the XML back to class instances.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

"Mark Collard" <Ma*********@discussions.microsoft.comwrote in message
news:B3**********************************@microsof t.com...
Hello

I've created the following XML file:
<?xml version="1.0" encoding="utf-8"?>
<Company>
<Languages>
<Language>
<Name>English</Name>
<Code>1234</Code>
<Connect>54</Flag>
</Language>
<Language>
<Name>French</Name>
<Code>4567</Code>
</Language>
</Languages>
</Company>

I've also created a Language class that has the following properties
- string Name
- int Code
- int Connect

And a Language collection class called LanguageCollection.

Can someone please tell me what is the easiest / best way is to read the
values from the XML file and store them in a collection of Language of
objects.

Please note that not ever Language will be fully populated in the XML
file.
For example, the French language doesn't have a Connect value in the above
XML file
Thank you for your help.

Jan 18 '08 #3

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

Similar topics

14
by: deko | last post by:
Do I need to use flock() when reading a file into an array? It's possible that the file in question could be open at the time the file('filename') request is made. I realize flock() is required...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
11
by: Matt DeFoor | last post by:
I have some log files that I'm working with that look like this: 1000000000 3456 1234 1000000001 3456 1235 1000020002 3456 1223 1000203044 3456 986 etc. I'm trying to read the file...
2
by: archana | last post by:
Hi all, I am new to asp.net (learning phase). I have to develop application in asp.net to read file from client pc and display statistics of that file to client. So my question is that to...
2
by: MSDN | last post by:
Hello, I have the following code below that does not work for me because the directory has millions of files. foreach (string ofile in System.IO.Directory.GetFiles(strMyDir)) { ...
3
by: miss time | last post by:
Hi all, my java friends ^-^ I have next week quiz in reading file text ,and understand the topic very well. can any one give some question related to this topic .this help me more to...
6
by: Studlyami | last post by:
Is it possible to open a file for reading, while another process has it open for writing to it? One of the problems is that the process that is writing to it is written in C and is running on a...
1
Coldfire
by: Coldfire | last post by:
Hi, The strange problem i am having is, the input element of type='file' not reading file names after 20 file elements. It simple returns null on reading the 'name' of file. The code is...
1
by: bjoarn | last post by:
I have an Application C# handling file reading, building index on this file, using dll wrapped with SWIG. The dll is originaly programmed in C++. Dll reports back to the the C# programm throug...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.