Questions tagged [selectsinglenode]

Selects the first Xml Node that matches the XPath expression

.NET
Selects the first XmlNode that matches the XPath expression. Any prefixes found in the XPath expression are resolved using the supplied XmlNamespaceManager.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

http://msdn.microsoft.com/en-us/library/h0hw012b(v=vs.110).aspx

Java

public abstract java.lang.Object selectSingleNode(java.lang.Object context)
                                           throws JDOMException

Evaluates the wrapped XPath expression and returns the first entry in the list of selected nodes (or atomics). Parameters: context - the node to use as context for evaluating the XPath expression. Returns: the first selected item, which may be of types: Element, Attribute, Text, CDATA, Comment, ProcessingInstruction, Boolean, Double, String, or null if no item was selected. Throws: JDOMException - if the evaluation of the XPath expression on the specified context failed.

http://www.jdom.org/docs/apidocs.1.1/org/jdom/xpath/XPath.html#selectSingleNode(java.lang.Object)

126 questions
76
votes
6 answers

Why is XmlNamespaceManager necessary?

I've come up kinda dry as to why -- at least in the .Net Framework -- it is necessary to use an XmlNamespaceManager in order to handle namespaces (or the rather clunky and verbose [local-name()=... XPath predicate/function/whatever) when performing…
Code Jockey
  • 6,611
  • 6
  • 33
  • 45
55
votes
4 answers

SelectSingleNode returns null when tag contains xmlNamespace

I'm loading a string into an XML document that contains the following structure:
Shlomi Komemi
  • 5,445
  • 3
  • 28
  • 41
20
votes
1 answer

Html Agility Pack SelectSingleNode giving always same result in iteration?

I would like the nodes in the collection but with iterating SelectSingleNode I keep getting the same object just node.Id is changing... What i try is to readout the webresponse of a given site and catch some information like values, links .. in…
Mikatsu
  • 530
  • 2
  • 4
  • 15
13
votes
1 answer

Using XPath in SelectSingleNode: Retrieving individual element from XML if it's present

My XML looks like : one two three .....maybe more Items here. Some of the individual Item may or may not be present. Say I want to…
user108324
12
votes
1 answer

SelectSingleNode always returns null?

Taking this simplifed example of my XML:
bigtv
  • 2,611
  • 5
  • 29
  • 42
8
votes
1 answer

XPath query for an attribute containing forward slash (/)

I'm trying to do a SelectSingleNode on an XMLDocument using an XPath expression. However, when the attribute value that I'm searching contains multiple forward slashes (/), it returns null. I can't find any resources online for escaping the forward…
Chris
  • 201
  • 4
  • 9
8
votes
2 answers
7
votes
2 answers

xpath query for finding an element with a condition which matches the attribute and child node value

I have 2 elements with same attribute but with different child node values. Can I query to find a specific element which matches the attribute and also the child node value. To be specific, this is the sample xml i am using to query(each element in…
anamik
  • 73
  • 1
  • 1
  • 5
6
votes
1 answer

Why is SelectSingleNode returning null?

I'm working with an XML document that contains a structure that looks similar to this: . . . I'm…
Todd Richardson
  • 1,119
  • 1
  • 11
  • 22
6
votes
1 answer

Parsing XML: Colon in my element causes XPath to miss it

I have an XML document that I load in and try to search with XPath. The root node in this file is and the file end is properly closed with . My problem is that I cannot walk the tree…
Mike K
  • 1,313
  • 2
  • 18
  • 28
5
votes
2 answers

System.Xml.XPath.XPathException: Expression must evaluate to a node-set when executing SelectSingleNode("//(artist|author)")

Can somebody explain me why is this not working? I'm executing XmlNode xmlNode = xmlDocument.SelectSingleNode("//(artist|author)"); and I get System.Xml.XPath.XPathException: Expression must evaluate to a node-set. but this works and does not…
knoopx
  • 17,089
  • 7
  • 36
  • 41
4
votes
1 answer

HtmlAgilityPack - selecting single node from a node collection using XPath

i have been fighting with this code for a few hours now.... Sample Node for results:

Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93

4
votes
1 answer

Select Single Node with a attribute name in vbscript

Have an xml file
fireBand
  • 947
  • 7
  • 23
  • 42
4
votes
3 answers

SelectSingleNode is giving compilation error in dnx core 5.0

I am getting this error with SelectSingleNode method: DNX Core 5.0 error CS1061: 'XmlDocument' does not contain a definition for 'SelectSingleNode' and no extension method 'SelectSingleNode' accepting a first argument of type 'XmlDocument' could be…
Prosenjit
  • 41
  • 3
4
votes
4 answers

Function RemoveChild(XmlNode node) failed in C#

When I try to remove some of my child element with RemoveChild(). But throw exception. I attached my code below. nodeName = doc.SelectSingleNode("//Equipment//DataCollections//EnabledIDs//MyID[@id='" + attrValue + "']"); // Found the…
Nano HE
  • 9,109
  • 31
  • 97
  • 137
1
2 3
8 9