473,402 Members | 2,050 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,402 software developers and data experts.

Reading XML Node

Hi I am trying to read xmlNode and validate user
code used to do this is given below.

i am able to load the XMLDocument.
but the SelectSingleNode method call is always returning null value.

is there anything wrong in this code.

Expand|Select|Wrap|Line Numbers
  1. ProcessLogin(string userName, string password)
  2. {
  3.         HttpServerUtility Server = HttpContext.Current.Server;
  4.         HttpRequest Request = HttpContext.Current.Request;
  5.  
  6.         XmlDocument doc = new XmlDocument();
  7.         string path = Server.MapPath("/DataFile.xml");
  8.         doc.Load(path);
  9.         XmlNode node = doc.SelectSingleNode("Data/Users/UserName[. = '" + userName + "']/parent::node()/Password");
  10.         if (node != null && node.InnerText == password)
  11.             return true;
  12.         else
  13.             return false;
  14. }
and the xml document is as follows

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Data xmlns="http://tempuri.org/DataFile.xsd">
  3.     <Users>
  4.         <UserName>Usr1</UserName>
  5.         <Password>123456</Password>
  6.         <Active>true</Active>
  7.         <UpdatedTime>1/1/2007</UpdatedTime>
  8.     </Users>
  9.     <Users>
  10.         <UserName>su234</UserName>
  11.         <Password>su432</Password>
  12.         <Active>true</Active>
  13.         <UpdatedTime>1/1/2007</UpdatedTime>
  14.     </Users>
  15.     <Users>
  16.         <UserName>admin</UserName>
  17.         <Password>sec123</Password>
  18.         <Active>true</Active>
  19.         <UpdatedTime>1/1/2007</UpdatedTime>
  20.     </Users>
  21.     <Style>
  22.         <Font>Arialasda</Font>
  23.         <FontSize>12</FontSize>
  24.         <ForeColor>Blue</ForeColor>
  25.         <BackColor>White</BackColor>
  26.         <BackGroundImage></BackGroundImage>
  27.         <BulletIcon>Next.gif</BulletIcon>
  28.         <Speed>1</Speed>
  29.         <UpdatedTime>1/1/2007</UpdatedTime>
  30.     </Style>
  31. </Data>
Mar 3 '07 #1
2 3421
dorinbogdan
839 Expert 512MB
Try to get the password node like:
Expand|Select|Wrap|Line Numbers
  1.      XmlNode node = doc.SelectSingleNode("Data/Users[UserName = '" + userName + "'].ParentNode.SelectSingleNode("Password");
  2.  
  3.  
Mar 5 '07 #2
dorinbogdan
839 Expert 512MB
Hi,
Did you succeed to solve the problem ?
If yes, please let me know, in order to close the thread.
Thanks,
Dorin.
Mar 21 '07 #3

Sign in to post your reply or Sign up for a free account.

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...
9
by: Xarky | last post by:
Hi, I am writing an XML file in the following way. Now I need to read again that file to retrieve data such as Name and Age. Can someone help me out. Thanks in Advance ...
3
by: Eroc | last post by:
I'm new to XML files so I'm kinda lost here. I found some example code on reading an XML file. My objective is simple. Read the whole XML file into memory. Here is part of my code: Private...
13
by: Rick | last post by:
The following code will enter an infinate loop when in ReadChars. I can only make it happen when reading a Stream and with this particular XML. If I use the ReadInnerXml call rather than my own...
1
by: Zhiyao | last post by:
I want to write a program which can read strings, one per line, from standard input, and the program builds a list of strings then prints it. The code is listed below, when I compile it, there is no...
111
by: Tonio Cartonio | last post by:
I have to read characters from stdin and save them in a string. The problem is that I don't know how much characters will be read. Francesco -- ------------------------------------- ...
1
by: theeverdead | last post by:
Ok I have a file in it is a record of a persons first and last name. Format is like: Trevor Johnson Kevin Smith Allan Harris I need to read that file into program and then turn it into a linked...
21
by: Stephen.Schoenberger | last post by:
Hello, My C is a bit rusty (.NET programmer normally but need to do this in C) and I need to read in a text file that is setup as a table. The general form of the file is 00000000 USNIST00Z...
8
by: Aftabpasha | last post by:
I have seen a simple program for handling Link List operations. The following is the part of the code that contains the problem. The code is modified but contains all necessary information regarding...
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: 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:
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
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...
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
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,...

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.