views:

33

answers:

1

Say I have an invalid XML. For some reason, TouchXML still sees it as a valid object.

For example:

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]);

The output is:

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

Does anybody know why this is happening? I'm not tidying up the XML...

Thanks!

A: 

Found a way around this. Inside

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

For my purposes, I changed

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

to

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