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 5846307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:33:30+00:00 2026-05-22T12:33:30+00:00

How can I use XPath to select a node without retrieving all of its

  • 0

How can I use XPath to select a node without retrieving all of its child nodes? For instance, in the following XML document:

<parentnode>
  <node1 a="b" b="c">
    <child1/>
    <child2/>
    ... many many child nodes
    <childN/>
  </node1>
  <node2/>
</parentnode>

I’d like to be able to select the ‘node1’ element in order to inspect its attributes, but without selecting the child nodes, which I don’t need to parse and could be thousands of elements, thus impacting the performance of the query (the output of which is used to build a sort of DOM tree with arrays and dictionaries in a 3rd party library).

Update: just to be clearer, the 3rd party library I mentioned is actually just an Objective-C wrapper around the libxml2 parser that builds a DOM tree made of Foundation classes with the result of any XPath query. The queries themselves are executed over an already parsed document (xmlDocPtr) that is reused for all queries, so yes, as many answers say, the document is already DOM’ed up at C level, but the Objective-C wrapper implementation produces the performance hit in this particular scenario. I could modify this library to optionally not fetch the selected node’s children, but I thought there would probably be a simple way to retrieve just the node’s attributes with the query.

  • 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-22T12:33:31+00:00Added an answer on May 22, 2026 at 12:33 pm

    If you just want the attributes, then just select the attributes: /parentnode/node1/@*

    But (as noted in another answer) and Xpath processor still has to parse the whole file.
    You won’t be saving much.

    If you only want to parse part of the file and then stop after you’ve gotten the info you need, you should probably use SAX or some other API that gives you lower level control of the parsing.

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

Sidebar

Related Questions

How can I use XPath to select an XML-node based on its content? If
You can use XPath if you're binding the XML document in the XAML, but
I want to sort a XML-Document by attributes of an Child-Node. I am working
Appreciate some pointers on how can I use XPath on XML file to extract
I am having the problem that I cannot select a specific XML node which
Can somebody show me some examples to import a html-page and use the XPath
Im using HtmlAgilityPack/HAP so that I can use Xpath with HTML documents. I need
We can use the XPathEvaluator object(in javascript) to do xpath evaluation on Safari,Google Chrome
i use the following XSLT by using XMLSpy: <?xml version=1.0 encoding=UTF-16?> <xsl:stylesheet version=2.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform
I run an XPath in Java with the following xml and code: <?xml version=1.0

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.