views:

509

answers:

2

I understand that the name of selectNode/selectSingleNode methods actually suggests that they are designed to return a node, however maybe there is some other way or a setting available to enable XPath evaluator to return data of other types (that are also valid XPath results)

oDocument.selectSingleNode("'1'"); 

throws an error "Expression does not return a DOM node"

I want to query oDocument.selectSingleNode("concat(@day, '-', @month, '-', @year") and get a result (that is possible with standard DOM XPath API). Indeed I can query for nodes and then traverse them with DOM, however this would be way to inefficient.

+1  A: 

selectSingleNode() and selectNodes() select nodes identified by an XPath expression.

Their return values are of type IXMLDOMNode and IXMLDOMNodeList, respectively. Nothing else can be returned.

Expressions that do not return a node set (but otherwise are valid XPath expressions) will result in an error.

Tomalak
+1  A: 

The API exposed by msxml do not allow this.

You may look into the source code of the XPath Visualizer to see how such XPath expressions are successfully evaluated. Just in few words, when an exception is caught attempting to evaluate an XPath expression, and this exception's message is exactly the one provided in your (original) question, then a special XSLT transformation is created dynamically, and it returns the result of the XPath expression using <xsl:value-of>

Dimitre Novatchev