2010-07-21 53 views
2

說我有一個無效的XML。出於某種原因,TouchXML仍然認爲它是一個有效的對象。TouchXML - 無效的XML不返回錯誤對象

例如:

NSString *str = @"?> obviously invalid!"; 
NSData *data = [str dataUsingEncoding:NSASCIIStringEncoding]; 
NSError *parseError = nil; 
CXMLDocument *document = [[[CXMLDocument alloc] initWithData:data encoding:NSASCIIStringEncoding options:0 error:&parseError] autorelease]; 
NSLog(@"Error %i......%@", [parseError code], [parseError localizedFailureReason]); 
NSLog(@"Document ......%@", [document description]); 

輸出是:

Error 0......(null) 
    Document ......<CXMLDocument 0x6f05710 [0x6f274c0]> <?xml version="1.0" encoding="us-ascii"?> 

有誰知道爲什麼發生這種情況?我沒有收拾XML ...

謝謝!

回答

0

找到了解決辦法。裏面

- (id)initWithData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError 

對於我而言,我改變

theDoc = xmlReadMemory([inData bytes], [inData length], NULL, enc, XML_PARSE_RECOVER | XML_PARSE_NOWARNING); 

theDoc = xmlReadMemory([inData bytes], [inData length], NULL, enc, XML_PARSE_DTDVALID | XML_PARSE_NOWARNING);