1

TBXML に関して多くの質問があることは承知しており、いくつかの解決策を試しましたが、何もうまくいきません。私はこのようなことに慣れていません。

<?xml version="1.0" encoding="utf-8"?>
  <ArrayOfNewsFeedService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
    <NewsFeedService>
      <LngNewsItemID>1</LngNewsItemID>
        <Contents>test</Contents>
        <LngUserID>1</LngUserID>
        <DteCreated>1/04/2014 12:00:00 a.m.</DteCreated>
        <NewsReply>
           <NewsFeedReplyService>
              <lngNewsItemReplyID />
              <LngNewsItemID>1</LngNewsItemID>
              <ReplyContent>reply</ReplyContent>
              <LngUserID>1</LngUserID>
              <DteCreated>1/04/2014 12:00:00 a.m.</DteCreated>
           </NewsFeedReplyService>
          <NewsFeedReplyService>
              <lngNewsItemReplyID />
              <LngNewsItemID>1</LngNewsItemID>
              <ReplyContent>reply2</ReplyContent>
              <LngUserID>1</LngUserID>
              <DteCreated>1/04/2014 12:00:00 a.m.</DteCreated>
          </NewsFeedReplyService>
        </NewsReply>
     </NewsFeedService>
   </ArrayOfNewsFeedService>

xml から「Contents」値を読み取ることはできますが、「NewsReply」とすべての内部 xml を読み取ろうとすると問題が発生します。それを解決する方法がよくわかりません。どんな助けでも大歓迎です。私はこれを2週間以上解決しようとしています。

前もって感謝します

編集 - ここでの謝罪は、私が試したコードです。

NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];



NSLog(@"%@", theXML);

TBXML * tbxml = [TBXML newTBXMLWithXMLString:theXML];



NSLog(@"%@", [TBXML elementName:tbxml.rootXMLElement]);





if (tbxml.rootXMLElement)

{



    NSString *content = [self traverseElement:tbxml.rootXMLElement: @"Contents"];



    UITextViewPost.text = content;



    NSString *test = [self traverseElement:tbxml.rootXMLElement: @"NewsReply"];

    NSLog(@"ReplyContent - %@", test);



    TBXMLElement * elem_items = [TBXML childElementNamed:@"NewsFeedReplyService" parentElement:tbxml.rootXMLElement];



    NSLog(@"elem_items - %@", elem_items);



    NSMutableArray * array=[[NSMutableArray alloc]init];



    while (elem_items !=nil)

    {

        NSMutableDictionary * dictionary=[[NSMutableDictionary alloc]init];

        NSString * str_ParseData=[[NSString alloc]init];



        TBXMLElement * elem_item = [TBXML childElementNamed:@"NewsFeedReplyService" parentElement:elem_items];



        TBXMLElement * elem_itemid = [TBXML childElementNamed:@"LngUserID" parentElement:elem_item];

        str_ParseData = [TBXML textForElement:elem_itemid];

        [dictionary setObject:str_ParseData forKey:@"LngUserID"];



        TBXMLElement * elem_itemname = [TBXML childElementNamed:@"ReplyContent" parentElement:elem_item];

        str_ParseData = [TBXML textForElement:elem_itemname];

        [dictionary setObject:str_ParseData forKey:@"ReplyContent"];



        [array addObject:dictionary];

        elem_items = [TBXML nextSiblingNamed:@"NewsFeedReplyService" searchFromElement:elem_items];  /// end node



        NSLog(@"printing arrays - %@", str_ParseData);

    }

}
4

1 に答える 1