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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:36:41+00:00 2026-05-12T09:36:41+00:00

I am trying to figure out NSXMLParser for my iPhone app and while I

  • 0

I am trying to figure out NSXMLParser for my iPhone app and while I generally understand how it works, I am still a little confused about how to extract the values I need.

The XML result that I am parsing is very basic. it is like so:

<start>
 <status>300</status>
 <record>
  <title>The Title</title>
  <content>Some content</content>
 </record>
</start>

I need to do 3 things:
Get the value of status.
Get the value of content from the first record. There may come a response that offers multiple “record” elements so I need to only get the first.

I can’t figure out how to simply do that. Most all of the examples I have seen involve creating a separate object to populate this data into and I can’t see that being necessary for 2 values. Can anyone tell me how to pull these 2 pieces of data out and only for the first record?

  • 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-12T09:36:41+00:00Added an answer on May 12, 2026 at 9:36 am

    The first thing that happens when the NSXMLParser encounters an XML tag is that the delegate method parser:didStartElement:namespaceURI:qualifiedName:attributes: is called; you’ll probably only need to use the elementName variable here. Then, the XML parser reads the characters in the tag and calls parser:foundCharacters: with the contents. Finally parser:didEndElement:namespaceURI:qualifiedName is called.

    The approach that I’ve taken, as Apple uses in the SeismicXML examlple, is to use the methods as follows:

    1. In parser:didStartElement:namespaceURI:qualifiedName:attributes:, compare the string of the element name to a known value to see if it’s a string you care about. If so, then set an instance variable (an NSMutableString; I’ll call it contentOfCurrentXMLProperty) to an empty string. Otherwise set it to nil.
    2. In parser:foundCharacters:, append the found characters to contentOfCurrentXMLProperty.
    3. In parser:didEndElement:namespaceURI:qualifiedName, assign the value of contentofCurrentXMLProperty to whatever the appropriate variable is.

    See the SeismicXML example for more information.

    A couple of things about your specific case: first, since the XML parser only returns strings, you’ll need to convert the string to an integer (or whatever data type you’re using) for status.

    Second, since you only want the first value for record, in parser:didStartElement:... I’d set up a BOOL that flags whether you’ve already seen a record tag before and, if so, set contentOfCurrentXMLProperty to nil.

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

Sidebar

Ask A Question

Stats

  • Questions 170k
  • Answers 170k
  • 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 Check the sys.columns system catalog view: SELECT * FROM sys.columns… May 12, 2026 at 2:07 pm
  • Editorial Team
    Editorial Team added an answer You can, but you need to set System.Core to be… May 12, 2026 at 2:07 pm
  • Editorial Team
    Editorial Team added an answer The problem is that property1..3 are not properties, but fields.… May 12, 2026 at 2:07 pm

Related Questions

I am trying to figure out this: c = 1 def f(n): print c
I am trying to figure out how to click a button on a web
I am trying to figure out how to add a custom control to the
I am trying to figure out Messagebox( ownerWindow, ... ). Using reflector I see

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.