Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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文件中_Xquery_Basex - Fatal编程技术网

Xquery将数据保存在XML文件中

Xquery将数据保存在XML文件中,xquery,basex,Xquery,Basex,下面是XML结构- <Documents> <Doc n="Name1" year="2010"> ..... </Doc> <Doc n="Name2" year="2010"> ..... </Doc> <Doc n="Name3" year="2011"> ..... </Doc> <Doc n="Name4" year="2011"> ..... </Doc>

下面是XML结构-

<Documents>
 <Doc n="Name1" year="2010">
 .....
 </Doc>
 <Doc n="Name2" year="2010">
 .....
 </Doc>
 <Doc n="Name3" year="2011">
 .....
 </Doc>
 <Doc n="Name4" year="2011">
 .....
 </Doc>

.....
.....
.....
.....

我正在使用BaseX存储此文档。我需要提取 从中提取一些数据并将其存储为xml文件。喂,我需要一个单独的 xml文件已经存在多年了


如何完成此操作?

当您使用BaseX时,请访问此链接-

此查询将提取C驱动器中名为2010.xml的文件中所需的数据。文件名和位置可以根据您的要求进行更改

使用上述查询,您将根据需要更改年份值
2010
。如我从结构中看到的,如果年份具有不同的值和顺序,则可以使用以下查询。此查询将为所有年份创建多个文件

for $year in (2010 to 2011)
  (: Year are specified :)
  let $fName := concat("C:\", $year, "B.xml")
  (: The path is created and stored in $fName variable :)
  for $x in doc('docs')//Doc
    where $x/@year eq xs:string($year)
    return file:append($fName, $x)

我希望这两个例子都是不言自明的

多谢各位。根据我的需要,第二个答案是最合适的。
for $year in (2010 to 2011)
  (: Year are specified :)
  let $fName := concat("C:\", $year, "B.xml")
  (: The path is created and stored in $fName variable :)
  for $x in doc('docs')//Doc
    where $x/@year eq xs:string($year)
    return file:append($fName, $x)