xpath - Return value from XPathSelectElement(s) in C# -
how to node.expath select element ()
and node.expathasaccredited elements ()
Behavior occurs when the selection is a nodeset with nodesets or non-elements? For example, do they always return something or they can throw exceptions? Can return value be empty or is it always an IEnumerable type? The detected XML is stable:
& lt; A & gt; & Lt; B c = "d" / & gt; & Lt; E & gt; Fgh & lt; / E & gt; & Lt; E & gt; Xyz & lt; / E & gt; & Lt ;! - Comment -> & Lt; P / & gt; & Lt; / A & gt;
Here are some XPath strings to describe; I would be grateful for the behavior of both XPathSelectElement and XPathSelectElements in each case (I have set the required XSLT nodes below - if you disagree, please comment)
-
//
//b
// b [1]
// C
// @ c
// b | // @ c
// e / text ()
// comment ()
count (//b)
and expected return value
- 1 element < 1 element
- 1 element
- 1 element
- 1 attribute node
- 2 elements and 1 attribute
- 2 text nodes
- 1 comment node
- integer 2
If Xpath elements do not return an IEnumerable (XPathSelectElements) or one single element (XPathSelectElement) is there any signal or failure is silent?
If you evaluate a valid XPath expression for XElements
You will get:
Linq.XPathSelectElement Linq.XPathSelectElements DOM.SelectSingleNode DOM.SelectNodes ---------- ------------- - ---------------------- "// c" tap .Count == 0 "/ / A" XElement .Count == 1
If you try to match xipeth separately from the exception node type, you will get a invalid operation exponent
; If you are not sure about XPTH return and want to avoid catching exceptions, you can node.xpathEvaluate ()
Comments
Post a Comment