In article <oster-0ACA3B.22075428042008@[EMAIL PROTECTED]
>,
David Phillip Oster <oster@[EMAIL PROTECTED]
> wrote:
> In article
> <lazloman-91EB72.20371028042008@[EMAIL PROTECTED]
>,
> Can I Get a Word In <lazloman@[EMAIL PROTECTED]
> wrote:
>
> > I'm using NSXMLParser to read an XML do***ent from a server via
> > initiWithContentsOfURL. This works just fine under Leopard. I can read
> > and parse the data just fine, but under Tiger, I get an empty do***ent
> > error: NSXMLParserErrorDomain = 4 (Empty do***ent). There are several
> > posts in the archives about problems with NSXMLParser, but nothing
> > suggesting a Tiger bug leading to an empty do***ent. Unless someone
> > thinks there's something wrong with my code, I'm going to file a bug
> > with Apple.
> >
> > Here is my code:
> > NSXMLParser* locationData = [[[XMLParser alloc]
> > initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease];
> > [locationData setDelegate:self];
> > [locationData parse];
> > NSError* err = [locationData parseError]; <---Empty do***ent error
> >
> >
> > urlString is an NSString that was created using
> > stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding
> >
> > The do***ents encoding is actually Latin1, I pasted the last one I
tried
> > here. I've tried a few encodings, but they all fail with the same
error.
> > Any ideas?
>
> Do an NSData initWithContentsOfURL:, and see if you can convert it to a
> UTF8String, If you can't, you certainly couldn't expect NSXMLParser to
> handle it.
>
> Save the NSData to a file, and use the command line tool:
>
> tidy -e -xml -utf8 inFile
>
> and it will tell you about malformed XML.
tidy re****ted about 300 errors. That gave me the idea to try
NSXMLDo***ent, since it has the tidyXML option. This actually works.
Here's the code:
NSXMLDo***ent* theDoc = [[[NSXMLDo***ent alloc]
initWithContentsOfURL:[NSURL URLWithString:urlString]
options:NSXMLDo***entTidyXML error:&err] autorelease];
NSData* xmlData = [theDoc XMLData];
NSXMLParser* parser = [[[NSXMLParser alloc] initWithData:xmlData]
autorelease];
[parser setDelegate:self];
[parser parse];
I'm happy again.


|