1

友人のポッドキャスト用のアプリを作成しています。アプリには、URL を含む rss xml ファイルがあります。ここを見回した後、ドキュメントに KissXML を使用することにしましたが、DDXMLDocument が正しく機能していないようです。フォームの URL を使用して、ポッドキャストの RSS フィードとの接続を作成します。

NSString *podcastURL = [NSString stringWithFormat:@"http://podcast.website.com/rss/"];
NSURL *requestURL = [NSURL URLWithString:podcastURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]

次に、デリゲート メソッドで

-(void)接続:(NSURLConnection *)接続didReceiveData:(NSData *)データ

受信したデータを使用して DDXMLDocument を作成しようとしています。文字列を作成した後、initWithDataとinitWithStringを試しました...

NSError *error = nil;
NSString *response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

この文字列を NSLog してその内容を確認すると、完全に優れた xml ドキュメントのように見えます。私はXMLDocを作成します

DDXMLDocument *responseDoc = [[DDXMLDocument alloc] initWithXMLString:response options:0 error:&error];

しかし、この新しい XMLDoc を調べようとすると、NULL しか表示されません。私が何か間違ったことをしているかどうか、誰にもわかりますか?XML 文字列の応答は有効に見えますが、実際にはわかりません。助けてくれてありがとう!

編集:誰かが私ができない問題を見つけた場合に備えて、受け取ったXMLの一部を追加する必要があると考えました。ただし、ポッドキャストには 100 を超えるエピソードがあり、各エピソードには、長さ、説明、タイトル、iTunes 用のさまざまな要素など、すべてが含まれています。XML の冒頭部分は次のようになり、エピソードの 1 つが含まれています (ただし、実際のポッドキャスト情報は含まれていません):

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"         xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<channel>
    <atom:link href="http://podcast.libsyn.com/rss/" rel="self" type="application/rss+xml"/>
    <title>Podcast</title>
    <pubDate>Mon, 01 Oct 2012 06:18:33 +0000</pubDate>
    <lastBuildDate>Wed, 03 Oct 2012 22:19:37 +0000</lastBuildDate>
    <generator>Libsyn WebEngine 2.0</generator>
    <link>http://podcast.libsyn.com</link>
    <language>en</language>
    <copyright><![CDATA[podcast]]></copyright>
    <docs>http://podcast.libsyn.com</docs>
    <managingEditor>person@hotmail.com (person@hotmail.com)</managingEditor>
    <description><![CDATA[Comedy podcast with People!]]></description>
    <image>
        <url>http://assets.libsyn.com/content/3220867.jpg</url>
        <title>podcast</title>
        <link><![CDATA[http://podcast.libsyn.com]]></link>
    </image>
    <itunes:author>Person1  and Person2</itunes:author>
<itunes:keywords>keywords</itunes:keywords>
<itunes:category text="Comedy"/>
    <itunes:image href="http://assets.libsyn.com/content/3220867.jpg" />
    <itunes:explicit>yes</itunes:explicit>
    <itunes:owner>
        <itunes:name><![CDATA[Person1]]></itunes:name>
        <itunes:email>person@hotmail.com</itunes:email>
    </itunes:owner>
    <itunes:summary><![CDATA[Show Summary]]></itunes:summary>
    <itunes:subtitle><![CDATA[podcast]]></itunes:subtitle>
            <item>
        <title>#123 - Episode123 Title</title>
        <pubDate>Mon, 01 Oct 2012 06:18:33 +0000</pubDate>
        <guid isPermaLink="false"><![CDATA[46f771dfb560aa4d573fe3ebdee86870]]></guid>
        <link><![CDATA[http://podcast.libsyn.com/Episode123_Title]]></link>
        <media:thumbnail url="http://assets.libsyn.com/item/2082832" />
        <description><![CDATA[<p>Description of Episode 123.</p>
<p>Music: Episode 123 Music</p>]]></description>
        <enclosure length="80069010" type="audio/mpeg" url="http://traffic.libsyn.com/podcast/123.mp3" />
        <itunes:duration>01:06:44</itunes:duration>
        <itunes:explicit>no</itunes:explicit>
        <itunes:keywords />
        <itunes:subtitle><![CDATA[Episode 123 Description]]></itunes:subtitle>
                </item>

これがここに投稿するには多すぎる場合は申し訳ありません。この XML には、ヘッダーと 1 つのアイテム (エピソード) が含まれています。これは、DDXMLDocument で動作する正しいコードのように見えますか? 改めまして、皆様。

4

2 に答える 2

0

ティム・ディーンのコメントは正しかったようです。私が受け取っていた XML 文字列は非常に巨大だったので、didReceiveData: で NSLog が呼び出される間に実際に分割されていることに気づきませんでした。DDXMLDocument は、これらの部分的な文字列で作成できませんでした。ありがとう!

于 2012-10-04T08:01:33.803 に答える
0

ちょっと遅いかもしれませんが、KissXML 自体のこの例を使用しないのはなぜですか。

-(void)downloadXML{
    AFKissXMLRequestOperation *operation = [AFKissXMLRequestOperation XMLDocumentRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://legalindexes.indoff.com/sitemap.xml"]] success:^(NSURLRequest *request, NSHTTPURLResponse *response, DDXMLDocument *XMLDocument) {
      NSLog(@"XMLDocument: %@", XMLDocument);
  } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, DDXMLDocument *XMLDocument) {
      NSLog(@"Failure!");
}];

[operation start];

あとは、必要なものをXMLDocument取り出して取り出すだけですDDXMLElements

于 2012-11-20T12:01:56.387 に答える