对于示例XML:
<aaa name ="a1">
<bbb name="b1"/>
<bbb name="b2"/>
<ccc name="c1">
<bbb name="b3"/>
</ccc>
<ddd name="d1">
<bbb name="b4"/>
</ddd>
</aaa>
我想选择所有父节点不是bbb
节点的ccc
个节点。这将是名称为b1
,b2
和b4
的节点。
我已经尝试过XPath /aaa//bbb[not(parent::ccc)]
,但这仍然会选择https://codebeautify.org/Xpath-Tester处的所有bbb
节点。
答案 0 :(得分:1)
CodeBeautify.org是错误的,并且您的XPath是正确的。
您的XPath应该选择
library("ggplot2")
set.seed(111018)
interval1 <- -qnorm((1-0.9)/2)
means_treatment_1 <- rnorm(2)
se_treatment_1 <- rnorm(2)
df_treatment_1 <- data.frame("Mean" = means_treatment_1,
"lower" = means_treatment_1 - se_treatment_1*interval1,
"upper" = means_treatment_1 + se_treatment_1*interval1,
"Variable" = c("medicare_spending_dummy",
"job_training_dummy"),
"Treatment" = "a")
means_treatment_2 <- rnorm(2)
se_treatment_2 <- rnorm(2)
df_treatment_2 <- data.frame("Mean" = means_treatment_2,
"lower" = means_treatment_2 - se_treatment_2*interval1,
"upper" = means_treatment_2 + se_treatment_2*interval1,
"Variable" = c("medicare_spending_dummy",
"job_training_dummy"),
"Treatment" = "b")
df_tot<-rbind(df_treatment_1, df_treatment_2)
# Plot
ggplot(df_tot, aes(colour = Treatment)) +
geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) +
geom_pointrange(aes(x = Variable, y = Mean, ymin = lower, ymax = upper ),lwd = 1, position = position_dodge(width = 1/2)) +
coord_flip() +
theme_bw()
满足您的期望,即未选择<bbb name="b1"/>
<bbb name="b2"/>
<bbb name="b4"/>
。
鉴于这种基本问题,我会避免使用CodeBeautify。
以下是两个返回正确结果的备用XPath在线站点:
答案 1 :(得分:0)
这通过使用xpath解决了
/aaa//bbb[local-name(..) != 'ccc']