iPhone 中的 Xpath 问题
在GdataXML中,我只能使用来自XML根的nodesforXpath,但我希望一旦我有了inferenceMembers,我想将Xpath应用于该节点的其余部分,但不是整个DOM树,这可能吗?
下面的示例在 for 循环中工作错误,带来了 DOM 中的所有变量,但是一旦我有了variableElement,我只想在variableElement上工作,而不是在整个DOM上工作。
NSArray *inferenceMembers = [doc nodesForXPath:@"//inferenceresponse/state/variable[not(valuedefinition/variablevalue)]" error:nil];
for (GDataXMLElement *variableElement in inferenceMembers) {
Variable *variable=[[Variable alloc] init];
NSArray *items = [variableElement nodesForXPath:@"//variable/domaindefinition/domain/enumType/domainitem" error:nil];
}
我想要这个的原因不是因为它很难做到,但我想如果我每次对整个 XML 进行 xpath 查询以到达同一元素的子元素,速度会更慢。我读到我可以使用命名空间和 NSDictionary 做一些魔法,但不知道该怎么做
In GdataXML I can only use nodesforXpath from the root of XML, but I want that once I have the inferenceMembers I would like to apply Xpath to rest of this node, but not whole DOM tree, is that possible?
Example below works wrong in for loop, brings all the varibles in the DOM, but I want to work only on the variableElement not whole the DOM once I have the variableElement.
NSArray *inferenceMembers = [doc nodesForXPath:@"//inferenceresponse/state/variable[not(valuedefinition/variablevalue)]" error:nil];
for (GDataXMLElement *variableElement in inferenceMembers) {
Variable *variable=[[Variable alloc] init];
NSArray *items = [variableElement nodesForXPath:@"//variable/domaindefinition/domain/enumType/domainitem" error:nil];
}
The reason I want this not because it is hard to do, but I guess it would be slower if I xpath query to whole XML to reach the same element's children each time. I have read that I can do some magic with namespaces and NSDictionary but do not know how to do
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
看看 XML 结构能够提供充分的帮助会很有用。
Try this:
It'd be useful to see the XML structure to be able to help fully.