xml – XPath选择多个标签
发布时间:2020-12-16 02:02:34 所属栏目:百科 来源:网络整理
导读:给定这个简化的数据格式: a b cC1/c dD1/d eE1/e fdon't select this one/f /b b cC2/c dD2/d eE1/e gdon't select me/g /b cnot this one/c dnor this one/d edefinitely not this one/e/a 你如何选择所有的Cs,Ds和Es是B元素的子项? 基本上,类似: a/b/
给定这个简化的数据格式:
<a> <b> <c>C1</c> <d>D1</d> <e>E1</e> <f>don't select this one</f> </b> <b> <c>C2</c> <d>D2</d> <e>E1</e> <g>don't select me</g> </b> <c>not this one</c> <d>nor this one</d> <e>definitely not this one</e> </a> 你如何选择所有的Cs,Ds和Es是B元素的子项? 基本上,类似: a/b/(c|d|e) 在我自己的情况下,而不是只是a / b /,查询导致选择那些C,D,E节点实际上是相当复杂,所以我想避免这样做: a/b/c|a/b/d|a/b/e 这可能吗?
一个正确的答案是:
/a/b/*[self::c or self::d or self::e] 请注意这一点 a/b/*[local-name()='c' or local-name()='d' or local-name()='e'] 是太长和不正确??。此XPath表达式将选择如下节点: OhMy:c NotWanted:d QuiteDifferent:e (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |