我正在嘗試使用TouchXml爲此解析xml文件。不幸的是,我得到錯誤解析XML時得到錯誤
實體:行1:分析器錯誤:預期的開始標記,'<'沒有找到,即使解析示例 xml是絕對正確的。
代碼是:
NSString *path = [[NSBundle mainBundle] pathForResource:@"SampleXml" ofType:@"xml"];
NSData *xmlData = [[NSData alloc] initWithContentsOfFile:path];
NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:1];
CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:xmlData options:0 error:nil]autorelease];
NSArray *nodes = NULL;
nodes = [doc nodesForXPath:@"//nodeX" error:nil];
for(CXMLElement *node in nodes){
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
int counter;
for(counter = 0; counter < [node childCount]; counter++){
NSString * value = [[[node childAtIndex:counter] stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if(value){
[item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
}}
[item setObject:[[node attributeForName:@"id"] stringValue] forKey:@"id"];
[result addObject:item];
[item release];
}
NSLog(@"%@",result);
}
或許它與touchXml類的問題還是我做錯了什麼?請幫忙。
您是否首先檢查了XML文件? –
是的,它是正確的文件 –
開始哪個最簡單: <? xml version =「1.0」?> 如果有效。 –