鉴于此 XML
<DateInfo date="2016/02/02 13:11:12">
<Year>2016</Year>
<Month number="2">February</Month>
<Day ofMonth="2" ofYear="33">Tuesday</Day>
<Hour am="false" pm="true">13</Hour>
<Minute>11</Minute>
<Second>12</Second>
<Monday is="false" numInMonth="0" firstInMonth="false" lastInMonth="false" />
<Tuesday is="true" numInMonth="1" firstInMonth="true" lastInMonth="false" />
<Wednesday is="false" numInMonth="0" firstInMonth="false" lastInMonth="false" />
<Thursday is="false" numInMonth="0" firstInMonth="false" lastInMonth="false" />
<Friday is="false" numInMonth="0" firstInMonth="false" lastInMonth="false" />
<Saturday is="false" numInMonth="0" firstInMonth="false" lastInMonth="false" />
<Sunday is="false" numInMonth="0" firstInMonth="false" lastInMonth="false" />
<WeekDay is="true" isFirstWeekDay="false" isLastWeekDay="false" />
<Weekend is="false" />
<DueDay>Tuesday</DueDay>
</DateInfo>
如何获取 firstInMonth
的值名称为 <DueDay>
值的元素的属性元素?
例如,DueDay
是 Tuesday
所以我想获取 firstInMonth
的值元素的属性 Tuesday
,即“真实”。
我正在现有框架中工作,无法访问 XPath 2。
最佳答案
要选择名称由 DueDay
子项指定的 DateInfo
子项的 @firstInMonth
属性,请使用以下 XPath 1.0 表达式:
/DateInfo/*[name() = ../DueDay]/@firstInMonth
对于您的 XML,这将根据要求选择 true
。
关于xml - 选择名称包含在另一个节点中的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35155919/