我怎樣才能得到這個<firstName>
和<lastName>
。我嘗試了很多,但我已經搞砸了。如何使用GDataXML解析器解析嵌套的xml?
<list>
<OrderData HASH="1843180441">
<id>26</id><customer>
<CustomerData HASH="882063912">
<id>1</id>
<sex>Male</sex>
<firstName>admin</firstName>
<lastName>admin</lastName>
<companyName>Individual</companyName>
<userName>admin</userName>
<password>21232f297a57a5a743894a0e4a801fc3</password>
<lastLogin>2012-01-26T12:11:38</lastLogin>
<status>A</status>
<created>2011-09-28T07:01:47</created>
<modified>2012-01-26T12:11:38</modified>
<canChangePassword>Y</canChangePassword>
<isDeleted>false</isDeleted>
<abn/>
<abnBranch/>
<storeCredit>50000.0</storeCredit>
<billingAddress>
<list>
<AddressData HASH="768553743">
<id>2</id>
<firstName>admin</firstName>
<lastName>admin</lastName>
<addressLine1>suite: 1307, 9 Yara Street</addressLine1>
<addressLine2>dgdgdf</addressLine2>
<postCode>3000</postCode>
<suburb>dfgdfg</suburb>
<city>sadf</city>
<phone>4456</phone>
<mobile/>
<fax/>
<active>true</active>
<type>C</type>
<email>[email protected]</email>
<log/>
</AddressData>
</deliveryAddress>
<purchaseDate>2011-10-03T03:23:48</purchaseDate>
</OrderData>
<OrderData HASH="1569451006"></OrderData>
<OrderData HASH="1449383081"></OrderData>
<OrderData HASH="1438157618"></OrderData>
<OrderData HASH="269308788"></OrderData>
</list>
直到現在我已經做到了。
NSLog(@"Enering in the xml file");
NSArray *getNumberOfOrder = [[xmlDocument rootElement] elementsForName:@"OrderData"];
for(GDataXMLElement *e in getNumberOfOrder){
for(int i =0;i<[[e elementsForName:@"customer"]count];i++){
// All orderd customer name
NSString *orderByFirstString = [[[[e elementsForName:@"customer"] objectAtIndex:0] childAtIndex:2] stringValue];
NSString *orderByLastString = [[[[e elementsForName:@"customer"] objectAtIndex:0] childAtIndex:3]stringValue];
orderByString = [NSString stringWithFormat:@"%@ %@",orderByFirstString,orderByLastString];
NSLog(@"order By String: %@",orderByString);
}
}
非常感謝您的任何幫助或建議。
有人請幫忙。 – 2012-01-31 04:11:11
可能的重複[如何解析這個XML使用GDataXML分析器?](http://stackoverflow.com/questions/9156302/how-can-i-parse-this-xml-using-gdataxml-parser) – 2013-01-31 06:25:57