Jayraj Gohil
Jayraj Gohil

Reputation: 1

how to read webService from server using Xcode?

![I tried to read xml file using Xcode but it give response in String and xml will show like in following image and it give < and > behalf of < and >][1]

I am trying to read mywebservice from server. i wrote web service which create file in xml formate in website. when i check that file on website uing internet it shows like following:

<NewDataSet>
  <Table>
    <Column1>Audi</Column1>
  </Table>
  <Table>
    <Column1>BMW</Column1>
  </Table>
  <Table>
    <Column1>MINI</Column1>
  </Table>
</NewDataSet>

but when i call that file via soap it gives response in following:

&lt;NewDataSet&gt;
  &lt;Table&gt;
 &lt;Column1&gt;Audi&lt;/Column1&gt;
 &lt;/Table&gt;
  &lt;Table&gt;
 &lt;Column1&gt;BMW&lt;/Column1&gt;
 &lt;/Table&gt;
 &lt;Table&gt;
 &lt;Column1&gt;MINI&lt;/Column1&gt;
 &lt;/Table&gt;
&lt;/NewDataSet&gt;

but i can't read the tag like 'NewDataSet' because it give back response in String and i am new in XML so please help me.. i use Xcode and nsmutabledata for that..!! i tried stringbyReplaceofOccurance but it did not replace &lt and &gt with < >. Thanks in Advance.

Thanks in advance for helping.

Upvotes: 0

Views: 1362

Answers (3)

Abdullah Md. Zubair
Abdullah Md. Zubair

Reputation: 3324

This is not a parsing problem. Check the web service and make sure that xml header is: <?xml version="1.0" encoding="utf-8"?> or something like this.

Upvotes: 0

Paras Joshi
Paras Joshi

Reputation: 20551

you use best way of read xml file with TouchXML ....and for TouchXML use this bellow link

http://dblog.com.au/general/iphone-sdk-tutorial-building-an-advanced-rss...

also here when you get response then other way you can read like bellow using TouchXML.. ie..

- (void) fetchDataSuccessforEvent:(NSMutableData *)data
{
    CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:data options:0 error:nil] autorelease];
    NSArray *nodes = [doc nodesForXPath:@"//Table" error:nil];

    for (CXMLElement *node in nodes) 
    {


        for(int counter = 0; counter < [node childCount]; counter++) 
        {
            if ([[[node childAtIndex:counter] name] isEqualToString:@"Column1"]) 
            {
                NSString *string = [[node childAtIndex:counter] stringValue];
                                NSLog(@"\n\n Title %@",string);

            }

        }


    }

}

so easy... hope,this help you.... :)

Upvotes: 0

Related Questions