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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:51:50+00:00 2026-05-28T20:51:50+00:00

I’ve set up a parser that is consuming an asmx web service, and .NET

  • 0

I’ve set up a parser that is consuming an asmx web service, and .NET is creating a close element tag. Here’s a clip from the log:

<Name>This is the Name</Name>
<EmptyString1 />
<EmptyString2 />
<Name2>This is Name2</Name2>

When I get to the foundCharacters method, there are no found characters, and the empty element is being populated by the most recent found characters.

For instance, the string for and is “This is the Name” when I want it to be an empty string or return a string that says “N/A”.

It seems like NSXMLparser doesn’t support this type of end tag, as it is just skipping over it. You would think it would be catchable in didEndElement method, but it never gets there because it doesn’t see it when the slash is at then end instead of .

How can I tell the parser to return a string when it hits this form of end tag?

EDIT: Here is some more from my code. In my understanding, for the most part, I’m already doing what NJones suggests, so I should focus this question more to this situation…

setting the the NSMutableData object to 0 clear it

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

webData is set from a soap call to the web service and is then put into the log as a string so I can see what the result looks like (same as to NJones “stringToParse” except the soap headers are included) then webData is sent to the parser.

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [webData appendData:data];
    NSString *soapResponse = [[NSString alloc] initWithData:webData encoding:NSASCIIStringEncoding];
    NSLog(@"webData: %@",soapResponse);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (xmlParser)
    {
        [xmlParser release];
    }
    xmlParser = [[NSXMLParser alloc] initWithData:webData];
    [xmlParser setDelegate:self];
    [xmlParser setShouldProcessNamespaces:YES];
    [xmlParser parse];

    [connection release];
    [webData release];
}

this inside didStartElement, inside the “File” tag, a.k.a the “WebServiceResult” tag that parses through all the elements

if ([elementName isEqualToString:@"WebServiceResult"]) 
{   
    if(!soapResults)
    {
        soapResults = [[NSMutableString alloc] init]; //declared in .h
    }
    recordResults = YES;
}

below, when I’m in the main parent tag (WebServiceResult), record results is now set to YES, so it goes into foundCharacters and sets the string to @”” then attempts to append

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string 
{
    if (recordResults)
    {
        if ([string isEqualToString:@""] || string == nil) {
            [soapResults appendString:@"N/A"];
            NSLog(@"foundResults empty: %@",soapResults);
        }
        else {
            [soapResults setString:@""];
           [soapResults appendString: string];
           NSLog(@"foundResults: %@",soapResults);
        }
    }
}

inside the didEndElement method, it is important to note that “EmptyString1” is sometimes NOT EMPTY so you can’t set the EmptyString element to @”” without an if statement of some sort somewhere, like in the foundCharacters method above. Then webData is sent to the parser

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"Name"]) 
    {
        name = [NSString stringWithFormat:@"%@",soapResults];
        NSLog(@"Name: %@",name);
    }
        if ([elementName isEqualToString:@"EmptyString1"]) 
    {
       sometimesEmptyString = [NSString stringWithFormat:@"%@",soapResults];
       NSLog(@"EmptyString1: %@",sometimesEmptyString);
    }

        //...and the same goes for sometimesEmptyString2, and name2...
}

So in summary, the log is not going into the “foundCharacters empty” if statement with [string isEqualToString:@””] because it never goes into the foundCharacters method when there’s an empty element tag. This is just to clarify, and I’m not sure how to append the @”” if I the parser isn’t seeing the empty element at all…someone will see what I’m missing and I’m sure it’s a simple fix from here

  • 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-28T20:51:51+00:00Added an answer on May 28, 2026 at 8:51 pm

    Wow…super easy fix, but I figured it out…

    this is the change needed for the foundCharacters method

    -(void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string {
    
        if (string != nil) {
            [soapResults setString:@""];
            [soapResults appendString: string];
            NSLog(@"foundResults: %@",soapResults);
        }
    
    }
    

    and then I added this simple piece to didEndElement at the very end

    [soapMessage setString:@"N/A"];
    

    What this does is set soapMessage to @”N/A” so when foundCharacters is skipped, soapMessage has retained the @”N/A” and if it there’s foundCharacters, it clears the no matter what it is and appends the string to soapMessage so it can be set in didEndElement. So really, the string needs to be set to whatever you want at the end of didEndElement, not in didStartElement for my particualar case.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.