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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:15:01+00:00 2026-06-15T17:15:01+00:00

Sorry for the rudimentary question – I need some help. I’m able to get

  • 0

Sorry for the rudimentary question – I need some help. I’m able to get the XML doc and save it. Can’t get editing to work. I want to update the “theme” tag using the contents of a textField and set with an action prior to saving. My editing code obviously not working.

Thanks for the help.

-paul.

 <temp>
<theme>note</theme>
 </temp>

 ///////

 NSMutableArray* temps = [[NSMutableArray alloc] initWithCapacity:10];
 NSXMLDocument *xmlDoc;
 NSError *err=nil;

 NSString *file = [input1 stringValue];

 NSURL *furl = [NSURL fileURLWithPath:file];
if (!furl) {
   NSLog(@"Unable to create URL %@.", file);
   return;
}
xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:     (NSXMLNodePreserveWhitespace|NSXMLNodePreserveCDATA) error:&err];
 if (xmlDoc == nil) {
  xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:NSXMLDocumentTidyXML  error:&err];
}


 NSXMLElement* root  = [xmlDoc rootElement];
 NSArray* objectElements = [root nodesForXPath:@"//temp" error:nil];
for(NSXMLElement* xmlElement in objectElements)
[temps addObject:[xmlElement stringValue]];


 NSXMLElement *themeElement = [NSXMLNode elementWithName:@"theme"];
[root addChild:themeElement];
 NSString * theTheme = [textField stringValue];
[themeElement setStringValue:theTheme];
  • 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-06-15T17:15:03+00:00Added an answer on June 15, 2026 at 5:15 pm

    Here’s how you can change the theme element in a file. Basically when you setStringValue on an element, the root element is updated with the new value and thus the xmlDoc is also updated because it’s linked to the root element. So you can then just write that to file. As an example, here’s the xml document I started with…

    <root>
        <temp>
            <theme>first theme</theme>
            <title>first title</title>
        </temp>
        <temp>
            <theme>second theme</theme>
            <title>second title</title>
        </temp>
    </root>
    

    And in this code I change the “first theme” value to “changed theme”. Notice also that my “nodesForXPath” code gets the theme elements directly.

    // the xml file
    NSString* file = [NSHomeDirectory() stringByAppendingPathComponent:@"Desktop/a.xml"];
    NSURL *furl = [NSURL fileURLWithPath:file];
    
    // get the xml document
    NSError* err = nil;
    NSXMLDocument* xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:(NSXMLNodePreserveWhitespace | NSXMLNodePreserveCDATA) error:&err];
    if (err) {
        NSLog(@"There was an error reading the xml document.");
        return 0;
    }
    NSXMLElement* root  = [xmlDoc rootElement];
    
    // look for the <theme> tags
    NSArray* themeElements = [root nodesForXPath:@"//theme" error:nil];
    
    // change a specific theme tag value
    for(NSXMLElement* themeElement in themeElements) {
        if ([[themeElement stringValue] isEqualToString:@"first theme"]) {
            [themeElement setStringValue:@"changed theme"];
        }
    }
    
    // write xmlDoc to file
    NSData* xmlData = [xmlDoc XMLDataWithOptions:NSXMLNodePrettyPrint];
    if (![xmlData writeToURL:furl atomically:YES]) {
        NSLog(@"Could not write document out...");
    }
    
    [xmlDoc release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for question but I can't find answer anywhere on internet. I couldn't find
Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get
Sorry, guys.I am quite new in mysql but I do need help from getting
Sorry if this sounds like a really stupid question, but I need to make
Sorry for this question to be a can you fix it one, but this
Sorry if this question's been asked before, but I can't seem to find an
Sorry but yet another question on JavaScript. From my previous post, I was able
sorry for the dummy question but I cannot find a simple and clean way
Sorry but I am not sure how to ask this question but I am

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.