What is the proper XPath for "all nodes are exactly one below the base node?"

Assuming I don’t know the name of my node database or its children, what is the XPath syntax for "all nodes exactly one below the node base?"

If the template is an XmlNode, I have the following code:

XmlNodeList kvpsList = pattern.SelectNodes(@"//");

Which looks right, but I get the following exception:

   System.Xml.XPath.XPathException: Expression must evaluate to a node-set.

What is the correct syntax?

+5
source share
2 answers

Two current answers are incorrect:

/*/*

does not select all nodes that are children of the top node . It does not select text nodes, processing instructions, or comments that are children of the top element.

XPath, , :

/*/node()

// XPath; XPath Spec:

// / -:: node()/

. , XPath, , , , .

, // , . XML, descend , XPath, :

/*//node()

+7

, ,

/*/*

// XPath, . - //element, element XML, , .

/*/* , " node, ".

+8

All Articles