473,769 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading XML Node

1 New Member
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 SelectSingleNod e 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 3446
dorinbogdan
839 Recognized Expert Contributor
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 Recognized Expert Contributor
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
4912
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 question twice! Here it is: I am having problems reading the value of a text Node. I think it has to do with the fact that the text is in a <span> tag. I have a table and in each <td> I have text + a checkbox. I want to retreive the text next to the...
3
4837
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 child and bind it to a grid. Like that it goes on for the next parent and the related child for the next button click.
9
1994
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 /*********************************/ static void writeXML() {
3
1621
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 Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim query As String
13
3278
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 ReadElementBodyAsXml the code works, but is less efficent. ReadElementBodyAsXml is required by my application with .Net Framework 1.1. The code breaks on the second call to ReadElementBodyAsXml with the inner xml: </EGDConfigExtension>...
1
7062
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 problem, but everytime when I run it, the segmentation fault occurs and I couldn't find out the problem. #include <stdio.h> #include <stdlib.h> #include <string.h> #define LEN sizeof(struct Node) typedef struct Node { char *string;
111
20072
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 -- ------------------------------------- http://www.riscossione.info/
1
15553
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 list. So on the list I can go Trevor, Kevin, Allan in a straight row but I can also call out there last name when I am on their first name in the list. Sorry if it doesn't make sense trying to explain best I can. So far I have // list.cpp
21
3064
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 00000000_00 0 000 000 000 0000 000 I need to read the file line by line and eventually parse out each piece of the file and store in arrays that correspond to the specific
8
7371
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 the problem. #include<stdio.h> #include<stdlib.h> #include<conio.h> struct llist { int val; struct llist *next; };
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5309
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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 we have to send another system
2
3565
muto222
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.