将XPath应用于节点,而不是整个文档

时间:2018-01-26 20:45:16

标签: r xpath

XML包中的

,有getNodeSet(doc, path, ...)xpathApply(doc, path, ...)等函数,可以将特定的xpath应用于XML文档。如果我想将xpath应用于节点怎么办?例如:

myMatches <- getNodeSet(doc, '/html/body/table/tr') # list of nodes
myNode1 <- myMatches[[1]] # I want to work further only within this node 
mySubMatches <- getNodeSet(myNode1, '/tr/td') # this tries to look in the whole doc instead of just myNode1

1 个答案:

答案 0 :(得分:0)

xpath开头的斜杠意味着从根开始。尝试不使用前导斜杠来搜索该节点。尝试

mySubMatches <- getNodeSet(myNode1, 'tr/td')