nodesForXPath 不返回任何节点:TouchXML
我正在使用 TouchXML 使用 Web 服务,但无法按照教程读取节点。我确实收到了 CXMLDocument 元素,但是,我的nodesForXPath 调用始终返回NULL。可能出什么问题了?
XML 解析代码
NSMutableArray *res = [[NSMutableArray alloc] init];
NSData* valueData=[value dataUsingEncoding:NSUTF8StringEncoding];
// Do something with the CXMLDocument* result
CXMLDocument *result = [[[CXMLDocument alloc] initWithData:valueData options:0 error:nil] autorelease];
NSArray *nodes = NULL;
nodes = [result nodesForXPath:@"//Outputs" error:nil];
NSLog (@"Nodes is %@\n", nodes);
for (CXMLElement *node in nodes) {
NSLog (@"Test");
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
int counter;
NSLog (@"Child Count is %@\n",[node childCount]);
NSLog (@"Child node is%@\n",[[node childAtIndex:0] stringValue]);
for(counter = 0; counter <= [node childCount]; counter++) {
// common procedure: dictionary with keys/values from XML node
[item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
}
//[item setObject:[[node attributeForName:@"id"] stringValue] forKey:@"id"];
[res addObject:item];
[item release];
}
// and we print our results
NSLog(@"%@", res);
[res release];
}
XML:
<Nodes>
<Inputs>
<name>TestProgram</name>
</Inputs>
<Outputs>
<ReturnCode>0</ReturnCode>
<ReturnMessage>Success</ReturnMessage>
<NameDetails attr1="value1">Test Program</NameDetails>
<NameInstance attr1="value1">
<NameCharacteristics>
<Dob>04-25-2011</Dob>
</NameCharacteristics>
</NameInstance>
</Outputs>
</Nodes>
nodesForXPatch for //Outputs 始终返回 NULL。我想获取节点值。我尝试用 Dob 替换输出,但仍然得到一个空集。
I'm consuming a Web Service using TouchXML and I'm unable to read the nodes as per the tutorial. I do receive the CXMLDocument element, however, my nodesForXPath call always returns NULL. What could be wrong?
XML Parsing code
NSMutableArray *res = [[NSMutableArray alloc] init];
NSData* valueData=[value dataUsingEncoding:NSUTF8StringEncoding];
// Do something with the CXMLDocument* result
CXMLDocument *result = [[[CXMLDocument alloc] initWithData:valueData options:0 error:nil] autorelease];
NSArray *nodes = NULL;
nodes = [result nodesForXPath:@"//Outputs" error:nil];
NSLog (@"Nodes is %@\n", nodes);
for (CXMLElement *node in nodes) {
NSLog (@"Test");
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
int counter;
NSLog (@"Child Count is %@\n",[node childCount]);
NSLog (@"Child node is%@\n",[[node childAtIndex:0] stringValue]);
for(counter = 0; counter <= [node childCount]; counter++) {
// common procedure: dictionary with keys/values from XML node
[item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
}
//[item setObject:[[node attributeForName:@"id"] stringValue] forKey:@"id"];
[res addObject:item];
[item release];
}
// and we print our results
NSLog(@"%@", res);
[res release];
}
XML:
<Nodes>
<Inputs>
<name>TestProgram</name>
</Inputs>
<Outputs>
<ReturnCode>0</ReturnCode>
<ReturnMessage>Success</ReturnMessage>
<NameDetails attr1="value1">Test Program</NameDetails>
<NameInstance attr1="value1">
<NameCharacteristics>
<Dob>04-25-2011</Dob>
</NameCharacteristics>
</NameInstance>
</Outputs>
</Nodes>
nodesForXPatch for //Outputs always returns NULL. I want to fetch the node value. I tried replacing Outputs with Dob and still get an empty set.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论