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 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

Related Questions

Trying to figure out why my vertex shader works on my cell phone (Casio
In trying to figure out this problem (which is still unsolved and I still
Trying to figure out a way to use Javascript to set up a little
Trying to figure out the best way to set up collection lists for users
Trying to figure out which to use.
Trying to figure out how to programmatically access the web pages in the application.
Trying to figure out the best way to do this: Should I do something
Trying to figure out how to write a jquery formula that will sum all
Trying to figure out this pseudo code. The following is assumed.... I can only
Trying to figure out how to adequately test my accounts controller. I am having

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.