简体   繁体   中英

Parse XML Data response

I need help to parse data response. When I send parameter to Web Service then Web Service will give data in response I'm used wsdl2objc

for( ; cur != NULL ; cur = cur->next) {
            if(cur->type == XML_ELEMENT_NODE) {

                if(xmlStrEqual(cur->name, (const xmlChar *) "Body")) {
                    NSMutableArray *responseBodyParts = [NSMutableArray array];

                    xmlNodePtr bodyNode;
                    for(bodyNode=cur->children ; bodyNode != NULL ; bodyNode = bodyNode->next) {
                        if(cur->type == XML_ELEMENT_NODE) {
                            if(xmlStrEqual(bodyNode->name, (const xmlChar *) "selectDataReturn")) {
                                NSString  *bodyObject = [NSString  deserializeNode:bodyNode];

                                if (bodyObject != nil) [responseBodyParts addObject:bodyObject];


                            }

                            if (xmlStrEqual(bodyNode->ns->prefix, cur->ns->prefix) && 
                                xmlStrEqual(bodyNode->name, (const xmlChar *) "Fault")) {
                                SOAPFault *bodyObject = [SOAPFault deserializeNode:bodyNode];

                                if (bodyObject != nil) [responseBodyParts addObject:bodyObject];

                            }
                        }
                    }

                    response.bodyParts = responseBodyParts;

                    //bodyParts is my data.

                }
            }
        }

But my bodyParts response to me:

<?xml version='1.0' encoding='UTF-8'?><EISDataRS><EISDataRecord><RECSEQ>1</RECSEQ><INPUT_DATE>201201</INPUT_DATE><PREFIX_BU>AAA</PREFIX_BU><INDEX_LEVEL>10000</INDEX_LEVEL><CF>83.94</CF></EISDataRecord><EISDataRecord><RECSEQ>2</RECSEQ><INPUT_DATE>201201</INPUT_DATE><PREFIX_BU>AAA</PREFIX_BU><INDEX_LEVEL>20100</INDEX_LEVEL><CF>73.94</CF></EISDataRecord><EISDataRecord><RECSEQ>1</RECSEQ><INPUT_DATE>201201</INPUT_DATE><PREFIX_BU>AAA</PREFIX_BU><INDEX_LEVEL>22100</INDEX_LEVEL><CF>57.44</CF></EISDataRecord></EISDataRS>

How I can parse data in wsdl2objc or how should I parse on resp.bodyParts in view controller I just need text data only Please Advice. Thanks.

If you want to parse XML data, look into XMLDictionary.

It is an easy framework that easily parses your data into a neat and ordered hierarchy of NSDictionaries and NSArrays.

https://github.com/nicklockwood/XMLDictionary

I had the same issue and I fixed it by parsing the correct body name.

In your code, try replacing selectDataReturn with EISDataRS . Because from your response I can see EISDataRS is your child.

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