Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 22, 2008, 06:14 AM   #1
tadelv
macrumors newbie
 
Join Date: Sep 2008
NSXMLParser Problem

I am having a problem with my own application that parses a xml file using NSXMLParser, however, the file does not have a valid xml start tag. This is how it looks like:
Code:
	<current_observation>
		<credit>Weather Underground Personal Weather Station</credit>
		<credit_URL>http://wunderground.com/weatherstation/</credit_URL>
		<image>
and so on...
I also get this in the console:
Code:
Operation could not be completed. (NSXMLParserErrorDomain error 5.)
When i try to process a different file, it works perfectly, and this other file has a xml start tag.

I tried allready to open the file to a string and then append the start tag, but when i try to open it the response from the server is like this:
Code:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>500 Internal Server Error</TITLE>
</HEAD><BODY>
<H1>Internal Server Error</H1>
The server encountered an internal error or
misconfiguration and was unable to complete
your request.<P>
Please contact the server administrator,
 support@wunderground.com and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.<P>
More information about this error may be available
in the server error log.<P>
<HR>
<ADDRESS>Apache/1.3.33 Server at b2.wunderground.com Port 80</ADDRESS>
</BODY></HTML>
Any suggestions? Using NSXMLDocument perhaps? I have tried NSXMLDocument with the "initWithContentsOfURL:xmlURL options:1 << 10 error:NULL" method but it returns null at initialization...

Last edited by WildCowboy; Sep 22, 2008 at 04:41 PM. Reason: thread split cleanup
tadelv is offline   0 Reply With Quote
Old Sep 22, 2008, 06:28 AM   #2
fishkorp
macrumors 68000
 
Join Date: Apr 2006
Like mentioned before, you need to specifically set each part of your object, you can't just say that the whole element found is your object. So in my didStartElement I do:

Code:
if ([elementName isEqualToString:@"WhatYoureLookingFor"]) {
	item = [[NSMutableDictionary alloc] init];
        propertyOne = [[NSMutableString alloc] init];
        propertyTwo = [[NSMutableString alloc] init];
}
Then in the didEndElement I do this:
Code:
if ([elementName isEqualToString:@"WhatYoureLookingFor"]) {
	[item setObject:propertyOne forKey:@"propOneTag"];
	[item setObject:propertyTwo forKey:@"propTwoTag"];
       // etc...
}
fishkorp is offline   0 Reply With Quote
Old Sep 22, 2008, 06:40 AM   #3
grimjim
macrumors member
 
Join Date: May 2003
Quote:
Originally Posted by tadelv View Post
Any suggestions? Using NSXMLDocument perhaps? I have tried NSXMLDocument with the "initWithContentsOfURL:xmlURL options:1 << 10 error:NULL" method but it returns null at initialization...
I don't recommend trying to use NSXMLDocument. It's not available on the iPhone (although it will work on the simulator). That's why we're all scratching away with NSXMLParser in the first place...

Last edited by WildCowboy; Sep 22, 2008 at 04:41 PM. Reason: thread split cleanup
grimjim is offline   0 Reply With Quote
Old Sep 23, 2008, 04:19 PM   #4
tadelv
Thread Starter
macrumors newbie
 
Join Date: Sep 2008
Ok, so here is what i've gathered so far:

The NSXMLParserErrorDomain error 5 is actually this:
Code:
NSXMLParserPrematureDocumentEndError
The document ended unexpectedly.

Available in Mac OS X v10.3 and later.

Declared in NSXMLParser.h
my guess is still that this is because of the missing start tag.

Still haven't found out why the NSString way doesnt work... and have sent a mail to support@wunderground, asking them to do something about it. They have it specified in the api documentation anyway, so i guess all i have to do is sit on my a** and wait for them to fix it
tadelv is offline   0 Reply With Quote
Old Sep 24, 2008, 04:54 AM   #5
grimjim
macrumors member
 
Join Date: May 2003
I don't fully understand what you're doing, but I think I can make some guesses that might help.

Firstly, I don't believe that the missing start tag (by which I assume you mean the <XML> tag) has anything to do with it. I can parse the XML from this site without it. You don't need it.

Secondly, the HTML error that you are getting back is probably due to a problem in the URL you are submitting to the site. If I submit a malformed URL, I get this error. I think that this is where your problem really lies. I suggest that you check that the request you are sending is correct. Other than that, I think I will need more info/code to help any further.
grimjim is offline   0 Reply With Quote
Old Sep 24, 2008, 12:19 PM   #6
tadelv
Thread Starter
macrumors newbie
 
Join Date: Sep 2008
Hi!

I just found out i was heading in the wrong direction with the <XML> tag...

Anyway, here is the console output:
Code:
2008-09-24 19:09:52.253 iVreme[9162:20b] lat = 46.051244, lon = 14.503061
2008-09-24 19:09:54.535 iVreme[9162:20b] started parsing for psw
2008-09-24 19:09:54.537 iVreme[9162:20b] Got stuff: ILJUBLJA3
2008-09-24 19:09:54.541 iVreme[9162:20b] request = 
2008-09-24 19:09:54.542 iVreme[9162:20b] request = http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=ILJUBLJA3
And the code(with comments in slovene):
Code:
NSMutableString *request = [[[NSMutableString alloc] init] autorelease];
	//Parsanje, da dobimo pws kodo
	[request appendString:@"http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query="];
	[request appendFormat:@"%@,%@",latitude,longitude];
	
	[main parseXMLForLocationAtURL:request];
	//Parsanje vremenskega stanja
	
	//cleanup :)
	[request setString:@""];
	NSLog(@"request = %@", request);
	[request appendString:@"http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID="];
	[request appendFormat:@"%@",[main postajaPWS]];
	NSLog(@"request = %@", request);
[main parseXMLFileAtURL:request];
and the parsing code:
Code:
 NSURL *xmlURL = [NSURL URLWithString:URL];
wUnderParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
	
    // Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
    [wUnderParser setDelegate:self];
	
    // Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
    [wUnderParser setShouldProcessNamespaces:NO];
    [wUnderParser setShouldReportNamespacePrefixes:NO];
    [wUnderParser setShouldResolveExternalEntities:NO];

	NSLog(@"started parsing");
    imeFertig = NO;
	[wUnderParser parse];
What i am trying to do here is the following:

- get the lat,long
- submit them to the "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=" to get the city
- parse the xml to get the Personal Weather Station ID
- reset the "request" string
- append the Personal Weather Station ID to "http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=" --> it works to here
-parse the file for weather info

The links are correct afaik, i tried copying/pasting to safari and they work so i am a little confused here. the only difference i see now is that the last url has an .asp ending

Thank you for your help!
tadelv is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
NSXMLParser MickeyT iPhone/iPad Programming 3 Jun 18, 2014 04:29 PM
iTunes DRM problem? Or, HD Versions of Movie on ATV1 Problem? Aqueous Apple TV and Home Theater 5 Feb 9, 2014 07:54 AM
NSXmlParser error leconteconte iPhone/iPad Programming 2 Feb 28, 2013 06:29 AM
Resolved: NSXMLParser fails after first element? ArtOfWarfare Mac Programming 2 Jul 17, 2012 07:30 PM

Forum Jump

All times are GMT -5. The time now is 05:03 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC