여기에서 xml을 구문 분석하려고하는데 내 CXMLElement를 올바르게 가져 오려고합니다. 하나는, 예를 들어,이iOS CXMLElement StringValue
<CXMLElement 0x1d8cfdc0 [0x1c556660] TrackDetail <TrackDetail>Tracked</TrackDetail>>
기록하지만이 경우 Tracked
에, 문자열 값을 얻을 수 없습니다. 시도했습니다.
CXMLNode *title = [[fd objectAtIndex:indexPath.row] nodeForXPath:@"TrackDetail" error:nil];
을 로깅합니다. 누구든지 CXMLElement의 stringValue를 얻는 방법을 알고 있습니까?
을 Heres 예제 XML
<TrackResponse>
<TrackInfo ID="9400110200793563195827">
<TrackSummary>
The delivery status for this item has not been updated as of February 07, 2013, 11:34 pm.
</TrackSummary>
<TrackDetail>
Out for Delivery, February 07, 2013, 9:34 am, MASSAPEQUA, NY 11758
</TrackDetail>
<TrackDetail>
Sorting Complete, February 07, 2013, 9:24 am, MASSAPEQUA, NY 11758
</TrackDetail>
<TrackDetail>
Arrival at Post Office, February 07, 2013, 6:00 am, MASSAPEQUA, NY 11758
</TrackDetail>
<TrackDetail>
Depart USPS Sort Facility, February 05, 2013, GRAND FORKS, ND 58201
</TrackDetail>
<TrackDetail>
Processed at USPS Origin Sort Facility, February 04, 2013, 7:13 pm, GRAND FORKS, ND 58201
</TrackDetail>
<TrackDetail>
Accepted at USPS Origin Sort Facility, February 04, 2013, 5:58 pm, EAST GRAND FORKS, MN 56721
</TrackDetail>
<TrackDetail>
Electronic Shipping Info Received, February 04, 2013
</TrackDetail>
<TrackDetail>
Shipment Accepted, February 04, 2013, 2:19 pm, EAST GRAND FORKS, MN 56721
</TrackDetail>
</TrackInfo>
</TrackResponse>
와 나는이
NSArray *arr = [parser nodesForXPath:@"//TrackResponse/TrackInfo/TrackSummary" error:nil];
NSArray *p = [parser nodesForXPath:@"//TrackResponse/TrackInfo" error:nil];
if ([p count]>0) {
for (CXMLElement *resultElement in p) {
for(int counter = 0; counter < [resultElement childCount]; counter++) {
NSLog(@"%@", [[[resultElement nodesForXPath:@"TrackDetail" error:nil] objectAtIndex:counter] stringValue]);
[self.arr1 setObject:[[[resultElement nodesForXPath:@"TrackDetail" error:nil] objectAtIndex:counter] stringValue] forKey:@"det"];
}
}
}
누구나 알고 계십니까? –
샘플 xml을 추가하십시오. 아마 제 3 자 라이브러리를 사용하는 것보다 내장 된 xml 파서를 사용하는 것이 더 쉽습니다 (나는 경험에서 이야기합니다 ^^). 이 답변을 참조하십시오 http://stackoverflow.com/a/7295767/207616 –