1

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

The message string displayed in the <error> tag is descriptive only.
Then it's a bad message. URLs are case sensitive (other than the host and domain). If the parameter needs to be id then the message should state id, not Id. Anyway, log url then copy the URL to your browser and what do you get?
Logging the url I get url: http://domain.com/xml.php?id=00idcode00, but the querystring still isnt being used, and I still get the <error> tag returned instead of the data.
Perhaps there is an issue on the server side. What happens when you enter that URL in your computer's browser?
I get the 50 odd elements I was expecting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.