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
答案 0 :(得分:0)
xpath开头的斜杠意味着从根开始。尝试不使用前导斜杠来搜索该节点。尝试
mySubMatches <- getNodeSet(myNode1, 'tr/td')