473,387 Members | 3,684 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,387 software developers and data experts.

XPath + SelectSingleNode

Hi All,

I have this weird problem. I have an xml document and tried to do an XPath
query to it. If I use the SelectSingleNode method it throws an exception but
it works with SelectNodes method. Is this a known problem with XPath and
SelectSingleNode?

Code snippet:

<snip>
XmlDocument xml= new XmlDocument();
xml.LoadXml(xmlString);
XmlNamespaceManager namespaceManager =
new XmlNamespaceManager(xml.NameTable);

namespaceManager.AddNamespace("defns", defns);

// return xml.DocumentElement.SelectSingleNode(xpath, namespaceManager);
<-- does not work
return xml.DocumentElement.SelectNodes(xpath, namespaceManager); // WORKS!

</snip>

so ... this is odd, does anyone has any explanation?
thanks,

/m
Nov 11 '05 #1
3 14847
muscha wrote:
I have this weird problem. I have an xml document and tried to do an XPath
query to it. If I use the SelectSingleNode method it throws an exception but
it works with SelectNodes method. Is this a known problem with XPath and
SelectSingleNode?


That's really weird, because SelectSingleNode is in fact only a wrapper around
SelectNodes, which returns only first selected node.
Provide more information please - what is your XML and XPath expression.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
I'd say the problem is in the method definition. Maybe it's defined to
return an XmlNodeList and when you do the return from SelectSingleNode it
doesn't work.... just an idea...

--
.../d:cazz
Daniel Cazzulino
DEVerest - Lagash
Tel +54 (0) 11 4247 7396
www.deverest.com.ar
www.lagash.com
dotnetopensrc.sourceforge.net

Coauthor of:
Beginning C# Web Applications with Visual Studio .NET
Beginning Web Programming using VB.NET and Visual Studio .NET
Professional ASP.NET Server Controls: Building Custom Controls with C#
ASP.NET Components Toolkit

"He who is good for making excuses, is seldom good for anything else."

"muscha" <mu****@no.spam.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi All,

I have this weird problem. I have an xml document and tried to do an XPath
query to it. If I use the SelectSingleNode method it throws an exception but it works with SelectNodes method. Is this a known problem with XPath and
SelectSingleNode?

Code snippet:

<snip>
XmlDocument xml= new XmlDocument();
xml.LoadXml(xmlString);
XmlNamespaceManager namespaceManager =
new XmlNamespaceManager(xml.NameTable);

namespaceManager.AddNamespace("defns", defns);

// return xml.DocumentElement.SelectSingleNode(xpath, namespaceManager);
<-- does not work
return xml.DocumentElement.SelectNodes(xpath, namespaceManager); // WORKS!

</snip>

so ... this is odd, does anyone has any explanation?
thanks,

/m

Nov 11 '05 #3
> > I have this weird problem. I have an xml document and tried to do an
XPath
query to it. If I use the SelectSingleNode method it throws an exception but it works with SelectNodes method. Is this a known problem with XPath and
SelectSingleNode?
That's really weird, because SelectSingleNode is in fact only a wrapper

around SelectNodes, which returns only first selected node.
Provide more information please - what is your XML and XPath expression.


You're right. It was a problem on my XPath. Found that it works now for
SelectSingleNode and even if I pass XPath that returns multiple nodes it
will return the first occurance of the node.

thanks

/m
Nov 11 '05 #4

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

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
4
by: Andreas Håkansson | last post by:
I have a price of XML that looks like this <Root> <SomeNode> ..... </SomeNode> <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> ... </Signature> </Root>
1
by: Angela | last post by:
I am getting an error when I attempt to access a node with SelectSingleNode(): "The expression passed to this method should result in a NodeSet." I understand there is some confusion when you have...
1
by: mjwills | last post by:
All, I am tearing my hair out on this one. I've checked Google and the newsgroups, and can't seem to solve it... My problem: I have an XML document that I pass to another function with an...
13
by: David Thielen | last post by:
XPathNavigator nav = MyCreateNav(); // InnerXml == "software" nav.SelectSingleNode"."); The select returns an exception: + $exception {"'.' has an invalid token."} System.Exception...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
4
by: Daniel | last post by:
Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ? string sdoc = "<foo><bar a='1'/><bar a='2'/></foo>";...
2
by: surya926 | last post by:
Hello! I want to generate dynamicaly xpath in c#.net code from xml file which is having multiple child elements under parent element.The purpose of generating xpath is uses for calculation.The...
3
rhitam30111985
by: rhitam30111985 | last post by:
Hi all, I have an xml like this : <root> <url newurl="something.asp?folder/file.htm#somethingsomething" /> <root> This is stored in a file. i am loading it at runtime like this :
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.