我需要从XML中提取两个类似于以下内容的数据。
首先,我需要所有IncidentDetail文本,其中Dispatch ID是" JJJJ",LogType是" KKKK",且IncidentDetail本身包含文字" Subset from xpath query"。
第二,我需要包含此类事件的任何事件的日志ID字符串。
<Dispatch ID = "JJJJ">
<Log ID = "150504BCFSP00072">
<LogTime>"May 4 2015 5:48PM"</LogTime>
<LogType>"1125-KKKK"</LogType>
<LogDetails>
<details>
<DetailTime>"May 4 2015 5:48PM"</DetailTime>
<IncidentDetail>"[1] The Thing I Want"</IncidentDetail>
<DetailTime>"May 4 2015 5:49PM"</DetailTime>
<IncidentDetail>"[2] The Thing I Don't Want"</IncidentDetail>
</details>
</LogDetails>
</Log>
<Log ID = "250504BCFSP00072">
<LogTime>"May 5 2015 5:48PM"</LogTime>
<LogType>"1125-MMMM"</LogType>
<LogDetails>
<details>
<DetailTime>"May 5 2015 5:48PM"</DetailTime>
<IncidentDetail>"[1] A Thing I Don't Want"</IncidentDetail>
<DetailTime>"May 5 2015 5:49PM"</DetailTime>
<IncidentDetail>"[2] A Thing I Don't Want"</IncidentDetail>
</details>
</LogDetails>
</Log>
<Log ID = "350504BCFSP00072">
<LogTime>"May 6 2015 5:48PM"</LogTime>
<LogType>"1125-KKKK"</LogType>
<LogDetails>
<details>
<DetailTime>"May 6 2015 5:48PM"</DetailTime>
<IncidentDetail>"[1] Another Thing I Want"</IncidentDetail>
<DetailTime>"May 6 2015 5:49PM"</DetailTime>
<IncidentDetail>"[2] Another Thing I Don't Want"</IncidentDetail>
</details>
</LogDetails>
</Log>
</Dispatch>
以下XPATH查询满足第一个条件。它为上面条件1)为真的事件提取IncidentDetail。 (原始讨论here。)
//Dispatch[@ID='JJJJ' and Log/LogType[contains(.,'KKKK')]]/Log/LogDetails/details/IncidentDetail[contains(.,'[1]')]
现在我需要每个这种情况的唯一日志ID。在这个XML的子字符串中,我想要&#34; 150504BCFSP00072&#34;。在完整的XML中,可能会记录许多事件,因此许多日志ID,其中只有一些包含与我上面描述的三个过滤器匹配的事件。换句话说,只需要提取某些日志ID并与IncidentDetail字符串匹配。
我希望实际输出看起来如下:
<IncidentDetail>"[1] The Thing I Want"</IncidentDetail>
<Log ID = "150504BCFSP00072">
<IncidentDetail>"[1] Another Thing I Want"<IncidentDetail>
<Log ID = "350504BCFSP00072">
etc.
我如何进行第二次提取并以某种方式将其与第一次XPATH查询的结果联合起来?为我的问题语法提前道歉。我对XPATH比较陌生,而且我还在整理可能的,什么不是,以及你如何询问它。