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

The Archive Base Latest Questions

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

I’m trying to create an XML string and pass it to another method where

  • 0

I’m trying to create an XML string and pass it to another method where I use the HTTP POST to send it to a PHP script. See the log file below, I can create the XML string and display it in the log file, but I cannot pass it to the postXMLFeed method.

What am I doing wrong ?

-(IBAction)syncUp { 
 [self createXMLFeed];
// [self postXMLFeed:XMLStr];
 [self postXMLFeed];
}


-(void)createXMLFeed{
 //Fetch details from the database.
 NSFetchRequest *request = [[NSFetchRequest alloc] init];
 NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tabrss" inManagedObjectContext:managedObjectContext];
 [request setEntity:entity];
 NSError *error;
 self.stories = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
 [request release];

 // Count the number of items in the array and display in the log.
 int arrayItemQuantity = [stories count];
 NSLog(@"Array Quantity: %d", arrayItemQuantity);

 // Loop through the array and display the contents in the log.
 int i;
 for (i = 0; i < arrayItemQuantity; i++)
 {
  //NSString *XMLStr = [NSString stringWithFormat:@"<workout><id>%@</id><userid>%@</userid><walkid>%@</walkid><date>%@</date><distance>%@</distance><repeats>%@</repeats><type>%@</type><intensity>%@</intensity><comments>%@</comments><time>%@</time><weight>%@</weight><height>%@</height></workout>", 
  XMLStr = [NSString stringWithFormat:@"<workout><id>%@</id><userid>%@</userid><walkid>%@</walkid><date>%@</date><distance>%@</distance><repeats>%@</repeats><type>%@</type><intensity>%@</intensity><comments>%@</comments><time>%@</time><weight>%@</weight><height>%@</height></workout>", 
       [[stories objectAtIndex:i] valueForKey:@"ID"], 
       [[stories objectAtIndex:i] valueForKey:@"UserID"], 
       [[stories objectAtIndex:i] valueForKey:@"walkID"], 
       [[stories objectAtIndex:i] valueForKey:@"xDate"], 
       [[stories objectAtIndex:i] valueForKey:@"Distance"], 
       [[stories objectAtIndex:i] valueForKey:@"Repeats"], 
       [[stories objectAtIndex:i] valueForKey:@"Type"],
       [[stories objectAtIndex:i] valueForKey:@"Intensity"],
       [[stories objectAtIndex:i] valueForKey:@"Comments"],
       [[stories objectAtIndex:i] valueForKey:@"xTime"],
       [[stories objectAtIndex:i] valueForKey:@"Weight"],
       [[stories objectAtIndex:i] valueForKey:@"Height"]];

  NSLog (@"XML Feed1: %@", XMLStr); 
 }
 NSLog (@"XML Feed2: ", XMLStr);

 [stories release];  

 // Update log file.
 NSLog(@"Database read and XML feed created."); 
}


//-(void)postXMLFeed:(NSString *)XMLStr
-(void)postXMLFeed
{ 
 //XMLStr = @"<workout><id>1</id><userid>4</userid><walkid>20</walkid><date>2010-06-21 10:42:50</date><distance>12345</distance><repeats>1</repeats><type>StephenTesting</type><intensity>6.0</intensity><comments>testtesttest</comments><time>00:00:00</time><weight>65</weight><height>173</height></workout>";
 //XMLStr = @"<xml><id>Hello World!</id></xml>";
 NSLog (@"XML Feed3: ", XMLStr);

 NSURL *url = [NSURL URLWithString:@"http://192.168.1.200/stephen/sync_upload.php"];
 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
 [request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
 [request setHTTPMethod:@"POST"];
 [request setHTTPBody:[XMLStr dataUsingEncoding:NSASCIIStringEncoding]];

 NSURLResponse *response;
 NSError *error;
 response = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];


 // Update log file.
 NSLog(@"XML feed POSTED to website: ", XMLStr);

 //[super postXMLFeed];
}

Log file:

2010-06-25 14:34:38.001 TAB RSS[2229:207] XML Feed: <workout><id>27
  </id><userid>4
  </userid><walkid>
  </walkid><date>2010-06-21 10:42:25
  </date><distance>1000
  </distance><repeats>1
  </repeats><type>Walking
  </type><intensity>6.0
  </intensity><comments>asdf
  </comments><time>00:00:00
  </time><weight>65
  </weight><height>173
</height></workout>
2010-06-25 14:34:38.001 TAB RSS[2229:207] XML Feed: <workout><id>28
  </id><userid>4
  </userid><walkid>
  </walkid><date>2010-06-21 10:45:05
  </date><distance>152.4
  </distance><repeats>1
  </repeats><type>Hiking/Backpacking
  </type><intensity>8.0
  </intensity><comments>test
  </comments><time>00:00:00
  </time><weight>65
  </weight><height>173
</height></workout>
2010-06-25 14:34:38.002 TAB RSS[2229:207] XML Feed: <workout><id>29
  </id><userid>4
  </userid><walkid>
  </walkid><date>2010-06-21 12:31:28
  </date><distance>0
  </distance><repeats>1
  </repeats><type>Aikido
  </type><intensity>5.0
  </intensity><comments>Nice training
  </comments><time>01:30:00
  </time><weight>65
  </weight><height>173
</height></workout>
2010-06-25 14:34:38.002 TAB RSS[2229:207] XML Feed2: 
2010-06-25 14:34:38.003 TAB RSS[2229:207] Database read and XML feed created.
2010-06-25 14:34:38.004 TAB RSS[2229:207] XML Feed3: 
(gdb) continue
Current language:  auto; currently objective-c
2010-06-25 14:34:39.585 TAB RSS[2229:207] XML feed POSTED to website: 
  • 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-15T11:50:33+00:00Added an answer on May 15, 2026 at 11:50 am

    stringWithFormat: is an NSString class method. It doesn’t retain the string it returns, so it only persists for the remainder of the scope in which it was called. If you were to use [[NSString alloc] initWithFormat:] instead, or simply call retain on your XMLStr variable, you should be able to use it just fine in the second method. Just remember to release the string when you’re done with it at the end of the second method.

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

Sidebar

Ask A Question

Stats

  • Questions 453k
  • Answers 453k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The text you are adding to the datacell most likely… May 15, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer See Comment below question. May 15, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer What's the easiest way to get a project including all… May 15, 2026 at 9:26 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.