在Swift中处理复杂XML文件的最佳方法?

时间:2016-08-27 15:15:03

标签: ios xml swift nsxmlparser

我正在制作一个iOS应用程序来帮助学生安排课程,我从在线XML文件中获取所有信息。它是一个相当大的文件(400,000行),因此我计划在后台定期下载和处理,但始终保存一份副本,以便可以脱机使用该应用程序。我一直在玩几个选项,但没有一个看起来像是一个很好的解决方案。这就是XML的样子:

<?xml version="1.0" encoding="UTF-8"?>
<unmschedule version="1.0.4" pubdate="2016-08-26-17:00:10" source="UNM">
    <semester code="201680" name="Fall 2016" index="1">
        <campus code="ABQ" name="Albuquerque/Main">
            <college code="AP" name="School of Arch. and Planning">
                <department code="ABM" name="School Architecture Planning">
                    <subject code="ARCH" name="Architecture">
                        <course number="109" title="Design Fundamentals">
                            <catalog-description>Studio/lecture introduces fundamental principles and processes of two-, three-, and four-dimensional design. Methods of perception, technique, composition, evaluation of materials and methods, critical evaluation and graphic representation are studied through both abstract and representational assignments.</catalog-description>
                            <section crn="41646" number="002" part-of-term="1" status="S">
                               v <section-title></section-title>
                                <text>Cancel/Reschedule to CRN 57664 04/20/2016.</text>
                                <instructional-method code=""></instructional-method>
                                <delivery-type code="LC">Lecture</delivery-type>
                                <enrollment max="18">0</enrollment>
                                <waitlist max="0">0</waitlist>
                                <credits>3</credits>
                                <fees>60</fees>
                                <instructors>
                                </instructors>
                                <meeting-times>
                                </meeting-times>
                            </section>

选项1:使用嵌套字典:我已经尝试了这个并且它主要起作用,但是我遇到了诸如课程的问题,他们是部分字典,但也需要有标题和描述。我也试过使用Any类型,但是还没有能够让它运行起来。

选项2:结构:这些似乎不起作用,因为您无法动态添加新变量。

选项3: XML:我认为这是解决方案,但我还没有弄清楚如何直接将XML数据读入我的程序(例如,显示所有2016秋季课程,然后是所有英语课程,然后是所有英语101部分),而不是在每一步都解析整个XML文件。

感谢任何帮助,我已经广泛搜索了互联网,但是我发现的文章都没有解决XML这么复杂,所以我无法弄清楚如何使它适应我的程序。

0 个答案:

没有答案