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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:08:38+00:00 2026-06-06T20:08:38+00:00

I am trying to read an XML file using objective C language and parse

  • 0

I am trying to read an XML file using objective C language and parse it. I am using XCode 4.2 and writing application for iPhone. I have created Viewcontroller .h and .m files. I am using NSXMLParser and xml file is named as “simple.xml”. I have downloaded it from w3schools website. I am not using ARC. There are no build errors.
Below is my code in viewDidLoad method –

NSString *filePath;
filePath = [[NSBundle mainBundle] pathForResource:@"simple" ofType:@"xml"];
NSData *fileData = [NSData dataWithContentsOfFile:filePath]; 
NSString *urlString = [[NSString alloc] initWithData:fileData encoding:NSASCIIStringEncoding];
NSLog(@"File data is %@",urlString);    
NSString* str= urlString;
NSData* data=[str dataUsingEncoding:NSUTF8StringEncoding];
xmlParser = [[NSXMLParser alloc] initWithData:data];
xmlParser.delegate = self;
[xmlParser parse];

Here is the XML content –

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<breakfast_menu>
    <food>
        <name>Belgian Waffles</name>
        <price>$5.95</price>
        <description>two of our famous Belgian Waffles with plenty of real maple syrup</description>
        <calories>650</calories>
    </food>
    <food>
        <name>Strawberry Belgian Waffles</name>
        <price>$7.95</price>
        <description>light Belgian waffles covered with strawberries and whipped cream</description>
        <calories>900</calories>
    </food>
    <food>
        <name>Berry-Berry Belgian Waffles</name>
        <price>$8.95</price>
        <description>light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
        <calories>900</calories>
    </food> 
  </breakfast_menu>

But when I execute this code the program terminates abruptly. I do not see any exception info in logs. But it has something to do with fileData variable because in XCode the line in which I am using this variable is shown in green color with text “thread 1 stopped executing…”. Perhaps the XML is encoded in ISO-8859-1 and I am using ASCII encoding? Earlier I used similar code for parsing XML returned from a web-service and at that time response was encoded in UTF-8. Or maybe I have made some mistake in memory management..allos, release etc? Kindly help me in this.

Also I tried saving the file with “UTF-8” in “TextEdit” but there was no such option available.

  • 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-06T20:08:39+00:00Added an answer on June 6, 2026 at 8:08 pm

    removed encoding part and passed whatever data I read from the xml file directly to the XML parser and it worked for me.

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

Sidebar

Related Questions

I have one .net windows application I'm trying to read .xml file from c#
I am trying to read an XML file using LINQ. I have had no
I am trying to read this XML file using PHP and I have two
I have been trying to parse an XML file using boost's property tree, but
I am trying to read in an XML file that I have saved to
I have an XML file that I'm trying to read from here , and
I have a really simple XML file that I'm trying to read, but I
I have an xml file(from federal government's data.gov) which I'm trying to read with
I have an XML file as follows, and I'm trying to read the content
I am trying to parse an xml file using XmlReader but although 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.