473,472 Members | 1,717 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Simple Store and Retrieve with XML (using C#)

Hello.

I want to store some system settings in XML, but I am new to it. So
far, I am able to retrieve the attributes, but not the elements they
belong to (I hope my terminology is right). For example, I can
retrieve "Clear", "AV1", "AV2", "BB", and "BB2" from the XML file
below using this code, but I have no idea if they belong to the
"GLOBAL", "AVIS", or "BOATING" elements. Can anyone tell me how to
retrieve the element name, and while I'm at it, connect the dots? I'm
open to different code, in case I'm doing it all wrong.

Thanks in advance for any help.

-Brian
Here's my code:

XmlTextReader r = new XmlTextReader ("speedbar.xml");
while (r.Read()) {
if (r.NodeType == XmlNodeType.Text)
Console.WriteLine (r.Value);
}
r.Close();
Here's my XML file:

<?xml version="1.0"?>
<ConfigurationSettings>

<System SystemID="GLOBAL">
<CLEAR>Clear</CLEAR>
</System>

<System SystemID="AVIS">
<AV1>AV1</AV1>
<AV2>AV2</AV2>
</System>

<System SystemID="BOATING">
<BB>BB</BB>
<BB2>BB2</BB2>
</System>
</ConfigurationSettings>
Nov 12 '05 #1
1 7912
Han
Something like,

static void Main(string[] args)
{
XmlDocument doc=new XmlDocument();
doc.Load("c:/x.xml");

foreach ( XmlNode n in doc.SelectNodes("*/*") )
{
Console.WriteLine("attribute;{0}", n.Attributes[0].InnerText);
Console.WriteLine("node;{0}", n.FirstChild.InnerText);
}

Console.Read();
}

XmlDocument is convenient. At the cost of performance/memory.

"Brian" <br*********@ky.gov> wrote in message
news:63**************************@posting.google.c om...
Hello.

I want to store some system settings in XML, but I am new to it. So
far, I am able to retrieve the attributes, but not the elements they
belong to (I hope my terminology is right). For example, I can
retrieve "Clear", "AV1", "AV2", "BB", and "BB2" from the XML file
below using this code, but I have no idea if they belong to the
"GLOBAL", "AVIS", or "BOATING" elements. Can anyone tell me how to
retrieve the element name, and while I'm at it, connect the dots? I'm
open to different code, in case I'm doing it all wrong.

Thanks in advance for any help.

-Brian
Here's my code:

XmlTextReader r = new XmlTextReader ("speedbar.xml");
while (r.Read()) {
if (r.NodeType == XmlNodeType.Text)
Console.WriteLine (r.Value);
}
r.Close();
Here's my XML file:

<?xml version="1.0"?>
<ConfigurationSettings>

<System SystemID="GLOBAL">
<CLEAR>Clear</CLEAR>
</System>

<System SystemID="AVIS">
<AV1>AV1</AV1>
<AV2>AV2</AV2>
</System>

<System SystemID="BOATING">
<BB>BB</BB>
<BB2>BB2</BB2>
</System>
</ConfigurationSettings>

Nov 12 '05 #2

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

Similar topics

2
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into...
0
by: Senthil Kannan | last post by:
Hi all, Currently i have a FORM_BASED Authentication of tomcat5.0 to store and retrieve passwords in my homepage.Now when i try to Store my password in a encrypted form i am having some problems,i...
1
by: thejackofall | last post by:
Hi. I am having a problem doing a simple sorting. Would someone be cool enough to take a look and advise? It doesn't sort. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
1
by: Kenny ODell | last post by:
I am struggling a bit with XML, even as I wade through endless help files and several books. I thought it would be useful to toss my particular needs to the group to see what you think is the best...
5
by: Roy Gourgi | last post by:
Hi, I am used to working in Visual FoxPro and I would like to be able to create a database and store and retrieve information from it. What is the simplest way to do it and what should I be...
6
by: Rudy | last post by:
Hello all! I am amazed how many posts I have read to store an image in SQL, and just as many against it. So I learned how to store an image in a SQL db and retrieve the image. A little tricky,...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
3
by: Solution Seeker | last post by:
I want to Store the String value with Single Quotes in the Field of Database where if i try to Store the String value with Single Quotes (as it is) then it is throwing the error as SQL String...
7
by: laptopia | last post by:
I need to build, very quickly, implement a form that will add to a database two text fields and store store an image associated with this record. All my experience with this is from ASP and...
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,...
1
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
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...
0
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,...
1
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: 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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.