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

Reading / Writing XML's - noob question

I'm baaaaack... some of you answered a question I had last week. Only
problem is: I'm a dope who doesn't understand most of what y'all posted. Raw
noob when it comes to .Net and C#.

So I'm going to be more specific... All I need to do at the moment is figure
out how to replace our usage of .ini files as configuration files for our
small, utility type apps. I'm not looking to use XML as a data stream or
anything like that. Not right now, anyway...

So... let's say I've got this ini file:

[OS]
OS1 = "Windows 2000"
OS2 = "Windows XP"
OS3 = "Windows Vista"

[RAM]
RAM1 = "256MB"
RAM2 = "512MB"
RAM3 = "1GB"

[Model]
Mod1 = "D620"
Mod2 = ""
Mod3 = ""

Which I -think- translates to something like this in XML:

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <section name="OS">
<setting name="OS1" value=""Windows 2000"" />
<setting name="OS2" value=""Windows XP"" />
<setting name="OS3" value=""Windows Vista"" />
</section>
- <section name="RAM">
<setting name="RAM1" value=""256MB"" />
<setting name="RAM2" value=""512MB"" />
<setting name="RAM3" value=""1GB"" />
</section>
- <section name="Model">
<setting name="Mod1" value=""D620"" />
<setting name="Mod2" value="""" />
<setting name="Mod3" value="""" />
</section>
</configuration>

All I want to know is: 1. How to read, say, OS2 out of the OS section. 2.
How to insert a RAM4 setting name with the value of "2GB" 3. How to modify
the value of Mod2. I suppose all that goes out the window if the structure
of the XML file in incorrect...

At any rate, all responses greatly appreciated in advance!

Thanks,

Lang
Jun 26 '07 #1
6 1612
Lang,

There is no definitive way to translate an INI file to an XML file.

Why not just use the same INI files and then call the INI file functions
through the P/Invoke layer?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lang Murphy" <la*********@hotmail.comwrote in message
news:63**********************************@microsof t.com...
I'm baaaaack... some of you answered a question I had last week. Only
problem is: I'm a dope who doesn't understand most of what y'all posted.
Raw noob when it comes to .Net and C#.

So I'm going to be more specific... All I need to do at the moment is
figure out how to replace our usage of .ini files as configuration files
for our small, utility type apps. I'm not looking to use XML as a data
stream or anything like that. Not right now, anyway...

So... let's say I've got this ini file:

[OS]
OS1 = "Windows 2000"
OS2 = "Windows XP"
OS3 = "Windows Vista"

[RAM]
RAM1 = "256MB"
RAM2 = "512MB"
RAM3 = "1GB"

[Model]
Mod1 = "D620"
Mod2 = ""
Mod3 = ""

Which I -think- translates to something like this in XML:

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <section name="OS">
<setting name="OS1" value=""Windows 2000"" />
<setting name="OS2" value=""Windows XP"" />
<setting name="OS3" value=""Windows Vista"" />
</section>
- <section name="RAM">
<setting name="RAM1" value=""256MB"" />
<setting name="RAM2" value=""512MB"" />
<setting name="RAM3" value=""1GB"" />
</section>
- <section name="Model">
<setting name="Mod1" value=""D620"" />
<setting name="Mod2" value="""" />
<setting name="Mod3" value="""" />
</section>
</configuration>

All I want to know is: 1. How to read, say, OS2 out of the OS section. 2.
How to insert a RAM4 setting name with the value of "2GB" 3. How to modify
the value of Mod2. I suppose all that goes out the window if the structure
of the XML file in incorrect...

At any rate, all responses greatly appreciated in advance!

Thanks,

Lang


Jun 26 '07 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:us**************@TK2MSFTNGP02.phx.gbl...
Lang,

There is no definitive way to translate an INI file to an XML file.

Why not just use the same INI files and then call the INI file
functions through the P/Invoke layer?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lang Murphy" <la*********@hotmail.comwrote in message
news:63**********************************@microsof t.com...
>I'm baaaaack... some of you answered a question I had last week. Only
problem is: I'm a dope who doesn't understand most of what y'all posted.
Raw noob when it comes to .Net and C#.

So I'm going to be more specific... All I need to do at the moment is
figure out how to replace our usage of .ini files as configuration files
for our small, utility type apps. I'm not looking to use XML as a data
stream or anything like that. Not right now, anyway...

So... let's say I've got this ini file:

[OS]
OS1 = "Windows 2000"
OS2 = "Windows XP"
OS3 = "Windows Vista"

[RAM]
RAM1 = "256MB"
RAM2 = "512MB"
RAM3 = "1GB"

[Model]
Mod1 = "D620"
Mod2 = ""
Mod3 = ""

Which I -think- translates to something like this in XML:

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <section name="OS">
<setting name="OS1" value=""Windows 2000"" />
<setting name="OS2" value=""Windows XP"" />
<setting name="OS3" value=""Windows Vista"" />
</section>
- <section name="RAM">
<setting name="RAM1" value=""256MB"" />
<setting name="RAM2" value=""512MB"" />
<setting name="RAM3" value=""1GB"" />
</section>
- <section name="Model">
<setting name="Mod1" value=""D620"" />
<setting name="Mod2" value="""" />
<setting name="Mod3" value="""" />
</section>
</configuration>

All I want to know is: 1. How to read, say, OS2 out of the OS section. 2.
How to insert a RAM4 setting name with the value of "2GB" 3. How to
modify the value of Mod2. I suppose all that goes out the window if the
structure of the XML file in incorrect...

At any rate, all responses greatly appreciated in advance!

Thanks,

Lang



OK... are you saying the XML example here is not well formed or valid? I
mean... LOL, using the P/invoke layer is a bit beyond my comprehension at
this point in time.

And... thanks for the response!

Lang

Jun 26 '07 #3
On Jun 26, 10:56 am, "Lang Murphy" <lang_mur...@hotmail.comwrote:
I'm baaaaack... some of you answered a question I had last week. Only
problem is: I'm a dope who doesn't understand most of what y'all posted. Raw
noob when it comes to .Net and C#.

So I'm going to be more specific... All I need to do at the moment is figure
out how to replace our usage of .ini files as configuration files for our
small, utility type apps. I'm not looking to use XML as a data stream or
anything like that. Not right now, anyway...

So... let's say I've got this ini file:

[OS]
OS1 = "Windows 2000"
OS2 = "Windows XP"
OS3 = "Windows Vista"

[RAM]
RAM1 = "256MB"
RAM2 = "512MB"
RAM3 = "1GB"

[Model]
Mod1 = "D620"
Mod2 = ""
Mod3 = ""

Which I -think- translates to something like this in XML:

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <section name="OS">
<setting name="OS1" value=""Windows 2000"" />
<setting name="OS2" value=""Windows XP"" />
<setting name="OS3" value=""Windows Vista"" />
</section>
- <section name="RAM">
<setting name="RAM1" value=""256MB"" />
<setting name="RAM2" value=""512MB"" />
<setting name="RAM3" value=""1GB"" />
</section>
- <section name="Model">
<setting name="Mod1" value=""D620"" />
<setting name="Mod2" value="""" />
<setting name="Mod3" value="""" />
</section>
</configuration>

All I want to know is: 1. How to read, say, OS2 out of the OS section. 2.
How to insert a RAM4 setting name with the value of "2GB" 3. How to modify
the value of Mod2. I suppose all that goes out the window if the structure
of the XML file in incorrect...

At any rate, all responses greatly appreciated in advance!

Thanks,

Lang
Look up XPath queries on Google or visit this site which has some good
lessons:

http://www.w3schools.com/

Basically, you would use the SelectSingleNode method and pass in an
Xpath string to the node that you want. Here's an off the top of my
head example (watch for typos):

XmlNode node = rootnode.SelectSingleNode("/configuration/
section[@name='OS']/setting[@name='OS2']");
Console.WriteLine(node.Text);

So this command would select the setting node with name 'OS2' that
exists under the section node with name 'OS' that exists under the
configuration node.

If the node cannot be found, the result will be null so it's best to
check if the result is null before trying to get the value of the
node. Keep in mind that xml is case sensitive, so if you get a null
result and you know the node exists in the xml, double check your
xpath.

Hope this gives you some ideas.

Chris

Jun 26 '07 #4
Lang,

No, I'm not saying it is invalid, but rather, there is no way of saying
"these elements in the INI file correspond to these elements in the XML
file" (at least, there is no standard way that I know of). I could just as
easily represent the data in a different way.

Actually, looking at it now, the XML is not valid or well formed, but
I'm nitpicking, since you copied and pasted it from IE, it seems (and the
expand/collapse tags are there, as well as two sets of double quotes around
strings).

I would look at http://www.pinvoke.net and enter in the API functions
from whatever previous application was using the INI files. It will most
definitely return C# declarations you can use to make the same calls in your
C# app.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Lang Murphy" <la*********@hotmail.comwrote in message
news:u5**************@TK2MSFTNGP04.phx.gbl...
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:us**************@TK2MSFTNGP02.phx.gbl...
>Lang,

There is no definitive way to translate an INI file to an XML file.

Why not just use the same INI files and then call the INI file
functions through the P/Invoke layer?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lang Murphy" <la*********@hotmail.comwrote in message
news:63**********************************@microso ft.com...
>>I'm baaaaack... some of you answered a question I had last week. Only
problem is: I'm a dope who doesn't understand most of what y'all posted.
Raw noob when it comes to .Net and C#.

So I'm going to be more specific... All I need to do at the moment is
figure out how to replace our usage of .ini files as configuration files
for our small, utility type apps. I'm not looking to use XML as a data
stream or anything like that. Not right now, anyway...

So... let's say I've got this ini file:

[OS]
OS1 = "Windows 2000"
OS2 = "Windows XP"
OS3 = "Windows Vista"

[RAM]
RAM1 = "256MB"
RAM2 = "512MB"
RAM3 = "1GB"

[Model]
Mod1 = "D620"
Mod2 = ""
Mod3 = ""

Which I -think- translates to something like this in XML:

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <section name="OS">
<setting name="OS1" value=""Windows 2000"" />
<setting name="OS2" value=""Windows XP"" />
<setting name="OS3" value=""Windows Vista"" />
</section>
- <section name="RAM">
<setting name="RAM1" value=""256MB"" />
<setting name="RAM2" value=""512MB"" />
<setting name="RAM3" value=""1GB"" />
</section>
- <section name="Model">
<setting name="Mod1" value=""D620"" />
<setting name="Mod2" value="""" />
<setting name="Mod3" value="""" />
</section>
</configuration>

All I want to know is: 1. How to read, say, OS2 out of the OS section.
2. How to insert a RAM4 setting name with the value of "2GB" 3. How to
modify the value of Mod2. I suppose all that goes out the window if the
structure of the XML file in incorrect...

At any rate, all responses greatly appreciated in advance!

Thanks,

Lang




OK... are you saying the XML example here is not well formed or valid? I
mean... LOL, using the P/invoke layer is a bit beyond my comprehension at
this point in time.

And... thanks for the response!

Lang

Jun 26 '07 #5
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP03.phx.gbl...
Lang,

No, I'm not saying it is invalid, but rather, there is no way of saying
"these elements in the INI file correspond to these elements in the XML
file" (at least, there is no standard way that I know of). I could just
as easily represent the data in a different way.

Actually, looking at it now, the XML is not valid or well formed, but
I'm nitpicking, since you copied and pasted it from IE, it seems (and the
expand/collapse tags are there, as well as two sets of double quotes
around strings).

I would look at http://www.pinvoke.net and enter in the API functions
from whatever previous application was using the INI files. It will most
definitely return C# declarations you can use to make the same calls in
your C# app.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Lang Murphy" <la*********@hotmail.comwrote in message
news:u5**************@TK2MSFTNGP04.phx.gbl...
>"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:us**************@TK2MSFTNGP02.phx.gbl...
>>Lang,

There is no definitive way to translate an INI file to an XML file.

Why not just use the same INI files and then call the INI file
functions through the P/Invoke layer?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lang Murphy" <la*********@hotmail.comwrote in message
news:63**********************************@micros oft.com...
I'm baaaaack... some of you answered a question I had last week. Only
problem is: I'm a dope who doesn't understand most of what y'all
posted. Raw noob when it comes to .Net and C#.

So I'm going to be more specific... All I need to do at the moment is
figure out how to replace our usage of .ini files as configuration
files for our small, utility type apps. I'm not looking to use XML as a
data stream or anything like that. Not right now, anyway...

So... let's say I've got this ini file:

[OS]
OS1 = "Windows 2000"
OS2 = "Windows XP"
OS3 = "Windows Vista"

[RAM]
RAM1 = "256MB"
RAM2 = "512MB"
RAM3 = "1GB"

[Model]
Mod1 = "D620"
Mod2 = ""
Mod3 = ""

Which I -think- translates to something like this in XML:

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <section name="OS">
<setting name="OS1" value=""Windows 2000"" />
<setting name="OS2" value=""Windows XP"" />
<setting name="OS3" value=""Windows Vista"" />
</section>
- <section name="RAM">
<setting name="RAM1" value=""256MB"" />
<setting name="RAM2" value=""512MB"" />
<setting name="RAM3" value=""1GB"" />
</section>
- <section name="Model">
<setting name="Mod1" value=""D620"" />
<setting name="Mod2" value="""" />
<setting name="Mod3" value="""" />
</section>
</configuration>

All I want to know is: 1. How to read, say, OS2 out of the OS section.
2. How to insert a RAM4 setting name with the value of "2GB" 3. How to
modify the value of Mod2. I suppose all that goes out the window if the
structure of the XML file in incorrect...

At any rate, all responses greatly appreciated in advance!

Thanks,

Lang



OK... are you saying the XML example here is not well formed or valid? I
mean... LOL, using the P/invoke layer is a bit beyond my comprehension at
this point in time.

And... thanks for the response!

Lang


Thanks for the follow up... you're right... copied and pasted from IE. I
understand what you're saying about the format of the XML. Thanks for the
link... I'll check it out, for sure.

Lang

Jun 26 '07 #6
"Chris Dunaway" <du******@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
On Jun 26, 10:56 am, "Lang Murphy" <lang_mur...@hotmail.comwrote:
>I'm baaaaack... some of you answered a question I had last week. Only
problem is: I'm a dope who doesn't understand most of what y'all posted.
Raw
noob when it comes to .Net and C#.

So I'm going to be more specific... All I need to do at the moment is
figure
out how to replace our usage of .ini files as configuration files for our
small, utility type apps. I'm not looking to use XML as a data stream or
anything like that. Not right now, anyway...

So... let's say I've got this ini file:

[OS]
OS1 = "Windows 2000"
OS2 = "Windows XP"
OS3 = "Windows Vista"

[RAM]
RAM1 = "256MB"
RAM2 = "512MB"
RAM3 = "1GB"

[Model]
Mod1 = "D620"
Mod2 = ""
Mod3 = ""

Which I -think- translates to something like this in XML:

<?xml version="1.0" encoding="utf-8" ?>
- <configuration>
- <section name="OS">
<setting name="OS1" value=""Windows 2000"" />
<setting name="OS2" value=""Windows XP"" />
<setting name="OS3" value=""Windows Vista"" />
</section>
- <section name="RAM">
<setting name="RAM1" value=""256MB"" />
<setting name="RAM2" value=""512MB"" />
<setting name="RAM3" value=""1GB"" />
</section>
- <section name="Model">
<setting name="Mod1" value=""D620"" />
<setting name="Mod2" value="""" />
<setting name="Mod3" value="""" />
</section>
</configuration>

All I want to know is: 1. How to read, say, OS2 out of the OS section. 2.
How to insert a RAM4 setting name with the value of "2GB" 3. How to
modify
the value of Mod2. I suppose all that goes out the window if the
structure
of the XML file in incorrect...

At any rate, all responses greatly appreciated in advance!

Thanks,

Lang

Look up XPath queries on Google or visit this site which has some good
lessons:

http://www.w3schools.com/

Basically, you would use the SelectSingleNode method and pass in an
Xpath string to the node that you want. Here's an off the top of my
head example (watch for typos):

XmlNode node = rootnode.SelectSingleNode("/configuration/
section[@name='OS']/setting[@name='OS2']");
Console.WriteLine(node.Text);

So this command would select the setting node with name 'OS2' that
exists under the section node with name 'OS' that exists under the
configuration node.

If the node cannot be found, the result will be null so it's best to
check if the result is null before trying to get the value of the
node. Keep in mind that xml is case sensitive, so if you get a null
result and you know the node exists in the xml, double check your
xpath.

Hope this gives you some ideas.

Chris

Chris,

Thanks for the response. I'll check out your example code and thanks for the
link; I'll check it out.

Lang

Jun 26 '07 #7

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

Similar topics

0
by: puffy | last post by:
hi to all..this is my 1st post in here..hope to get some help..need to use asp.net/ado.net to generate data from access db into xml doc or print it on screen..i only manage to generate it using...
12
by: jcrouse | last post by:
I am using the following code to write to an XML file myXmlTextWriter.Formatting = System.Xml.Formatting.Indente myXmlTextWriter.WriteStartElement("CPViewer"...
2
by: Jacob Kroon | last post by:
I'm writing a block-diagram editor, and could use some tips about writing/reading diagrams to/from an xml file format. The basic layout of my code : class Diagram { Blocks blocks } class...
0
by: R1gg4 | last post by:
Hi all, I currently have a VB.NET application that interfaces with Word 2003 to produce documents from templates substituting the data in the template to form the document. This is all working...
1
by: Ken Browning | last post by:
I have been working with Perl for a while now, but have not used it with XML - I am an XML noob. I want to be able to read an XML schema file and initialize an instance of the data item...
4
by: David | last post by:
Hi, (Sorry for duplicate post, finger trouble before I finished...) using C# 1.1 I am writing a winform app that collects a dataset from a webservice. At the same time I collect the data,...
4
by: ramyakrishnakumar | last post by:
Hi All, I am facing some problem with basic file operation... I have one xml file looks like <?xml version="1.0" encoding="UTF-8" standalone="no" ?> <x:recording> <udf3>Gélin</udf3> ...
19
by: Hapa | last post by:
Does only reading (never writing) of a variable need thread synchronisation? Thanks for help? PS. Anybody knows a Visual C++ news group?
16
by: billsahiker | last post by:
I am researching for an upcoming c# .net 2.0 project that may require reading and writing xml files. I don't want to use xmltextreader/ xmltextwriter as I prefer to have lower level file access...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.