搜索XML文档

时间:2013-09-21 02:57:51

标签: java xml parsing

我正在试图弄清楚如何搜索某个块的XML文档(Block?String?我是新手......)并返回...块的其余部分?我目前正在使用XStream作为我的处理程序,但是没有找到任何关于做特定事情的事情。

以下是代码示例(时间500,000):

<conversation>
    <input>HELLO</input>
    <response>
        <text>HELLO MATE</text>
        <hits>2</hits>
    </response>
    <response>
        <text>HOLA</text>
        <hits>1</hits>
    </response>
</conversation>

<conversation>
    <input>HOW ARE YOU</input>
    <response>
        <text>I AM GOOD</text>
        <hits>4</hits>
    </response>
    <response>
        <text>IM FINE</text>
        <hits>5</hits>
    </response>
</conversation>

它将搜索输入(例如,如何你),然后返回命中率最高的响应块。我认为这是一个简单的操作,但我的搜索没有任何结果。谢谢伙伴们!

1 个答案:

答案 0 :(得分:0)

在XQuery 1.0中,这将是

declare variable $search as external;
let $c := //conversation[$input eq $search]
for $r in $c/response
where $r/hits = max($c/response/hits)
return $r
相关问题