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)

  1. //
  2. //b
  3. // b [1]
  4. // C
  5. // @ c
  6. // b | // @ c
  7. // e / text ()
  8. // comment ()
  9. count (//b)

and expected return value

  1. 1 element
  2. < 1 element
  3. 1 element
  4. 1 element
  5. 1 attribute node
  6. 2 elements and 1 attribute
  7. 2 text nodes
  8. 1 comment node
  9. 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

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -