NSXMLParsing data, retriving data problem during parsing - iphone

i am creating an app in which i want to take xmldata using webservices.
i am using NSXMLParser.
i get the data in respond data when this below method calling
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
//NSLog(#"====== Connection ========");
[catalogData appendData:data];
//NSLog(#"catalog data-=-=-=-=-=-=-%#", catalogData);
}
but when i parse this catalogData in finishloading method i get the null array.
i don't know what the problem is,
this is my XML data
3
1
1
<sPagRichiestaFornitore>
</sPagRichiestaFornitore>
<idCategoria>1</idCategoria>

NSLog your data inside connectionfinishloading then. If you get a proper XML, then you can create the XML parser accordingly.
You can refer the Top Paid Sample app of apple for the NSXMLParser Implementation.

i cannot help with such a small code friend . can you please tell what exactly you get in response if you not getting please check your php file that is on server some problem with that . One thing i suggest you is that once remove this tag from your php file and again try to get response
thanks
hope this helps

Related

how to log raw JSON response with RestKit 0.2x

with RestKit 0.2x the RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); statement displays various mapping info with the returned JSON response but all things are mixed up together which is hard for me to extract the raw JSON body alone.
is there a way to log ONLY the returned JSON body without extra info with it ?
thanks in advance.
You can add a logging code in RKNSJSONSerialization's method
+ (id)objectFromData:(NSData *)data error:(NSError **)error
or better solution would be to subclass RKNSJSONSerialization and add the logging code.
It isn't clear exactly what you're looking for. The trace log does print the entire JSON before the mapping starts.
Alternatively, you could edit RKMapperOperation to do additional logging or just use AFNetworking to download and log the JSON.

Validate a XML file in IOS

I have a XML parser. I'm getting the XML file from server and write that XML file in to a local file in cache. Before do that, I want to check the URL has the XML file. How Can I check the available URL's page is a XML page or another type of page(Ex:HTML,PHP)?? Simply how can I identify a XML file ??
Ultimately, you have to look at the contents of the data retrieved to make sure it's valid XML, and parsing is the easiest way to do that.
If you're retrieving the data via a HTTP request, you can, though, also look at the response you receive before you start receiving the actual data. For example, if using NSURLConnection, you can implement a didReceiveResponse, which should often return a 200 for status code and text/xml for content type:
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
if ([response isKindOfClass:[NSHTTPURLResponse class]])
{
NSHTTPURLResponse *httpResponse = (id)response;
NSInteger statusCode = httpResponse.statusCode;
NSString *contentType = httpResponse.allHeaderFields[#"Content-Type"];
NSLog(#"%d; %#", statusCode, contentType);
// check to see if statusCode == 200 and/or [contentType isEqualToString:#"text/xml"] here;
}
}
As an aside, the status code and the content type are set by the server, so it is, admittedly, dependent upon the server's implementation (e.g. if the XML is being generated programmatically by the server, hopefully it's setting these HTTP response fields correctly, but if you're retrieving XML from third party servers, you can't be guaranteed that they're well-behaved). But a status code of 200 and content type of "text/xml" are customary and most servers will set these values appropriately if you're just retrieving a XML file.
The most reliable technique for validating your XML is to just receive the data from the server, and submit it to a parser, and see if the parser returns an error or not.
There are various solution available for this:
http://knol2share.blogspot.in/2009/05/validate-xml-against-xsd-in-c.html
http://wiki.njh.eu/XML-Schema_validation_with_libxml2
Checking for proper xml before parsing in NSXMLParser
Hope this will help you.

WSDL connection throws an ADBException

In my app i am using WSDl webservice.And try to call webservice method.
In that request send successfuly and also get response.But when i fetch that response using following method:
// Called when the connection has finished loading.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError* error;
if(self.logging == YES) {
NSString* response = [[NSString alloc] initWithData: self.receivedData encoding: NSUTF8StringEncoding];
NSLog(#"response=%#", response);
[response release];
}
It gives following exception.
And my NSLog statement shows following details:
response=<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>org.apache.axis2.databinding.ADBException: Unexpected subelement {http://services.webservices.sparta.com}sSessionId</faultstring><detail /></soapenv:Fault></soapenv:Body></soapenv:Envelope>
Please suggest me the way to solve this issue.
Thank you.
From the question description we can not exactly figure out problem.
But from your log I can give you some suggestion to check your code :
<soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>
1) You may be passing wrong number of parameters to web-service.
2) The parameter data type may not be matching. for example, you are passing string where server accepting integer or vice-versa.
3) Or web-service having some problem.
you can also search on org.apache.axis2.databinding.ADBException: Unexpected subelement. There are many useful links which may help you to figure out whether problem is at your web-service or in your iphone coding.

How to fetch web service response as a string in iPhone?

I've webservice which converts CelsiusToFahrenheit. This webservice response is in string format instead of xml so how can I display a response in a label programmatically?
Is there a sample available for that?
The simplest method is a one-liner:
NSError *error = nil;
myLabel.text = [NSString stringWithContentsOfURL:myURL encoding:NSUTF8StringEncoding error:&error];
As with most one-line solutions, there's a caveat. This method blocks the current thread until the request completes or fails, so you'd better use it in conjunction with performSelectorInBackground:withObject: to avoid locking UI.
Here is a tutorial that I used to retrieve data from a web service using the requestWithURL method of NSURLRequest:
http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/
The example is for JSON, but you can just omit all of the JSON stuff from the tutorial, since the string response is going to be fed into your connectionDidFinishLoading method.

How to get corresponding response of corresponding URLConnection, if we use more than one URLConnection?

I am not sure how should i get corresponding URLConnection response data , if i use more than one URLConnection. Please help me out, i need to use more than one URLConnection?
Regards
Sri
Every callback you get has the URLConnection as its first parameter, for example
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
So you always know what connection the data belongs to.