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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:13:19+00:00 2026-05-30T08:13:19+00:00

I am trying to parse XML from a .NET WCF Webservice using NSXML Parser.

  • 0

I am trying to parse XML from a .NET WCF Webservice using NSXML Parser.
Here is the XML which my web-service returns:

<QuestionnaireXML xmlns="http://schemas.datacontract.org/2004/07/QuestionnaireDescriptor" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <QuestionnaireName>Clinic Waiting Room Feedback</QuestionnaireName>
    <Questions>
        <Question>
            <Answers>
                <Answer>
                     <AnswerTitle>Windows</AnswerTitle>
                </Answer>
                <Answer>
                    <AnswerTitle>Mac</AnswerTitle>
                </Answer>
            </Answers>
            <QuestionID>363</QuestionID>
            <QuestionName>Windows or Mac?</QuestionName>
        </Question>
    </Questions>
</QuestionnaireXML>

I obtain the XML using the following method:

-(IBAction)getQuestionnaire
{
    // Obtain questionnaire ID from input textfield
    NSString *qid = questionnaireId.text;

    // Begin creating URL string and contact web service
    dataWebService = [NSMutableData data];
    NSString *combinedRequest = [NSString stringWithFormat:@"http://www.osqar.co.uk/OsqarWCF/frank.svc/getQuestionnaireForID?id=%@", qid];
    NSURL * myURL = [NSURL URLWithString:combinedRequest];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: myURL];
    NSURLConnection *myConnection = [NSURLConnection connectionWithRequest:request delegate:self];
    [myConnection start];  
}

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

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

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];
    XMLParser *parseQuestionnaire = [[XMLParser alloc] init];
    Questionnaire *myQuestionnaire = [parseQuestionnaire parseXML:responseString];  
}

And then parse the XML to the XMLParser class and it method. Like So:

#import "XMLParser.h"
#import "Questionnaire.h"

@implementation XMLParser

@synthesize xmlParser;

-(Questionnaire *)parseXML:(NSString *)xml
{    
    userRet = [[Questionnaire alloc] init];
    NSData *data = [xml dataUsingEncoding:NSUTF8StringEncoding];

    self.xmlParser = [[NSXMLParser alloc] initWithData:data];
    self.xmlParser.delegate = self;
    if([self.xmlParser parse])
    {
        NSLog(@"The Xml is parsed.");
    }
    else
    {
        NSLog(@"Failed to parse the XML");
    }

    return userRet;
}

- (void) parser: (NSXMLParser *) parser parseErrorOccurred: (NSError *) parseError 
{
    NSLog(@"Error Parser:%@",[parseError localizedDescription]);
}

- (void) parser: (NSXMLParser *) parser didStartElement: (NSString *) elementName
   namespaceURI: (NSString *) namespaceURI
  qualifiedName: (NSString *) qName
     attributes: (NSDictionary *) attributeDict
{
    if ([elementName isEqualToString:@"QuestionnaireName"]) 
    {
        NSString *name = [attributeDict objectForKey:@"QuestionnaireName"];
        NSLog(@"QuestionnaireName: %@", name);
        userRet.QuestionnaireName = [attributeDict objectForKey:@"QuestionnaireName"];
    }   
}

My problem here is that the element name QuestionnaireName is apparently not being found. I have placed a break point and the code steps into didStartElement method but then steps out of the if ([elementName isEqualToString:@”QuestionnaireName”]) statement.

As you can see from the XML sample above, the Element QuestionnaireName clearly exists.
What am I doing wrong here? Have I missed out anything?
Any help would be greatly appreciated.

  • 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-30T08:13:21+00:00Added an answer on May 30, 2026 at 8:13 am

    First you have to set currentelement = elementName in the method didstartelement.

    Now have to implement the method foundcharacter.

    In that method check the following:

    if ([currentelement isEqualtoString:@"QuestionnaireName"])
    {    
        NSLog(@"value  %@",string);    
    }
    

    then you will get value “Clinic Waiting Room Feedback”

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

Sidebar

Related Questions

I trying to parse xml from an inputstream using the sax parser. The inputstream
I'm trying to parse xml from SharePoint service (lists) using jquery. I have XMLHttpRequest
Here is a snippet from the XML file I am trying to parse: <Item
I am trying to parse a particular attribute/value pair from XML in VB.NET. The
So I'm trying to parse some XML, the creation of which is not under
So I'm trying to parse the following XML document with C#, using System.XML: <root
I am new to jquery. I am trying to parse xml string using jquery.
Ok I am trying to parse an XML from a get request in Javascript.
I am trying to parse out xml feeds from different sources, some news feeds
I am trying to parse an XML response from Amazon's Product Advertising API, this

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.