Connecting Tech Pros Worldwide Forums | Help | Site Map

SelectSingleNode..Not Working..???

smita
Guest
 
Posts: n/a
#1: Nov 12 '05
Hi,
I have an Xml file in which i am storing the usernames and password and
some other user details. The file contains data as shown below..

<?xml version="1.0" encoding="utf-8"?>
<RoleTables xmlns="http://tempuri.org/UserPass.xsd">
<Table>
<username>Arun</username>
<password>jgEEnsYs+ZY=</password>
<Email>arun@yahoo.com</Email>
</Table>
<Table>
<username>sweta</username>
<password>A/JvqRbKGes=</password>
<Email>sita@ere.com</Email>
</Table>
</RoleTables>

Now I have an aspx page where i am displaying the list of existing
users(which i am getting from this xml file) and displaying as a bound
column of a datagrid and each of these users has a coressponding Edit and
Delete links which are the Hyperlink columns of the DataGrid.

now, My problem is how do i get the corrresponding user information from
this xml file for the userhas been click whose Edit ink ed.
What I have done is in the Hyperlink column attribute i have set
DataNavigateUrlFormatString="AddEditUserAcnts.aspx ?username={0}
And in the PageLoad Event of AddEditUserAcnts.aspx page i am trying to get
to this particular users node.
Please can you tell me how can I get to this particular users node.

I tried using this in my AddEditUserAcnts.aspx page

string userstring = Request.QueryString["username"];

XmlDocument doc = new XmlDocument();
string UserPath = Server.MapPath("UserPass.xml");
doc.Load(UserPath);

XmlNode root = doc.DocumentElement;
XmlNode table = root.SelectSingleNode("descendant::Table[ @user='Arun' ]");

But table always points to null...i.e. I am not able to get to that
particular users node.

Any advice would be helpful...
Thanx
Smita.



Ryan Trudelle-Schwarz
Guest
 
Posts: n/a
#2: Nov 12 '05

re: SelectSingleNode..Not Working..???


"smita" <smita@rarefind.com> wrote
[color=blue]
> XmlNode table = root.SelectSingleNode("descendant::Table[[/color]
@user='Arun' ]");

I'm no XPath expert but i think what you want is:

"descendant::Table[username='Arun']"

I.e., look for the Table whose _child username element_ has a value of
'Arun'.

You were querying for the Table whose _user attribute_ had a value of
'Arun'.


Marc Scheuner [MVP ADSI]
Guest
 
Posts: n/a
#3: Nov 12 '05

re: SelectSingleNode..Not Working..???


><?xml version="1.0" encoding="utf-8"?>[color=blue]
><RoleTables xmlns="http://tempuri.org/UserPass.xsd">
> <Table>
> <username>Arun</username>
> <password>jgEEnsYs+ZY=</password>
> <Email>arun@yahoo.com</Email>
> </Table>
> <Table>
> <username>sweta</username>
> <password>A/JvqRbKGes=</password>
> <Email>sita@ere.com</Email>
> </Table>
></RoleTables>
>
>XmlNode table = root.SelectSingleNode("descendant::Table[ @user='Arun' ]");
>
>But table always points to null...i.e. I am not able to get to that
>particular users node.[/color]

Well, the <Table> tag contains a tag called <username> - so maybe you
need to select on that, not on "user" (which doesn't exist). Also, I
think the @user would refer to an attribute "user" of the <Table> tag
- which you don't have - you mostly likely need to use this instead:

XmlNode table =
root.SelectSingleNode("descendant::Table[username='Arun' ]");

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Closed Thread