Objective c 如何使用objective c从xml信封中提取xml soap正文?

Objective c 如何使用objective c从xml信封中提取xml soap正文?,objective-c,xml,soap,kissxml,Objective C,Xml,Soap,Kissxml,如何使用objective c从xml信封中提取xml soap正文 <soap:Envelope xmlns:c="http:************************" xmlns:soap="http://********************" xmlns:n1="http://**************" xmlns:n2="http:***********"> <soap:Header> </soap:Header> <soap

如何使用objective c从xml信封中提取xml soap正文

<soap:Envelope xmlns:c="http:************************" 
xmlns:soap="http://********************" 
xmlns:n1="http://**************" xmlns:n2="http:***********">
<soap:Header>
</soap:Header>
<soap:Body>
    <n1:GetDeviceConfiguration id="o0" c:root="1">
        <n1:request>
            <n2:Header>
                <n2:DeviceName>Tester Phone</n2:DeviceName>
                <n2:DeviceIpAddress>***********</n2:DeviceIpAddress>
                <n2:AppVersion>1.2</n2:AppVersion>
                <n2:RequestTime>2018-01-10T10:10:27</n2:RequestTime>
                <n2:MessageId>******************</n2:MessageId>
            </n2:Header>
            <n2:Body>
                <n2:LastUpdate>2017-08-06T15:34:00</n2:LastUpdate>
            </n2:Body>
        </n1:request>
    </n1:GetDeviceConfiguration>
</soap:Body>

测试电话
***********
1.2
2018-01-10T10:10:27
******************
2017-08-06T15:34:00


从这个xml中,我想使用objective C提取soap:Body。

您可以使用XMLParser提取soap正文

首先将xml转换为NSData并调用解析器对其进行解析

    //converting into NSData
    NSData* data = [theXML dataUsingEncoding:NSUTF8StringEncoding];

    //initiate  NSXMLParser with this data
    NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];

    //setting delegate
    parser.delegate = self;

    //call the method to parse
    BOOL result = parser.parse;

    parser.shouldResolveExternalEntities = true;
现在,您需要在类中实现NSXMLParser委托

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary<NSString *,NSString *> *)attributeDict {
currentElement = elementName;
NSLog(@"CurrentElementl: [%@]",elementName);
}

您将在xml的键下找到该值

不要忘记将NSXMLParserDelegate添加到类接口中

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSLog(@"foundCharacters: [%@]",string);