Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 427151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:33:04+00:00 2026-05-12T19:33:04+00:00

How do node.XPathSelectElement() and node.XPathSelectElements() behave when the selection is either not a NodeSet

  • 0

How do node.XPathSelectElement() and node.XPathSelectElements() behave when the selection is either not a NodeSet or a NodeSet containing non-Elements? For example do they always return something or can they throw Exceptions? can the return value be null or is it always an IEnumerable of some sort? The XML searched is constant:

<a>
  <b c="d"/>
  <e>fgh</e>
  <e>xyz</e>
<!-- comment -->
  <b/>
</a>

To illustrate this here are some XPath strings; I would be grateful for the behaviour of both XPathSelectElement and XPathSelectElements in each case (I have put the expected XSLT NodeSet below – please comment if you disagree)

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

and expected return values

  1. 1 element
  2. 2 elements
  3. 1 element
  4. 0 elements
  5. 1 attribute node
  6. 2 elements and 1 attribute
  7. 2 text nodes
  8. 1 comment node
  9. the integer 2

If the Xpath does not return an IEnumerable of Elements (XPathSelectElements) or a single Element (XPathSelectElement) is any indication given or is the failure silent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:33:04+00:00Added an answer on May 12, 2026 at 7:33 pm

    If you inform a valid XPath expression which evaluates to XElements, you’ll get:

            Linq.XPathSelectElement            Linq.XPathSelectElements
             DOM.SelectSingleNode               DOM.SelectNodes
            -----------------------            ------------------------
    "//c"             null                          .Count == 0
    "//a"           XElement                        .Count == 1
    

    If you try to send a XPath matching a node type different than XElement, you’ll get an InvalidOperationException; If you’re not sure about XPath return and want to avoid catching Exceptions, you can go with node.XPathEvaluate()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can an ArrayList of Node contain a non-Node type? Is there a very dirty
In Node 0.4.2, is it possible for http.request() to return both through the callback
any node above the current node in an hierarchical tree example the parent,grandparent,great-grandparent or
Node's HTTP module is not returning all the expected data from this URL: http://itradedata.co.za/pmchart/prices/GetPricesTRI.asp?Shortname=ACE&numprices=5
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)
Duplicate Of : Find node clicked under context menu I've got a context menu
I've got a node struct struct Node{CString text, int id;}; in a sorted vector.
After a node's label is edited in the tree I try to resort the
With my current node selected I wish to find an element <name> [./name] and
I have a node with many CCK fields. I want to hide a field

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.