iPhone中的GDataXml解析问题

时间:2012-05-03 12:36:40

标签: iphone xml parsing gdataxml

这是在我需要解析iOS中使用GDataXml的部分和公司子数据的代码之下。

-<MainList>
    <FirstMessage>Right</FirstMessage>
    <SecondMessage>Wrong</SecondMessage>
    <Status>0</Status>
   -<CompanyList>
     -<Company>
         <Address1>12447 Hedges Run Drive</Address1>
         <Address2>#B-1 </Address2>
         <City>Lake Ridge</City> 
         <CompanyName>Starbucks</CompanyName>
         <CreatedBy>example@example.com</CreatedBy>
     -</Company>
      -<Company>
         <Address1>12447 Hedges Run Drive</Address1>
         <Address2>#B-1 </Address2>
         <City>Lake Ridge</City>
         <CompanyName>Starbucks</CompanyName>
         <CreatedBy>example@example.com</CreatedBy>
      -</Company>
   </CompanyList>
</MainList>

这是我的尝试我得到的每件事都很好,但我在NSArray arr中什么都没得到。

  NSArray *channels = [rootElement elementsForName:@"CompanyList"];  
  for (GDataXMLElement *icon in channels) {  
  NSArray *arr = [icon elementsForName:@"Company"];  
  if ([arr count]>0)  
  {  
        NSlog(@"Done");  
  }  
} 

2 个答案:

答案 0 :(得分:0)

看到这个答案,这个答案对你有帮助。 NSXMLParser example

答案 1 :(得分:0)

大家好,我认为如下

GDataXMLDocument * xmlDocument = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:&amp; error];

NSLog(@"Error:%@",[error description]);

NSArray *getData = [[xmlDocument rootElement]elementsForName:@"CompanyList"];
NSArray  *tempArray = [[NSMutableArray alloc]init];

for(GDataXMLElement *e in getData)
{

    NSArray *el = [e elementsForName:@"Company"];

    for (GDataXMLElement *e in el) {
        static int count =0;
        NSString    *testString = [[[e elementsForName:@"Address1"] objectAtIndex:0] stringValue];
        NSLog(@"Company  %d  : %@",count+1, testString);

    }