Getting the value of an Element in Cocoa using TouchXML

心不动则不痛 提交于 2019-11-27 21:29:17

The problem is that your XML has a namespace, which means your XPath does not actually match. Unfortunately there is no default mapping, and XPath does not actually define a good way to handle this internally, so you can't fix it simply by changing the XPath. Instead you need to inform the interpreter how you want to map it in your XPath.

It looks like TouchXML implements support for this via:

- (NSArray *)nodesForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error;

So you can try something like:

NSDictionary *mappings = [NSDictionary dictionaryWithObject:@"http://tempuri.org/webservices" forKey:@"tempuri"];
[myParser nodesForXPath:@"//tempuri:FundInfo" namespaceMappings:mappings error:&err];

I had a similar problem. ANY selection on an XML that has a namespace specified (xmlns="http://somenamespace") will result in no nodes found. Very strange considering it does support the additional namespace formats such as xmlns:somenamespace="http://somenamespace".

In any case, by far the easiest thing to do is do a string replace and replace xmlns="http://tempuri.org/webservices with an empty string.

Overall I like touchxml, but I can't believe this bug still exists.

Try

NSArray *nodes = [myParser nodesForXPath:@"/FundInfo/*" error:&err];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!