Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用xQuery合并两个相同格式的xml文件,以便合并的文件按时间戳排序?_Xml_Xquery - Fatal编程技术网

如何使用xQuery合并两个相同格式的xml文件,以便合并的文件按时间戳排序?

如何使用xQuery合并两个相同格式的xml文件,以便合并的文件按时间戳排序?,xml,xquery,Xml,Xquery,我有两个xml文件,它们都包含多个元素,如下所示: <!--CodeSite Log File--> <!--Created on 12 December 2018 13:58:52 --> <CodeSiteLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CodeSiteLogFile.xsd"> . . . <Mess

我有两个xml文件,它们都包含多个
元素,如下所示:

<!--CodeSite Log File-->
<!--Created on 12 December 2018 13:58:52 -->
<CodeSiteLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="CodeSiteLogFile.xsd">
. . .
  <Message MsgType="Enter" MsgText="CStore">
    <TimeStamp Date="2018-12-11" Time="11:10:40.860" TimeBias="0"/>
    <ProcessID>7688</ProcessID>
    <ThreadName>7</ThreadName>
    <AppName>spoolsv</AppName>
    <ComputerName>W10-X64-BPT</ComputerName>
    <Category Color="clWhite" FontColor="clBlack"></Category>
    <TypeName></TypeName>
  </Message>
. . .
</CodeSiteLog>

. . .
7688
7.
短管
W10-X64-BPT
. . .
我的问题是,如何使用xQuery将这两个xml文件合并成一个按升序时间戳排序的xml文件?我已经能够合并这两个文件,但是我得到了第一个xml文件中的所有消息,然后是第二个xml文件中的所有消息,而不是按升序时间戳排序

我当前得到的合并文件如下所示,其中前两条消息来自第一个文件,其余消息来自第二个文件:

<?xml version="1.0" encoding="UTF-8"?>
<results>
  <result MsgText="message from first log" MsgType="Info" Time="11:10:40.858"/>
  <result MsgText="message from first log" MsgType="Info" Time="11:10:41.778"/>
  <result MsgText="message from second log" MsgType="Info" Time="11:10:30.791"/>
  <result MsgText="message from second log" MsgType="Info" Time="11:10:30.801"/>
  . . .
</results>

. . .
但是合并文件中的消息不再按时间戳顺序排列。

本质上

for $m in (doc('a.xml'), doc('b.xml'))//Message
order by $m/Timestamp/dateTime(@Date, @Time)
return $m

向我们展示您的代码是个好主意,这样我们就可以看到您的错误所在。否则,我们只是为您编写代码,而不是提供反馈。