Views 211 Votes 0 Comment 0
Atachment
Attachment '1'
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
XML  파싱할때 직관적으로 코딩할 수 있는 TBXML을 소개합니다.
아래는 예제파일에 포함된  소스코드 일부분입니다.  대략 이런식으로 코딩이 가능합니다. 참고하세요. ^^
// instantiate an array to hold author objects
authors = [[NSMutableArray alloc] initWithCapacity:10];
 
// Load and parse the books.xml file
tbxml = [[TBXML tbxmlWithXMLFile:@"books.xml"] retain];
 
// Obtain root element
TBXMLElement * root = tbxml.rootXMLElement;
 
// if root element is valid
if (root) {
  // search for the first author element within the root element's children
  TBXMLElement * author = [TBXML childElementNamed:@"author" parentElement:root];
   
  // if an author element was found
  while (author != nil) {
     
    // instantiate an author object
    Author * anAuthor = [[Author alloc] init];
     
    // get the name attribute from the author element
    anAuthor.name = [TBXML valueOfAttributeNamed:@"name" forElement:author];
     
    // search the author's child elements for a book element
    TBXMLElement * book = [TBXML childElementNamed:@"book" parentElement:author];
     
    // if a book element was found
    while (book != nil) {
       
      // instantiate a book object
      Book * aBook = [[Book alloc] init];
       
      // extract the title attribute from the book element
      aBook.title = [TBXML valueOfAttributeNamed:@"title" forElement:book];
 
      // extract the title attribute from the book element
      NSString * price = [TBXML valueOfAttributeNamed:@"price" forElement:book];
       
      // if we found a price
      if (price != nil) {
        // obtain the price from the book element
        aBook.price = [NSNumber numberWithFloat:[price floatValue]];
      }
       
      // find the description child element of the book element
      TBXMLElement * desc = [TBXML childElementNamed:@"description" parentElement:book];
       
      // if we found a description
      if (desc != nil) {
        // obtain the text from the description element
        aBook.description = [TBXML textForElement:desc];
      }
       
      // add the book object to the author's books array and release the resource
      [anAuthor.books addObject:aBook];
      [aBook release];
       
      // find the next sibling element named "book"
      book = [TBXML nextSiblingNamed:@"book" searchFromElement:book];
    }
     
    // add our author object to the authors array and release the resource
    [authors addObject:anAuthor];
    [anAuthor release];
     
    // find the next sibling element named "author"
    author = [TBXML nextSiblingNamed:@"author" searchFromElement:author];
  }       
}
 
// release resources
[tbxml release];

소스다운로드는 첨부파일 또는 아래링크를 참고하세요.
http://www.tbxml.co.uk/TBXML/TBXML_Free.html

?

List of Articles
No. Category Subject Author Date Views
» iOS XML 파싱을 쉽게 해주는 TBXML file hooni 2014.03.18 211
195 iOS iPad용 트위터앱 처럼 슬라이딩 패널 구현 소스 - StackScrollView file hooni 2014.03.18 226
194 iOS 간단한 테이블뷰 검색예제 file hooni 2014.03.18 239
193 iOS 차트라이브러리 - MIMChart Library file hooni 2014.03.18 260
192 iOS Pulse 스타일의 앱 만들기 file hooni 2014.03.18 220
191 iOS 달력라이브러리 - TapkuLibrary hooni 2014.03.18 231
190 iOS 커스텀 탭뷰 - JMTabView file hooni 2014.03.18 234
189 iOS UITableView + UIAlertView = SBTableAlert file hooni 2014.03.18 219
188 iOS plist로 테이블뷰 구성하기 - DrillDownApp file hooni 2014.03.18 269
187 iOS 페이스북형식의 슬라이딩메뉴패널구현하기 - JTRevealSidebar file hooni 2014.03.18 220
186 iOS 아이폰에 유튜브동영상표시 예제 file hooni 2014.03.18 456
185 iOS 에니메이션 커브 메뉴 - QuadCurveMenu (AwesomeMenu) file hooni 2014.03.18 207
184 iOS Cocos2D를 이용한 파티클 엔진 예제 file hooni 2014.03.18 234
183 iOS 슬라이딩 메뉴구현 예제 - ViewDeck file hooni 2014.03.18 242
182 iOS 이미지 외각 프레임 생성 라이브러리 - SWSnapshotStackView file hooni 2014.03.18 220
181 iOS 스크롤바위치에 레이블표시하는 오픈소스 - KNPathTableViewController file hooni 2014.03.18 232
Board Pagination Prev 1 2 3 4 5 ... 15 Next
/ 15