473,471 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

REading XML Tags Values

Hello All

This is my XML File,

<?xml version="1.0" encoding="utf-8" ?>
- <Authentiation>
<userId>TarunSinha</userId>
<password>sonumonu</password>
</Authentiation>
I want to read the XML Tag's value and compare those value with str1
and str2 respectively
in C#.NET
Can Anyone suggest me the Code for it.

With regards
Tarun Sinha

May 15 '06 #1
1 1705
Hi Tarun,

In order to read from (and write to) Xml streams, ensure that the System.Xml
assembly is referenced in your project. Also do not forget to include the
System.Xml namespace in your code (if not included already).

Provided that the root element's name is 'Authentiation', and the Xml file
is saved to a local file C:\Sample.Xml, you can use the following code
snippet to obtain the UserId and Password values:

string strUserName = string.Empty, strPassword = string.Empty;
XmlNode xnAuth, xnCur;
XmlDocument xDoc = new XmlDocument();
xDoc.Load(@"C:\Sample.Xml");

xnAuth = xDoc.SelectSingleNode("Authentiation");
if (xnAuth != null)
{
xnCur = xnAuth.SelectSingleNode("userId");
if (xnCur != null)
strUserName = xnCur.InnerText;
xnCur = xnAuth.SelectSingleNode("password");
if (xnCur != null)
strPassword = xnCur.InnerText;
}

Checks are made to make sure that the appropriate Xml nodes exist
(otherwise, NullReferenceException would be thrown). The found values are
stored in strUserName and strPassword respectively. You can now compare the
values with the ones you wish.

--
Stanimir Stoyanov
www.stoyanoff.info
"TARUN" wrote:
Hello All

This is my XML File,

<?xml version="1.0" encoding="utf-8" ?>
- <Authentiation>
<userId>TarunSinha</userId>
<password>sonumonu</password>
</Authentiation>
I want to read the XML Tag's value and compare those value with str1
and str2 respectively
in C#.NET
Can Anyone suggest me the Code for it.

With regards
Tarun Sinha

May 15 '06 #2

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

Similar topics

12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
3
by: Dinesh_GR | last post by:
Hi all, I have many parent tags and many child tags under the respective parent.. in an XML file. On the click of a button the application should pick up the one parent and the corresponding...
4
by: supster | last post by:
I have the full file path of a file stored as a string and I'de like to get the file size in bytes. What is the most efficient way of doing this with a static method from the File class or...
7
by: emferrari | last post by:
Hi all I have a XML file with the following: <Step step="1"> <Text><b>Chapter 1</b> This is a test. Click <b><i>Load</i></b> </Text> </Step>
1
by: vadarv | last post by:
Hia! I'm a total amateur to VBS but need help on a VBS script. This is used in a HMI system from Siemens called WinCC, used for process viewing and control. What I need to is to write to a table...
3
by: lizii | last post by:
i have a file - which on each line has some data i need to fill into a box - now although reading in the data is simple enough and putting it in the correct box will be no problem, as i can just...
3
by: Paul Moore | last post by:
I'd like to write some scripts to analyze and manipulate my music files. The files themselves are in MP3 and FLAC format (mostly MP3, but FLAC where I ripped original CDs and wanted a lossless...
2
by: Clive Green | last post by:
Hello peeps, I am using PHP 5.2.2 together with MP3_Id (a PEAR module for reading and writing MP3 tags). I have been using PHP on the command line (Mac OS X Unix shell, to be precise), and am...
1
by: bookimal | last post by:
Hi, I'm not sure whether this goes in the XML or the Javascript forum but I guess its more Javascript because I want to read an XML file.. Anyway... I've got an XML file in this form: ...
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
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...
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: 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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.