对于解析,您可以使用需要以下类的 TBXML。TBXML.h、TBXML.m 和 NSDataAdditions.h、NSDataAdditions.m。
我给出了一个示例。您可以根据您的代码进行更改
NSString *cStr = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><SetPatientBPXMLResponse xmlns=\"http://webservice.cruxmed.com/\"><SetPatientBPXMLResult><response><state><![CDATA[45djx96.jpg]]></state></response></SetPatientBPXMLResult></SetPatientBPXMLResponse></soap:Body></soap:Envelope>"];
TBXML *tbxmlObj = [[TBXML alloc] initWithXMLString:cStr];
// Obtain root element
TBXMLElement * root = tbxmlObj.rootXMLElement;
//-------------------------------------------
if (root)
{
//-------------------------------------------
// search for the first NewDataSet element within the root element's children
// instantiate an NewDataSet objectGetDataInXMLFromStoredProcedureResponse
TBXMLElement * SoapBody = [TBXML childElementNamed:@"soap:Body" parentElement:root];
TBXMLElement * SoapResponse = [TBXML childElementNamed:@"SetPatientBPXMLResponse" parentElement:SoapBody];
TBXMLElement * SoapResult = [TBXML childElementNamed:@"SetPatientBPXMLResult" parentElement:SoapResponse];
//TBXMLElement * NewDataSet1 = [TBXML childElementNamed:@"response" parentElement:SoapResult];
TBXMLElement * NewDataSet = [TBXML childElementNamed:@"response" parentElement:SoapResult];
// if an _wspGetChartTemplateByAgent element was found
while (NewDataSet != nil) {
//cAccountName,fOrdTotTaxDEx,fOrdTotTax,;
// instantiate a Order object
// find the iInvoiceId
TBXMLElement * AutoIndex = [TBXML childElementNamed:@"state" parentElement:NewDataSet];
if (AutoIndex != nil)
{
NSString* iVal=[TBXML textForElement:AutoIndex] ;
NSLog(@"iVal:%@",iVal);
}
// find the next sibling element named "_wspGetChartTemplateByAgent"
NewDataSet = [TBXML nextSiblingNamed:@"response" searchFromElement:NewDataSet];
}
}