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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:46:50+00:00 2026-05-14T08:46:50+00:00

I am needing to parse an XML file for my app and I dont

  • 0

I am needing to parse an XML file for my app and I dont have any clue how to do it. I went through one XMLParser tutorial, and it worked fine but the XML file in the tutorial was very simple and my XML file is quite a bit more complex.

here is a snippet of the xml file:

  <?xml version="1.0" encoding="UTF-8"?>
    <digital_tpp cycle="1003" from_edate="0901Z    03/11/10" to_edate="0901Z     04/08/10">
        <state_code ID="AK" state_fullname="Alaska">
            <city_name ID="ADAK ISLAND" volume="AK-1">
                <airport_name ID="ADAK" military="N" apt_ident="ADK" icao_ident="PADK" alnum="1244">
                    <record>
                        <chartseq>10100</chartseq>
                        <chart_code>MIN</chart_code>
                        <chart_name>TAKE-OFF MINIMUMS</chart_name>
                        <useraction></useraction>
                        <pdf_name>AKTO.PDF</pdf_name>
                        <cn_flg>N</cn_flg>
                        <cnsection></cnsection>
                        <cnpage></cnpage>
                        <bvsection>C</bvsection>
                        <bvpage></bvpage>
                        <procuid></procuid>
                        <two_colored>N</two_colored>
                        <civil> </civil>
                        <faanfd15></faanfd15>
                        <faanfd18></faanfd18>
                        <copter></copter>
                    </record>
                    <record>
                        <chartseq>10200</chartseq>
                        <chart_code>MIN</chart_code>
                        <chart_name>ALTERNATE MINIMUMS</chart_name>
                        <useraction></useraction>
                        <pdf_name>AKALT.PDF</pdf_name>
                        <cn_flg>N</cn_flg>
                        <cnsection></cnsection>
                        <cnpage></cnpage>
                        <bvsection>E</bvsection>
                        <bvpage></bvpage>
                        <procuid></procuid>
                        <two_colored>N</two_colored>
                        <civil> </civil>
                        <faanfd15></faanfd15>
                        <faanfd18></faanfd18>
                        <copter></copter>
                    </record>
                </airport_name>
            </city_name>
        </state_code>
    </digital_tpp>

What I’m needing to do is search the XML file for the <...icao_ident> that the user specifies, then create a dictionary containing the <pdf_name> and <chart_name> for each <record> . I will then create a UI that displays the pdf files.

Can someone direct me to a good tutorial or explanation of how XML parser works? Or if I’m going about this the wrong way I’d be open to suggestions too.

(the XML file is about 8MB)

  • 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-14T08:46:51+00:00Added an answer on May 14, 2026 at 8:46 am

    i know this isn’t the best way…

    I struggled for 2 days trying to adapt the XML parser to my situation. I couldnt grasp it, probably because I’m just so used to doing this in C# and obj-c is new to me…

    So what I did was parsed the whole thing as a string.

    I converted the entire XML file to a NSString, then used substringToIndex and substringFromIndex to isolate the section I needed (the airport). I then used the </record> tag to create an array of <records>, then wrote a for loop that took the values I needed out of the each array object just by getting the range of the tags.

    Like I said, it was a crazy solution, but I did it all in 26 lines of code and it works great.

    NSString *path = [[NSBundle mainBundle] pathForResource:@"dttps" ofType:@"xml"];
    NSData *data = [[NSData alloc]initWithContentsOfFile:path];
    NSString *xmlString = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    
    NSRange range = [xmlString rangeOfString:searchedAirport];
    xmlString = [xmlString substringFromIndex:range.location];
    range = [xmlString rangeOfString:@"/airport_name"];
    xmlString = [xmlString substringToIndex:range.location];
    
    NSMutableArray *chartNames = [[NSMutableArray alloc]initWithCapacity:100] ;
    NSMutableArray *pdfNames = [[NSMutableArray alloc]initWithCapacity:100] ;
    NSArray *charts = [xmlString componentsSeparatedByString:@"</record>"];
    
    NSString *tempString = [[NSString alloc]initWithFormat:@""];
    
    int chartsCount = [charts count]-1;
    
    int x;
    for (x=0; x < chartsCount; x=x+1) {
    
        tempString = [charts objectAtIndex:x];
        range = [tempString rangeOfString:@"<chart_name>"];
    
        tempString = [tempString substringFromIndex:range.location+12];
        range = [tempString rangeOfString:@"</chart_name>"];
        tempString = [tempString substringToIndex:range.location];
    
        [chartNames addObject:tempString];
    
        tempString = [charts objectAtIndex:x];
        range = [tempString rangeOfString:@"<pdf_name>"];
        tempString = [tempString substringFromIndex:range.location+10];
        range = [tempString rangeOfString:@"</pdf_name>"];
        tempString = [tempString substringToIndex:range.location-4];
        [pdfNames addObject:tempString];
    
    
    }
    

    followed by cleanup…

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

Sidebar

Related Questions

I am needing to have a dynamic jqgrid on my asp.net mvc3 app. The
In a desktop application needing some serious re-factoring, I have several chunks of code
I saw something about needing to have the assembly available for the type of
I am needing to log some xml data (which is currently a JDOM Document),
I'm using json-framework to parse some simple json in my iphone app, and it
I have a batch file that I can't change, but I want to automate
Needing some instructions on Xpath. I have something along the following lines in terms
I've come across a dilemma. My C# app uses a custom file format that
Good afternoon. I have been making a small openGL based app for android that
needing some help to just break down the problem. I have new users who

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.