我有一个非常长的xml文档(100k行),我想看看是否包含一个字符串。以下是我目前正在做的事情:
'HDRENT' in etree.tostring(node)
有更有效的方法吗?我不认为打印整个xml文档是必要的,如果我能以更直接/更快的方式完成它。
答案 0 :(得分:1)
试试xpath:
* installing *source* package ‘viridis’ ...
** package ‘viridis’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Warning: S3 methods ‘fullseq.Date’, ‘fullseq.POSIXt’, ‘fullseq.numeric’, ‘print.trans’ were declared in NAMESPACE but not found
Error in library.dynam(lib, package, package.lib) :
shared object ‘scales.so’ not found
ERROR: lazy loading failed for package ‘viridis’
如果'HRDENT'出现在html标签的文本中,则应返回true,否则返回false。
如果'HRDENT'出现在标签的属性中,请使用:
node.xpath("count(//text()[contains(.,'HDRENT')]) > 0")