我正在研究在WebService中使用函数的iPad项目。 处理web服务连接,数据等工程发现。但是我无法使用TouchXML解析结果SOAP。从xml中获取节点始终返回0长度。在iOS SDK(iPad)中使用TouchXML解析SOAP结果
输出XML:
<?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>
<LogOnResponse xmlns="http://coreservices.org/v1">
<LogOnResult>
<Id>1c0e9ad0-a3be-4cd0-8f0d-0616a63a4e28</Id>
<userId>2</userId>
<user>
<ID>2
<Name>Beheerder
<emailAddress />
<cultureName>nl-NL</cultureName>
</user>
</LogOnResult>
</LogOnResponse>
</soap:Body>
</soap:Envelope>
解析器代码:
NSData *aData = [[NSData alloc] initWithBytes:[webData mutableBytes]
length:[webData length]];
NSString *xmlData = [[NSString alloc] initWithData:aData
encoding:NSASCIIStringEncoding];
NSLog(@"%@", xmlData);
[xmlData release];
CXMLDocument *domUserIdentity = [[[CXMLDocument alloc] initWithData:aData
options:0
error:nil]
autorelease];
[aData release];
NSArray *nodesList = [domUserIdentity nodesForXPath:@"//LogOnResult" error:nil]; // 0 length
for (CXMLElement *resultElement in nodesList) {
for (int counter = 0; counter
NSString *elemName = [[resultElement childAtIndex:counter] name];
NSString * elemValue = [[[resultElement childAtIndex:counter]
stringValue]
stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[elemName release];
[elemValue release];
}
}
[nodesList release];
任何想法,我做了什么错?
非常感谢您的提前。
Inoel使用NSXMLDocument
NSXMLDocument是一个可可特定的事情吗?我不认为我可以在iOS SDK中使用它。我找不到任何库或框架来使用它。 – Inoel 2011-01-25 15:05:39
我意识到它迟到了,但KissXML库(http://code.google.com/p/kissxml/)复制了iOS中的NSXMLDocument类(并添加了一些功能)。我没有与图书馆联系,但是在我自己的代码中找到它非常有帮助! – 2011-05-07 23:50:14