Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by IPaPa for NSXML parsing error when used with NSData

My friend do the parser job, NSString* xmlData = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

xmlData should look like
abc and my friend just analyze the string,and it's work

and I used libxml2 to parse xml with

xmlTextReaderPtr reader = xmlReaderForMemory([data bytes], [data length], NULL, NULL,             (XML_PARSE_NOBLANKS | XML_PARSE_NOCDATA | XML_PARSE_NOERROR | XML_PARSE_NOWARNING));if (reader != NULL) {    ret = xmlTextReaderRead(reader);    while (ret == 1) {        const xmlChar *name, *value;        name = xmlTextReaderConstName(reader);        if (name == NULL)        name = BAD_CAST "--";        NSString *Name = [NSString stringWithCString:(const char*)name encoding:NSUTF8StringEncoding];        value = xmlTextReaderConstValue(reader);        if (value == NULL)            value = BAD_CAST "\n";        NSString *Value = [NSString stringWithCString:(const char*)value encoding:NSUTF8StringEncoding];        NSLog("%d %d %@ %d %@",         xmlTextReaderDepth(reader),        xmlTextReaderNodeType(reader),        Name,        xmlTextReaderIsEmptyElement(reader),        Value);        ret = xmlTextReaderRead(reader);    }    xmlFreeTextReader(reader);  }

and result is correct too


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles