[英]Generate XML file with document constructor from xquery
I have problem to generate.xml file from xquery.我有问题从 xquery 生成.xml 文件。 Here is my code:这是我的代码:
document {
<?xml version="1.0" encoding=UTF-8" href="C:\Users\User\Desktop\UDBXML-lab\artist.xml"?>,
<ARTISTS>
{
for $a in doc("Artists.xml")//ARTIST
return <ARTIST ID="{$a/@ID}">
{$a/*}
{
for $b in doc("Groups.xml")//GROUP
where $a/@ID = $b/@ID
return $b
}
{
for $b in doc("DJ.xml")//DJ
where $a/@ID = $b/@ID
return $b
}
{
for $b in doc("Singers.xml")//SINGER
where $a/@ID = $b/@ID
return $b
}
</ARTIST>
}
</ARTISTS>
}
I get error:我得到错误:
A processing instruction must not be named 'xml' in any combination of upper or lower case.处理指令不得以任何大小写组合命名为“xml”。
But I don't know which processing instruction to set to save this query in document.但我不知道要设置哪个处理指令来将此查询保存在文档中。
You need to leverage XQuery prolog declarations.您需要利用 XQuery prolog 声明。 Here is how to do it.这是如何做到的。
base-uri
declaration specifies a directory for all XML files. base-uri
声明为所有 XML 文件指定一个目录。 The other two declarations will create an XML prolog with desired settings.其他两个声明将创建具有所需设置的 XML prolog。
XQuery XQuery
xquery version "3.0";
declare base-uri 'C:\Users\User\Desktop\UDBXML-lab\';
declare option output:omit-xml-declaration "no";
declare option output:encoding "UTF-8";
<ARTISTS>
{
for $a in doc("Artists.xml")//ARTIST
return <ARTIST ID="{$a/@ID}">
{$a/*}
{
for $b in doc("Groups.xml")//GROUP
where $a/@ID = $b/@ID
return $b
}
{
for $b in doc("DJ.xml")//DJ
where $a/@ID = $b/@ID
return $b
}
{
for $b in doc("Singers.xml")//SINGER
where $a/@ID = $b/@ID
return $b
}
</ARTIST>
}
</ARTISTS>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.