简体   繁体   中英

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.

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.... :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM