English 中文(简体)
关于XML的多重联系/任务/调查的设计/执行建议
原标题:Design/Implementation advice on XML Parsing with multiple connections/feeds/views

Starting my first iOS project and wanted to advice on how to structure the application. The app pulls a XML feed, parses it out and displays a list representing the items in the XML feed. When clicking on a item in the list the app will pull a new XML feed using one of the attributes from the previously pulled XML feed. This happens several layers of pull, parse, display and on user selection do the same thing over again. Now most of the XML element structure is something like this:

(这些只是证明正在发生的事情的简单例子)

returns (Display info on new view):

<items>
    <item id="123" name="item 1" />
    <item id="124" name="item 2" />
    <item id="125" name="item 3" />
</itmes>

返回:

<itemDescription>
    <description itemId="123" name="desc 1" description="blah 1" />
</itemDescription>

了解:

  • Should I have a connection class/object or a new connection in each view?
  • Should I have a parser class/object or parse the XML feed in each view?
  • I m also looking to store some of the data returned so I don t need to call the XML feed again if the user navigates back to the main items list, but I would need to parse the itemsDescription XML feed every time.

我审视了几门教法的教导,我看到了如何做到这一点,希望更多地关注设计和可使用性,而不是在每一种新观点中重复该法典。 或者,我如何做这项工作。

最佳回答

The best way you can do this following Apple Guidelines is checking one of their examples, some months ago I made an app similar to yours following this example. Also you can see how to make your app in offline mode.

Basic structure (w/o offline mode):

The SeismicXML sample application demonstrates how to use NSXMLParser to parse XML data. When you launch the application it downloads and parses an RSS feed from the United States Geological Survey (USGS) that provides data on recent earthquakes around the world. It displays the location, date, and magnitude of each earthquake, along with a color-coded graphic that indicates the severity of the earthquake. The XML parsing occurs on a background thread using NSOperation and updates the earthquakes table view with batches of parsed objects.

Advanced structure (with offline mode):

Demonstrates how to use Core Data in a multi-threaded environment, following the first recommended pattern mentioned in the Core Data Programming Guide.

Based on the SeismicXML sample, it downloads and parses an RSS feed from the United States Geological Survey (USGS) that provides data on recent earthquakes around the world. What makes this sample different is that it persistently stores earthquakes using Core Data. Each time you launch the app, it downloads new earthquake data, parses it in an NSOperation which checks for duplicates and stores newly founded earthquakes as managed objects.

For those new to Core Data, it can be helpful to compare SeismicXML sample with this sample and notice the necessary ingredients to introduce Core Data in your application.

关于Cwieland的答复,I.n t use ASIHTTPRequest, 因为:outdated,因此,如果你要遵循他的做法,我会建议你使用,在那里,你可以处理XML的请求:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.flickr.com/services/rest/?method=flickr.groups.browse&api_key=b6300e17ad3c506e706cb0072175d047&cat_id=34427469792%40N01&format=rest"]];
AFXMLRequestOperation *operation = [AFXMLRequestOperation XMLParserRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser) {
  XMLParser.delegate = self;
  [XMLParser parse];
} failure:nil];

NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[queue addOperation:operation];
问题回答

Here is how I would implement it. I would use ASIHTTPRequest for all connection items and not worry about that part of it. It can handle all of your downloading of data asynchronous very easily with simple delegate methods.

我将有一个带宽的班子,以高压方式下载,然后将所交数据分类。 然后,通过代议制方法,将各类儿童送回表上,显示Xml数据中的儿童。

我将设立一个可调频的电算器子级,处理任何舱面/数据类型,在这种情况下,你只需要填写一个表象级,而不是担心用户如何浏览。 这将使你只需要书写一个类别,并处理任何数量钻井或组合。 这一执行在很大程度上取决于Xml数据不同水平的复杂性。 如果它们大不相同,那么在表格中采用更清洁的代码就更有意义,而没有<条码>,如果是,则检查小组制作中的数据类型。

采用导航风格,将消除每当观察负荷时再提供数据的必要性,因为你会冒着眼点。 如果需要/减少,则任何推进的时间都是再铺设,而只是ur子的ache子。 这要求每次发射数据时重载数据。 当然,如果你收到3个深层次的记忆警报,就必须在你回头的路上再进行分离或切碎。

如果你想要一个ach子系统,我会写出一门 class子,穿透视控制器和ur子,对仓库进行检查,如果它回来,数据阵列本会退回,然后拿到。

我个人将使用NSXMLParser,这是我熟悉的。 您可能希望把这些内容放在一个包裹中,在这种情况下,你只得检查你在<条码>didStartElement<>/code>上的哪一类内容,并设定一个通过制作而转换的平台。 这与ns食非常容易。 我的n子用其他ser子来比较,但确实发现,偷盗的NSXMLParser足够简单,ding光直截了当,所以很难加以控制。 这里是所有不同锡默勒教区的一个伟大场所:

因此,简言之,我将有一小类的NSObject,接受ur,通过ASIHTTPRequest下载。 A Sublcass of UITableview 主计长说,在囚室里,它用新车分配了同样的控制器级,将其推向导航站。 这一观点将显示一个装货屏幕,直到填表返回,然后才重载数据。 这将是一个充满希望的南联盟。

I would house as much of the code in global classes as possible. If each pull of data there is only one main category, as in

<items>
    <stuff></stuff>
    ....
    <stuff></stuff>
</items>
EOF

我将使用一个阵列来掌握所有价值观,如果有一个以上的主要章节,我将把所有东西都放在一个字典上,把母子归为阵列的关键和价值观。 然后,根据表格,根据字典的关键,有不同的章节。

我希望你回答一些问题。 我不肯定你所期望的低水平。 我说的是,我们只字不提几句,撰写了RSS的读者。 让我知道,与我一样,是否有任何东西要澄清。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签