2012-04-28 3 views
0

こんにちは私は最後の2日間どこでも見ました&私のために何かを見つけることができません。私は、URLからデータを引き出すことができました。私のログでは、すべての要素と値が表示されます。テーブルビューにTBXML URLデータを追加する方法がわかりません

私の知ることができないステップは、自動的に(ログに表示されるように)それを実行しているので、手動で各文字列を検索することなく、「イベント」配列に追加する方法です。ここで

は私のloadUrl方法である:

- (void)loadURL { 

// Create a success block to be called when the asyn request completes 
TBXMLSuccessBlock successBlock = ^(TBXML *tbxmlDocument) { 
    NSLog(@"PROCESSING ASYNC CALLBACK"); 

    // If TBXML found a root node, process element and iterate all children 
    if (tbxmlDocument.rootXMLElement) 
     [self traverseElement:tbxmlDocument.rootXMLElement]; 

}; 

// Create a failure block that gets called if something goes wrong 
TBXMLFailureBlock failureBlock = ^(TBXML *tbxmlDocument, NSError * error) { 
    NSLog(@"Error! %@ %@", [error localizedDescription], [error userInfo]); 
}; 

// Initialize TBXML with the URL of an XML doc. TBXML asynchronously loads and parses the file. 
tbxml = [[TBXML alloc] initWithURL:[NSURL URLWithString:@"http://somexml.com/xml"] 
          success:successBlock 
          failure:failureBlock]; 

    events = [NSMutableArray array]; } 

そして、ここでは私のtraverseElement方法である:

<resultsPage totalEntries="6" perPage="50" page="1" status="ok"> 
<results> 
<event uri="http://somexml.com/xml" popularity="0.863682" displayName="Radio 1's Hackney 
Weekend 2012" id="9234656" type="Festival" status="ok"> 
<location city="London, UK" lng="-0.128" lat="51.5078"/> 
<series displayName="Radio 1's Hackney Weekend"/> 
<end time="" date="2012-06-24" datetime=""/> 
<start time="" date="2012-06-23" datetime=""/> 
<performance displayName="Lucy Labeaux" billingIndex="5" id="23336188" billing="headline"> 
<artist uri="http://www.somexml.com/artistxml" displayName="Lucy Labeaux" id="1168415"> 
<identifier href="http://somexml.com.xml" mbid="4593d49a-7f67-46ba-9ec0-126bd676286f"/> 
</artist> 
</performance> 

マイログ:ここ

- (void) traverseElement:(TBXMLElement *)element { 

do { 
    // Display the name of the element 
    NSLog(@"%@",[TBXML elementName:element]); 


    // iterate all child elements of tbxml.rootXMLElement that are named "author" 
    [TBXML iterateAttributesOfElement:element withBlock:^(TBXMLAttribute *attribute, NSString *name, NSString *value) { 

     // Display name and value of attribute to the log window 
     NSLog(@"%@->%@ = %@",[TBXML elementName:element], name, value); 

    }]; 

    // if the element has child elements, process them 
    if (element->firstChild) [self traverseElement:element->firstChild]; 

    // Obtain next sibling element 
} while ((element = element->nextSibling)); 


} 

は私が引っ張ってるxmlです次のようになります。

PROCESSING ASYNC CALLBACK 
resultsPage 
resultsPage->totalEntries = 6 
resultsPage->perPage = 50 
resultsPage->page = 1 
resultsPage->status = ok 
results 
event 
event->uri = http://example.com 
event->popularity = 0.863682 
event->displayName = Cooled Up Week 2012 
event->id = 9234656 
event->type = Festival 
event->status = ok 
location 
location->city = London, UK 
location->lng = -0.128 
location->lat = 51.5078 
series 
series->displayName = Cooled Up Week 2012 
end 
end->time = 
end->date = 2012-06-24 
end->datetime = 
start 
start->time = 
start->date = 2012-06-23 
start->datetime = 
performance 
performance->displayName = Lucy Labeaux 
performance->billingIndex = 1 

今、私はすべての要素、属性などを見てきました。どのように私はそれを私のテーブルビューと行数にリンクしますか?私はあきらめて、助けてください!私は本当にありがとう、あなたの時間をありがとう!

+0

このXMLの具体的なデータは、あなたのテーブルビューに入れようとしているものですか? –

+0

イベントから、uri&displayNameを取得しようとしています。場所から、市、lng、&緯度。 &開始から、時間と日付。私はまたtotalEntriesの数に私の行数を割り当てようとしていますが、それを理解することはできません。 – Year3000

+0

私はこれらの行に沿って何かを考えていましたが、わかりません: 'TBXMLElement * event = [TBXML childElementNamed:@ "event" parentElement:element]; NSString * uri = [TBXML valueOfAttributeNamed:@ "uri" forElement:event]; NSString * venue = [TBXML valueOfAttributeNamed:@ "displayName" forElement:event]; [イベントの追加オブジェクト:[NSArray arrayWithObjects: [TBXML textForElement:event]、 uri、venue、nil]]; – Year3000

答えて

0

須藤のrm -rfは最高のレスポンスあなたがそれをしようとしない理由

まあでしたか?私がTBXMLを使用して以来、それはしばらくありました。それ以来、libxml2を直接(Cocoaラッパーを使用して)使用するようになりました。そのため、Xパスを使用してループなしで直接選択することができます。代わりに、この解析ライブラリを試してみる必要があります。私はそのシンプルさについて優れたことを聞いてきました。 github.com/ZaBlanc/RaptureXML申し訳ありませんが、私はこの時点でテストケースを書く時間がありません。

関連する問題