Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

objective c - iPhone XMLParser help

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You might find that my blog post about wrapping NSXMLParser gives you what you need - and possibly a higher level alternative (my wrapper).

For example, using my technique, you'd write methods like:

-(void) handleElement_chartname: (NSDictionary*) attributes;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...