我想找到沒有任何子節點的節點的父名稱。例如,我嘗試了我的 XPath 運算式,xpather.com它作業正常,但我無法讓它在 R 中作業。
//*[not(*)]/parent::*/name()
結果應該是 aa, ca
library(XML)
xml_doc <- ("<ca>
<ai>67400000</ai>
<ssci>FN</ssci>
<aa>
<ta>1280</ta>
<tc>EUR</tc>
</aa>
</ca>")
xml_parsed <- xmlParse(xml_doc)
a <- getNodeSet(xml_parsed, "//*[not(*)]/parent::*")
names(a)
uj5u.com熱心網友回復:
library(xml2)
doc <- read_xml(xml_doc)
# Xpath for parents of nodes without children
# xml_name() for name extraction
xml_name(xml_find_all(doc, ".//*[not(*)]/parent::*"))
# [1] "ca" "aa"
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/351654.html
上一篇:R-有條件的排列
下一篇:如何從觀星者輸出中洗掉模型型別?
