XPath - 在模板中遍历另一个XML元素的更有效方法是什么 [英] XPath - what is the more efficient approach to traverse to another XML element within a template

查看:60
本文介绍了XPath - 在模板中遍历另一个XML元素的更有效方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

使用(../../node/I/require)遍历备份文档树或者最好直接拍摄到节点(/ / node / I / require),请记住我在处理XML文件特定区域数据的模板中。

感谢


Tryst

Hi all,

is it good practice to traverse back up a document tree using (../../node/I/require) or is best to directly shoot to the node (//node/I/require), baring in mind that I am in a template that is handling data for a specific area of the XML file.

Thanks


Tryst

推荐答案

这完全取决于文档的结构以及嵌套的深度,但一般来说//节点非常昂贵,因为必须分离整个文档。如果你知道你可以去祖父母找到你的节点然后使用../../node,这应该更便宜,并且对于读取代码的任何人来说也更清楚,然后按照这种方式执行//节点它不清楚你可能只对祖父母的孩子(或后代)感兴趣。
It all depends on how your document is structured and how deeply it is nested but generally //node is very expensive as that way the complete document has to be seached. If you know you can go up to the grandparent to find your node then use ../../node, that should be less expensive and is also clearer for anyone reading the code then doing //node as that way it is not clear that you might only be interested in a child (or descendant) of the grandparent.


这篇关于XPath - 在模板中遍历另一个XML元素的更有效方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆