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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:40:00+00:00 2026-05-17T19:40:00+00:00

When I receive data from web service my NSMutableData is filled with following XML:

  • 0

When I receive data from web service my NSMutableData is filled with following XML:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetWeatherResponse xmlns="http://www.webserviceX.NET"><GetWeatherResult>&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;CurrentWeather&gt;
  &lt;Location&gt;BERLIN MUNICIPAL AIRPORT, NH, United States (KBML) 44-35N 71-11W 345M&lt;/Location&gt;
  &lt;Time&gt;Oct 19, 2010 - 03:52 AM EDT / 2010.10.19 0752 UTC&lt;/Time&gt;
  &lt;Wind&gt; Calm:0&lt;/Wind&gt;
  &lt;Visibility&gt; 10 mile(s):0&lt;/Visibility&gt;
  &lt;SkyConditions&gt; clear&lt;/SkyConditions&gt;
  &lt;Temperature&gt; 23.0 F (-5.0 C)&lt;/Temperature&gt;
  &lt;DewPoint&gt; 21.0 F (-6.1 C)&lt;/DewPoint&gt;
  &lt;RelativeHumidity&gt; 91&lt;/RelativeHumidity&gt;
  &lt;Pressure&gt; 29.83 in. Hg (1010 hPa)&lt;/Pressure&gt;
  &lt;Status&gt;Success&lt;/Status&gt;
&lt;/CurrentWeather&gt;</GetWeatherResult></GetWeatherResponse></soap:Body></soap:Envelope>

So when I search for “CurrentWeather” parser can’t find it because of &qt, &lt etc. How to fix my NSMutableData to have normal values (<, > etc.)?

COMPLETE CODE

#import "DemoWebServiceConsumeViewController.h"

@implementation DemoWebServiceConsumeViewController

@synthesize cityName;
@synthesize activityIndicator;
@synthesize location;

- (IBAction) hideKeyboard{
    [cityName resignFirstResponder];
}

- (IBAction) buttonClicked: (id)sender{

    [cityName resignFirstResponder];    

    NSString *soapMsg = 
    [NSString stringWithFormat:
     @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
     "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
     "<soap:Body>"
     "<GetWeather xmlns=\"http://www.webserviceX.NET\">"
     "<CityName>%@</CityName>"
     "<CountryName>%@</CountryName>"
     "</GetWeather>"
     "</soap:Body>"
     "</soap:Envelope>", cityName.text, @"united states"
     ];

    NSLog(soapMsg);    

    NSURL *url = [NSURL URLWithString: 
                  @"http://www.webservicex.com/globalweather.asmx"];
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];

    //---set the headers---
    // here copy method name to be called SOAP Action read from WS description
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
    [req addValue:@"text/xml; charset=utf-8" 
    forHTTPHeaderField:@"Content-Type"];
    [req addValue:@"http://www.webserviceX.NET/GetWeather" 
    forHTTPHeaderField:@"SOAPAction"];
    [req addValue:msgLength forHTTPHeaderField:@"Content-Length"];

    //---set the HTTP method and body---
    [req setHTTPMethod:@"POST"];
    [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];


    [activityIndicator startAnimating];    

    conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
    if (conn) {
        webData = [[NSMutableData data] retain];
    }  
}

-(void) connection:(NSURLConnection *) connection 
didReceiveResponse:(NSURLResponse *) response {
    [webData setLength: 0];
}

-(void) connection:(NSURLConnection *) connection 
    didReceiveData:(NSData *) data {
    [webData appendData:data];
}

-(void) connection:(NSURLConnection *) connection 
  didFailWithError:(NSError *) error {
    [webData release];    
    [connection release];
}

-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
    NSLog(@"DONE READING WEATHER WEB SERVICE. Received Bytes: %d", [webData length]);
    NSString *theXML = [[NSString alloc] 
                        initWithBytes: [webData mutableBytes] 
                        length:[webData length] 
                        encoding:NSUTF8StringEncoding];
    //---shows the XML---
    NSLog(theXML);  

    [theXML release]; 

    [activityIndicator stopAnimating];    

    if (xmlParser)
    {
        [xmlParser release];
    }
    xmlParser = [[NSXMLParser alloc] initWithData: webData];
                [xmlParser setDelegate:self];   
                [xmlParser setShouldResolveExternalEntities:YES];
                [xmlParser parse];


    [connection release];
    [webData release];
}

//---when the start of an element is found---
-(void) parser:(NSXMLParser *) parser 
    didStartElement:(NSString *) elementName 
    namespaceURI:(NSString *) namespaceURI 
    qualifiedName:(NSString *) qName
    attributes:(NSDictionary *) attributeDict {


    NSLog(elementName);
    if( [elementName isEqualToString:@"GetWeatherResult"])
    {
        if (!soapResults)
        {
            soapResults = [[NSMutableString alloc] init];
        }
        elementFound = YES;
    }
    else if([elementName isEqualToString:@"Location"])
    {
        elementFound = YES;
    }   
}

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string
{
    if (elementFound)
    {
        [soapResults appendString: string];
    }   
}

-(void)parser:(NSXMLParser *)parser 
        didEndElement:(NSString *)elementName 
        namespaceURI:(NSString *)namespaceURI 
        qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"GetWeatherResult"])
    {   
        NSLog(soapResults);        
        UIAlertView *alert = [[UIAlertView alloc] 
                              initWithTitle:@"Current Temperature!"                                                                                   
                              message:soapResults 
                              delegate:self  
                              cancelButtonTitle:@"OK" 
                              otherButtonTitles:nil];
        [alert show];
        [alert release];
        [soapResults setString:@""];
        elementFound = FALSE; 
    }
}

@end
  • 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-17T19:40:00+00:00Added an answer on May 17, 2026 at 7:40 pm

    I’ve edited your question so it shows what I think is what you meant to paste. It looks like the web service is encapsulating a whole XML file as a string inside another XML tag. So what you need to do is get the entire content of the <GetWeatherResult> XML tag as a single string. I think NSXMLParser will automatically substitute the correct characters in place of &gt; etc.

    Having got that string, you need to pass it into another NSXMLParser to parse the content of it.

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

Sidebar

Related Questions

Im requesting data from web service and receive a xml file.Not do flood the
I've managed to parse xml responses from a SOAP web service when I receive
I am using JSON to receive data from the web service , creating text
I have a web service from which i receive data, put it in a
I can successfully receive values from my web service so in that repect the
I have a web service that receives data in XML. I wish this XML
I have a doubt regarding downloading data from a web service. One way is
Good Afternoon all , I have downloaded data from a web service and im
What is backbone's convention/best practice for retrieving data from a RESTful web service, based
I want to use a web service and grab the data from the service.

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.