<time-layout time-coordinate="local" summarization="none">
<layout-key>k-p24h-n7-1</layout-key>
<start-valid-time>2013-10-30T08:00:00-07:00</start-valid-time>
<end-valid-time>2013-10-30T20:00:00-07:00</end-valid-time>
<start-valid-time>2013-10-31T08:00:00-07:00</start-valid-time>
<end-valid-time>2013-10-31T20:00:00-07:00</end-valid-time>
<start-valid-time>2013-11-01T08:00:00-07:00</start-valid-time>
<end-valid-time>2013-11-01T20:00:00-07:00</end-valid-time>
<start-valid-time>2013-11-02T08:00:00-07:00</start-valid-time>
<end-valid-time>2013-11-02T20:00:00-07:00</end-valid-time>
<start-valid-time>2013-11-03T07:00:00-08:00</start-valid-time>
<end-valid-time>2013-11-03T19:00:00-08:00</end-valid-time>
<start-valid-time>2013-11-04T07:00:00-08:00</start-valid-time>
<end-valid-time>2013-11-04T19:00:00-08:00</end-valid-time>
<start-valid-time>2013-11-05T07:00:00-08:00</start-valid-time>
<end-valid-time>2013-11-05T19:00:00-08:00</end-valid-time>
</time-layout>
<time-layout time-coordinate="local" summarization="none">
<layout-key>k-p24h-n6-2</layout-key>
<start-valid-time>2013-10-30T20:00:00-07:00</start-valid-time>
<end-valid-time>2013-10-31T09:00:00-07:00</end-valid-time>
<start-valid-time>2013-10-31T20:00:00-07:00</start-valid-time>
<end-valid-time>2013-11-01T09:00:00-07:00</end-valid-time>
<start-valid-time>2013-11-01T20:00:00-07:00</start-valid-time>
<end-valid-time>2013-11-02T09:00:00-07:00</end-valid-time>
<start-valid-time>2013-11-02T19:00:00-07:00</start-valid-time>
<end-valid-time>2013-11-03T08:00:00-08:00</end-valid-time>
<start-valid-time>2013-11-03T19:00:00-08:00</start-valid-time>
<end-valid-time>2013-11-04T08:00:00-08:00</end-valid-time>
<start-valid-time>2013-11-04T19:00:00-08:00</start-valid-time>
<end-valid-time>2013-11-05T08:00:00-08:00</end-valid-time>
</time-layout>
<time-layout time-coordinate="local" summarization="none">
<layout-key>k-p3h-n35-3</layout-key>
<start-valid-time>2013-10-30T11:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-30T14:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-30T17:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-30T20:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-30T23:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-31T02:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-31T05:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-31T08:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-31T11:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-31T14:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-31T17:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-31T20:00:00-07:00</start-valid-time>
<start-valid-time>2013-10-31T23:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-01T02:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-01T05:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-01T08:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-01T11:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-01T14:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-01T17:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-01T23:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-02T05:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-02T11:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-02T17:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-02T23:00:00-07:00</start-valid-time>
<start-valid-time>2013-11-03T04:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-03T10:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-03T16:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-03T22:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-04T04:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-04T10:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-04T16:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-04T22:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-05T04:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-05T10:00:00-08:00</start-valid-time>
<start-valid-time>2013-11-05T16:00:00-08:00</start-valid-time>
</time-layout>
目前我正在使用Java中的XPath解析XML。一切都很好,直到我看到这三个街区。让我感到困惑的是,我遇到了三个<time-layout time-coordinate="local" summarization="none">
,每个都有不同类型的信息。我目前的“黑客”是将每个local
重命名为local1
,local2
和local3
,因此我通过/dwml/data/time-layout[@time-coordinate='local3']/start-valid-time/text()
解析XPath。这是一种黑客行为,但由于我将很快直接从提取此XML的网站上读取XML,我不想使用这种方式,或者也许,我不能使用该黑客。由于那里有三个类似命名的元素,如何只用XPath解析第三个元素,而不重命名其中一个属性?
谢谢!
P.S。 <layout-key>
值每次都不同,因此我无法将其硬编码到我的解析器中。
答案 0 :(得分:1)
那么你可以检查你的xpath谓词中是否存在<end-valid-time>
,如果它不存在,你就会看第3个元素。
//time-layout[not(./end-valid-time)]
这也是一个黑客攻击,但至少它只是在xpath中。
答案 1 :(得分:1)
使用谓词:
//time-layout[3]