473,218 Members | 1,771 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,218 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 1603
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
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.