By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,973 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,973 IT Pros & Developers. It's quick & easy.

Anybody experience XPath anxiety?

P: n/a
I was wondering if anybody gets similar results when attempting to query an
XML Doc with an XPath query or if this is expected behavior or if I'm using
something incorrectly.

<xml ...>
<LoginInfo>
<user>
<username>test</username>
<password>test</password>
</user>
<user>
<username>why won't </username>
<password>this work</password>
</user>
</LoginInfo>
'vb.net code below
dim x as new xmldocument()
x.load("c:\filepath.xml")
dim y as xmlnodelist
y=x.selectnodes("/user[username='test']")

'When I examine the value of y, it holds something like "testtestwhy
won'tthiswork"
'I thought my query was bad, so I ran it in an .htm with IE and got the
result set I was looking for, namely

<user>
<username>test</username>
<password>test</username>
</user>

any ideas on why .net returns a string like that?
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try //user[username='test'] or /LoginInfo/user[username='test']

Wole
"Clamps" <Cl****@RobotMafia.Futurama.com> wrote in message news:Ok*************@TK2MSFTNGP09.phx.gbl...
I was wondering if anybody gets similar results when attempting to query an XML Doc with an XPath query or if this is expected behavior or if I'm using something incorrectly.

<xml ...>
<LoginInfo>
<user>
<username>test</username>
<password>test</password>
</user>
<user>
<username>why won't </username>
<password>this work</password>
</user>
</LoginInfo>
'vb.net code below
dim x as new xmldocument()
x.load("c:\filepath.xml")
dim y as xmlnodelist
y=x.selectnodes("/user[username='test']")

'When I examine the value of y, it holds something like "testtestwhy won'tthiswork"
'I thought my query was bad, so I ran it in an .htm with IE and got the result set I was looking for, namely

<user>
<username>test</username>
<password>test</username>
</user>

any ideas on why .net returns a string like that?
Nov 12 '05 #2

P: n/a
Wole, I got the same result.
So I did a bit more tooling around and found that when I use
//user[username='why won't'] that I get the same result set. I thought my
query was good. Did you compile my snippet?
"Wole Ogunremi" <wo*************@SPAMntlworld.com> wrote in message
news:jL****************@newsfe6-gui.ntli.net...
Try //user[username='test'] or /LoginInfo/user[username='test']

Wole
"Clamps" <Cl****@RobotMafia.Futurama.com> wrote in message
news:Ok*************@TK2MSFTNGP09.phx.gbl...
I was wondering if anybody gets similar results when attempting to query
an XML Doc with an XPath query or if this is expected behavior or if I'm
using something incorrectly.

<xml ...>
<LoginInfo>
<user>
<username>test</username>
<password>test</password>
</user>
<user>
<username>why won't </username>
<password>this work</password>
</user>
</LoginInfo>
'vb.net code below
dim x as new xmldocument()
x.load("c:\filepath.xml")
dim y as xmlnodelist
y=x.selectnodes("/user[username='test']")

'When I examine the value of y, it holds something like "testtestwhy
won'tthiswork"
'I thought my query was bad, so I ran it in an .htm with IE and got the
result set I was looking for, namely

<user>
<username>test</username>
<password>test</username>
</user>

any ideas on why .net returns a string like that?
Nov 12 '05 #3

P: n/a
Clamps

I did not compile your snippet but ran it thru Visual XPath Analyzer which is a .NET tool.
http://www.topxml.com/code/default.a...xpath&sw=categ

//user[username="why won't"] returns the expected nodeset...

Good luck
Wole

"Clamps" <Cl****@RobotMafia.Futurama.com> wrote in message news:ud**************@TK2MSFTNGP11.phx.gbl...
Wole, I got the same result.
So I did a bit more tooling around and found that when I use //user[username='why won't'] that I get the same result set. I thought my query was good. Did you compile my snippet?
"Wole Ogunremi" <wo*************@SPAMntlworld.com> wrote in message news:jL****************@newsfe6-gui.ntli.net...
Try //user[username='test'] or /LoginInfo/user[username='test']

Wole
"Clamps" <Cl****@RobotMafia.Futurama.com> wrote in message news:Ok*************@TK2MSFTNGP09.phx.gbl...
I was wondering if anybody gets similar results when attempting to query an XML Doc with an XPath query or if this is expected behavior or if I'm using something incorrectly.

<xml ...>
<LoginInfo>
<user>
<username>test</username>
<password>test</password>
</user>
<user>
<username>why won't </username>
<password>this work</password>
</user>
</LoginInfo>
'vb.net code below
dim x as new xmldocument()
x.load("c:\filepath.xml")
dim y as xmlnodelist
y=x.selectnodes("/user[username='test']")

'When I examine the value of y, it holds something like "testtestwhy won'tthiswork"
'I thought my query was bad, so I ran it in an .htm with IE and got the result set I was looking for, namely

<user>
<username>test</username>
<password>test</username>
</user>

any ideas on why .net returns a string like that?
Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.