Reputation: 10139
So Ive built an XML parser using the tutorial here: http://www.codeproject.com/Articles/248883/Objective-C-Fundamentals-NSXMLParser
My problem is that the XML file I am calling requires a querystring parameter. An example url would be something like:
http://domain.com/xml.php?id=00idcode00
Without the id=
the XML file just returns a single XML element <error>No id specified</error>
; with an id specified the XML file returns 50 odd XML elements.
My problem is that no matter what I try the XML file always returns the <error>
. How do I get NSURL to use the querystring?
Here is my code:
NSString *someId = @"00idcode00";
NSString *urlString = [NSString stringWithFormat:@"http://domain.com/xml.php?id=%@", someId];
NSURL *url = [NSURL URLWithString:urlString];
parser=[[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser parse];
NSLog(@"query: %@",[url query]);
And this NSLogs the following:
Started element error
Found an element named: error with a value of: No id specified.
query: id=00idcode00
The last line where I output the query
of url
implies that the NSURL has the right querystring, but the response of the XML file suggests that NSURL is not using the querystring.
Can anybody help?
Upvotes: 1
Views: 441
Reputation: 318954
Build the string first, then the URL.
NSString *someId = @"00idcode00";
NSString *urlString = [NSString stringWithFormat:@"http://domain.com/xml.php?Id=%@", someId];
NSURL *url = [NSURL URLWithString:urlString];
And the error states the query param is Id
, not id
.
Upvotes: 2