Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在iOS SDK(iPad)中使用TouchXML解析SOAP结果_Iphone_Ipad_Ios_Soap_Touchxml - Fatal编程技术网

Iphone 在iOS SDK(iPad)中使用TouchXML解析SOAP结果

Iphone 在iOS SDK(iPad)中使用TouchXML解析SOAP结果,iphone,ipad,ios,soap,touchxml,Iphone,Ipad,Ios,Soap,Touchxml,我正在从事一个iPad项目,该项目使用Web服务中的函数。 处理Web服务连接、数据等工作。但是我无法使用TouchXML解析结果SOAP。从xml中获取节点总是返回0长度 输出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/XMLSche

我正在从事一个iPad项目,该项目使用Web服务中的函数。 处理Web服务连接、数据等工作。但是我无法使用TouchXML解析结果SOAP。从xml中获取节点总是返回0长度

输出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>






1c0e9ad0-a3be-4cd0-8f0d-0616a63a4e28
2

2
贝赫尔德

nl



解析器代码:


 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];

NSData*aData=[[NSData alloc]initWithBytes:[webData可变字节]
长度:[webData长度]]; NSString*xmlData=[[NSString alloc]initWithData:aData
编码:NSASCIIStringEncoding]; NSLog(@“%@”,xmlData); [xmldatarelease]; CXMLDocument*domUserIdentity=[[CXMLDocument alloc]initWithData:aData
选项:0
错误:nil]
自动删除]; [数据释放]; NSArray*nodesList=[domUserIdentity nodesForXPath:@//LogOnResult”错误:nil];//0长度 用于(节点列表中的CXMLElement*resultElement){ 对于(int计数器=0;计数器 NSString*elemName=[[resultElement子索引:计数器]名称]; NSString*elemValue=[[[resultElement childAtIndex:counter]
stringValue]
stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]]; [元素名称发布]; [elemValue release]; } } [节点列表发布];
知道我做错了什么吗

谢谢,这是很早以前的事


Inoel

尝试使用NSXMLDocument,它应该与CXMLDocument一样工作。以下是一些文档:

我建议使用XPath解析器。你没有做太多的事情,因此速度的提升是值得的。我个人的选择是。有一些更快更精确的解决方案,但我发现TFHpple的简单性很难被打败

例如:

NSData*data=[[NSData alloc]initWithContentsOfFile:@“example.html”];
//创建解析器 xpathParser=[[TFHpple alloc]initWithXMLData:data];
NSArray*元素=[xpathParser搜索:@”//LogOnResult];
TFHppleElement*element=[elements objectAtIndex:0];
//获取单元格标记中的文本 NSString*content=[元素内容];
[xpathParser发布]; [数据发布];
显然,您必须编写一些代码来保存所需的部分。查看这些数据,我可能会创建一个自定义的data holder类,您可以使用属性访问该类。您可以将XML解析为该类,然后将其另存为将要访问它的视图控制器中的属性


愉快的编码!

NSXMLDocument是一个特定于cocoa的东西,对吗?我不认为我可以在iOS SDK中使用它。我找不到任何库或框架来使用它。我意识到时间已经晚了,但是KissXML库()在iOS中复制了NSXMLDocument类(还添加了一些功能)。我与该库没有关联,但发现它在我自己的许多代码中非常有用!TFHpple?这种新的xml解析器是否可靠?这是我尝试使用TouchXML.xpath所做的,但它没有给出我想要的结果。:(TouchXML设置起来很麻烦。这就是我使用TFHpple的原因。它使用相同的Xpath表达式,但设置起来要容易得多。GitHub页面上的自述文件就是您需要的全部内容。
NSData *data = [[NSData alloc] initWithContentsOfFile:@"example.html"]; 
// Create parser xpathParser = [[TFHpple alloc] initWithXMLData:data];
NSArray *elements = [xpathParser search:@"//LogOnResult"];
TFHppleElement *element = [elements objectAtIndex:0];
// Get the text within the cell tag NSString *content = [element content];
[xpathParser release]; [data release];