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

  • SEARCH
  • Home
  • 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 6542757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:15:57+00:00 2026-05-25T11:15:57+00:00

I have an NSXMLElement that is a copy from somewhere else in my code.

  • 0

I have an NSXMLElement that is a copy from somewhere else in my code. After it’s been used, it no longer is connected to an NSXMLDocument. It’s (what I believe to be) not linked to anything.

If I NSLog the NSXMLElement, I am given the contents. I can see it.

But, if I try to use nodesForXPath, it returns nothing. It’s blank. It cannot find anything (unless I just search for *, in which case it returns everything with /t/t/n/t/t).

Now, if I make that NSXMLElement the root of a NEW NSXMLDocument, and then search the new document, I can search the XPath perfectly!

I am trying to understand the logic there. I have been reading the documentation, but I haven’t found anything that explains what is happening here (or at least, I have no understood it if I did find it in the documentation).

I would really appreciate someone helping me understand exactly why this is happening, and whether or not I need to use this NSXMLDocument.

Here is my code:

(element is an NSXMLElement coming from an NSArray of stored NSXMLElements. They are copies from a document used in another method)

NSArray* scene = [element nodesForXPath:@"scene[1]" error:nil];
NSLog(@"scene: %@", [[scene objectAtIndex:0] stringValue]);

But if I do this, I get a result:

NSXMLDocument* docElement = [[NSXMLDocument alloc] initWithRootElement:element];
NSArray* scene = [docElement nodesForXPath:@"scene[1]" error:nil];
NSLog(@"scene: %@", [[scene objectAtIndex:0] stringValue]);
  • 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-25T11:15:57+00:00Added an answer on May 25, 2026 at 11:15 am

    It’s probably because the xpath context used by libxml2 holds a reference to the document. If there is no document, it probably doesn’t know how to operate. The behavior if you search for * may just be a special-case because it knows it has to return everything so it doesn’t even try to search.

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

Sidebar

Related Questions

I have a subclass of NSObject that implements an -(id)initWithRootElement:(MyElement *)e method. NSXMLDocument has
have a look at the code from an xml file where i am using
Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
Have a rails app that is supposed to display a list of products/managers. After
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
Have a matrix report now that has Position, Hours and Wages for a location
Have you ever obfuscated your code before? Are there ever legitimate reasons to do
Have you ever created or encountered a self modifying code in Java? If yes,
have not tested on windows. but in ubuntu when u disconnect from the network,

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.