xquery 相关问题

XQuery是一种用于查询和操作XML数据的函数式语言。它是XPath的超集,它添加了诸如创建新节点和更强大的FLWOR表达式等功能。虽然它与XSLT共享其数据模型,但XQuery针对查询而非转换数据进行了优化,因此它具有受SQL启发的不同设计。

如何在 C++ 中使用 XQilla 将变量传递给 XQuery

我正在使用 XQilla 来评估 C++ 中的 XQuery。 在 XQuery 中,我们定义两个变量:$metadataContent 和 $nuiContent。 每个变量都映射到一个 XML 文档。 如何将变量传递给 XQuery f...

回答 1 投票 0

清除marklogic数据库

有没有可以调用MarkLogic清除数据库的API? 我一直在使用管理 UI 页面中的“清除”按钮,但我想在脚本中使用此功能。我有

回答 1 投票 0

SQL Server XQuery 始终返回 null

我正在学习如何使用 SQL 读取 XML,目前正在努力返回我期望的所需数据。 对于给定的示例,我期望返回“tagFourData”及其值...

回答 1 投票 0

OSB 中的 XQUERY 转换

这是后端请求。 { “请求标头”:{ “应用程序ID”:“************”, “应用程序名称”:“TAS” }, “PartnerName”:“Coralpay test 2 Ltd”...

回答 1 投票 0

当一个值未定义时,如何处理 Saxon XQuery 处理器返回的多个值?

我正在尝试在 Java 应用程序中使用 Saxon HE XQuery 处理器对 XML 文档执行即席查询。 例如: 对于 $x //TestHistory[last()]/results/TestResult 其中 $x/status = 'TestedF...

回答 1 投票 0

在 XQuery 中计算不同的多个值TCP/IP 图解</ti...</desc> <question vote="0"> <p>给出下面的 XML 文档。这个 XML 文档包含很多书籍。书籍可以由许多作者撰写: *</p> <pre><code>`<bib> <book year="1994"> <title>TCP/IP Illustrated</title> <author> <last>Stevens</last> <first>W.</first> </author> <publisher>Addison-Wesley</publisher> <price>65.95</price> </book> <book year="1992"> <title>Advanced Programming in the UNIX Environment</title> <author> <last>Stevens</last> <first>W.</first> </author> <publisher>Addison-Wesley</publisher> <price>39.95</price> </book> <book year="2000"> <title>Data on the Web</title> <author> <last>Abiteboul</last> <first>Serge</first> </author> <author> <last>Buneman</last> <first>Peter</first> </author> <author> <last>Suciu</last> <first>Dan</first> </author> <publisher>Morgan Kaufmann Publishers</publisher> <price>39.95</price> </book> <book year="1999"> <title>The Economics of Technology and Content for Digital TV</title> <publisher>Kluwer Academic Publishers</publisher> <price>129.95</price> </book> </bib>` </code></pre> <ul> <li></li> </ul> <p>我想从这个文档中输出没有重复的作者数量。</p> <p>我尝试过以下方法:</p> <pre><code>let $x:= distinct-values(doc('biblio.xml')//author/(first, last)) return count ($x) </code></pre> <p>但是不幸的是,这个查询没有给我预期的输出。</p> </question> <answer tick="false" vote="0"> <p>您可以按 <pre><code>author</code></pre> 和 <pre><code>first</code></pre> 元素对 <pre><code>last</code></pre> 元素进行分组,然后对组进行计数:</p> <pre><code>(for $author in //author group by $first := $author/first, $last := $author/last return $author[1]) => count() </code></pre> </answer> <answer tick="false" vote="0"> <p>尝试将 xpath 表达式更改为</p> <pre><code>distinct-values(//author/concat(last, first)) </code></pre> <p>应该根据您的样本输出<pre><code>4</code></pre></p> </answer> </body></html>

给出下面的 XML 文档。这个 XML 文档包含很多书籍。书籍可以由许多作者撰写: * ` TCP/IP 图解</ti...</desc> <question vote="0"> <p>给出下面的 XML 文档。这个 XML 文档包含很多书籍。书籍可以由许多作者撰写: *</p> <pre><code>`<bib> <book year="1994"> <title>TCP/IP Illustrated</title> <author> <last>Stevens</last> <first>W.</first> </author> <publisher>Addison-Wesley</publisher> <price>65.95</price> </book> <book year="1992"> <title>Advanced Programming in the UNIX Environment</title> <author> <last>Stevens</last> <first>W.</first> </author> <publisher>Addison-Wesley</publisher> <price>39.95</price> </book> <book year="2000"> <title>Data on the Web</title> <author> <last>Abiteboul</last> <first>Serge</first> </author> <author> <last>Buneman</last> <first>Peter</first> </author> <author> <last>Suciu</last> <first>Dan</first> </author> <publisher>Morgan Kaufmann Publishers</publisher> <price>39.95</price> </book> <book year="1999"> <title>The Economics of Technology and Content for Digital TV</title> <publisher>Kluwer Academic Publishers</publisher> <price>129.95</price> </book> </bib>` </code></pre> <ul> <li></li> </ul> <p>我想从这个文档中输出没有重复的作者数量。</p> <p>我尝试过以下方法:</p> <pre><code>let $x:= distinct-values(doc('biblio.xml')//author/(first, last)) return count ($x) </code></pre> <p>但是不幸的是,这个查询没有给我预期的输出。</p> </question> <answer tick="false" vote="0"> <p>您可以按 <pre><code>author</code></pre> 和 <pre><code>first</code></pre> 元素对 <pre><code>last</code></pre> 元素进行分组,然后对组进行计数:</p> <pre><code>(for $author in //author group by $first := $author/first, $last := $author/last return $author[1]) => count() </code></pre> </answer> <answer tick="false" vote="0"> <p>尝试将 xpath 表达式更改为</p> <pre><code>distinct-values(//author/concat(last, first)) </code></pre> <p>应该根据您的样本输出<pre><code>4</code></pre></p> </answer> </body></html>

回答 0 投票 0

XPath 和 XQuery 等效性

我正在做一些自学,发现了这个我无法理解的问题的答案。 给定以下 DTD: 我正在自学,发现了这个我无法理解的问题的答案。 给出以下 DTD: <!DOCTYPE Courses [ <!ELEMENT Courses (Course*)> <!ELEMENT Course (Subject, Students)> <!ATTLIST Course CID ID #REQUIRED Credits PCDATA #REQUIRED> <!ELEMENT Subject (#PCDATA)> <!ELEMENT Students (Student+)> <!ELEMENT Student EMPTY> <!ATTLIST Student Name PCDATA #REQUIRED> ]> [1] 我有一个 XPath 提示: /Courses/Course[Students/Student/@Name="Smith"]/Subject [2] 以及 XQuery 提示: for $c in /Courses/Course where every $s in $c/Students/Student satisfies $s/@Name="Smith" return $c/Subject 答案声明 [2] 的结果始终包含在 [1] 中。有没有直观的解释? 根据我的理解,我认为这两个提示会输出相同的结果。 如果课程中的任何学生名为“Smith”,则您的 XPath 表达式 [1] 选择该课程。 如果课程中的每个学生都名为“Smith”,则您的 XQuery 表达式 [2] 将选择一门课程。 所以它们不等价。 [2]的结果始终是[1]的子集的命题依赖于这样一个事实:DTD不允许课程没有学生,或者学生没有名字。如果不是这种情况,那么 [2] 将选择一个空课程,而不是 [1]。

回答 1 投票 0

BOM:Oracle xquery 的二进制输出

我们需要从 OSB 写入 UTF-8 csv 文件。为了使Excel正确打开它,我们需要在文件的开头添加BOM序列EFBBBF。是否可以将二进制数据附加到正文中,其中...

回答 1 投票 0

SQL Server 中的 Soap XML 响应解析

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetLoginResponse xmlns="http://example.com"> <GetLoginResult> <xs:schema id="GetLoginIDResponse" targetNamespace="http://example.com/GetLoginIDResponse.xsd" xmlns:mstns="http://example.com/GetLoginIDResponse.xsd" xmlns="http://example.com/GetLoginIDResponse.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="GetLoginIDResponse" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="GetLoginIDResult"> <xs:complexType> <xs:sequence> <xs:element name="LoginID" type="xs:string" minOccurs="0" /> <xs:element name="Status" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> <GetLoginIDResponse xmlns="http://example.com/GetLoginIDResponse.xsd"> <GetLoginIDResult diffgr:id="GetLoginIDResult1" msdata:rowOrder="0" diffgr:hasChanges="inserted"> <LoginID>123456</LoginID> <Status>SUCCESS</Status> </GetLoginIDResult> </GetLoginIDResponse> </diffgr:diffgram> </GetLoginResult> </GetLoginResponse> </soap:Body> </soap:Envelope> 如何分别获得LoginID和Status?它只在列中显示 LoginID 和 Status。怎么分呢? 唯一的复杂之处是要处理多个命名空间。您可以尝试以下解决方案。 SQL DECLARE @xml XML = N'<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetLoginResponse xmlns="http://example.com"> <GetLoginResult> <xs:schema id="GetLoginIDResponse" targetNamespace="http://example.com/GetLoginIDResponse.xsd" xmlns:mstns="http://example.com/GetLoginIDResponse.xsd" xmlns="http://example.com/GetLoginIDResponse.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="GetLoginIDResponse" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="GetLoginIDResult"> <xs:complexType> <xs:sequence> <xs:element name="LoginID" type="xs:string" minOccurs="0"/> <xs:element name="Status" type="xs:string" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> <GetLoginIDResponse xmlns="http://example.com/GetLoginIDResponse.xsd"> <GetLoginIDResult diffgr:id="GetLoginIDResult1" msdata:rowOrder="0" diffgr:hasChanges="inserted"> <LoginID>123456</LoginID> <Status>SUCCESS</Status> </GetLoginIDResult> </GetLoginIDResponse> </diffgr:diffgram> </GetLoginResult> </GetLoginResponse> </soap:Body> </soap:Envelope>'; ;WITH XMLNAMESPACES ('http://schemas.xmlsoap.org/soap/envelope/' AS soap , 'http://example.com' AS ns1, 'urn:schemas-microsoft-com:xml-diffgram-v1' AS diffgr , DEFAULT 'http://example.com/GetLoginIDResponse.xsd') SELECT c.value('(LoginID/text())[1]','VARCHAR(30)') AS [LoginID] , c.value('(Status/text())[1]','VARCHAR(30)') AS [Status] FROM @xml.nodes('/soap:Envelope/soap:Body/ns1:GetLoginResponse/ns1:GetLoginResult/diffgr:diffgram/GetLoginIDResponse/GetLoginIDResult') AS t(c); 输出 +---------+---------+ | LoginID | Status | +---------+---------+ | 123456 | SUCCESS | +---------+---------+ 肥皂环境:身体 0 1 0未找到0 错误的 错误的 100蒙塔杰歌剧11.07.2023 09:34:00MONTAJ01 错误的 如何在 SQL Server 中肥皂泡 XML 响应解析 TBLRETURN COLUMN VALUES???

回答 2 投票 0

尝试插入数组节点对象 XDMP-CHILDDUPNAME 时出错?

我已经阅读了有关使用 XQuery 操作 JSON 文档以及使用 xdmp:insert-xxx 添加节点和向数组添加元素的所有文档,但我正在尝试使用 a...

回答 1 投票 0

xslt 或 xquery 在当前时间上添加分钟

我想创建一个安全标头,如下所示: 我想创建一个安全标头,如下所示: <soapenv:Header> <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd xmlns:wsu=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd> <wsu:Timestamp wsu:Id="TS-E157FC3B34ADB1C4DF16976549459948"> <wsu:Created>2023-10-18T18:49:05.994Z</wsu:Created> <wsu:Expires>2023-10-18T18:50:05.994Z</wsu:Expires> </wsu:Timestamp> </wsse:Security> 对于 <wsu:Created>2023-10-18T18:49:05.994Z</wsu:Created> 我想要当前日期时间并且 <wsu:Expires> </wsu:Expires> has to be 1 min more than current time xslt 1.0 中是否有任何函数可以用来获取当前日期时间并比它多 1 分钟或在 xquery 中 这在 XSLT 1.0 中实现起来很困难,但在 XSLT 2.0 或 XQuery 1.0(共享相同的函数库)中却很容易。简直就是 current-dateTime() + xs:dayTimeDuration('PT1M')

回答 1 投票 0

如何通过http发送xquery到BaseX数据库

我正在尝试使用http接口访问BaseX数据库。 设置如下: 在我的Windows 10系统上安装了最新的basex(版本10.7) 使用密码 test 创建了一个用户 test

回答 1 投票 0

XQuery 选择具有多个包含相同属性值的子元素的元素

我需要在 XML 文档库上执行查询,以查找包含多个元素和非常具体的项目的记录。在 SQL 中,我会使用 GROUP BY、WHERE 和 HAVING。 我想选择 Lorem,如果它有 &...

回答 1 投票 0

XMLQUERY - 当不为空时插入节点

示例代码: 宣布 l_xml_response xmltype; i_cl clob; l_flag 数字(1) := 1; l_product_type varchar2(5) := 'P'; 开始 l_xml_response := xmltype(' 示例代码: declare l_xml_response xmltype; i_cl clob; l_flag number(1) := 1; l_product_type varchar2(5) := 'P'; begin l_xml_response := xmltype('<?xml version="1.0"?> <main-node> <node1> <node2> <node3 product-type="PGZ"> <id>3</id> </node3> </node2> </node1> </main-node>'); SELECT XMLQUERY (' copy $res := $req modify insert nodes ( <amount>{$amount1}</amount>, <amount-1>{$amount2}</amount-1>, <amount-2>{$amount3}</amount-2>, <amount-3>{$amount4}</amount-3> ) after $res/main-node/node1/node2/node3/id return $res ' PASSING l_xml_response AS "req", 1 AS "amount1", 2 AS "amount2", 3 AS "amount3", CASE WHEN NVL(l_flag, 0) = 1 AND l_product_type = 'P' THEN 456 END AS "amount4" RETURNING CONTENT ) INTO l_xml_response FROM dual; SELECT XMLSERIALIZE ( CONTENT l_xml_response AS CLOB VERSION '1.0' INDENT SIZE = 2 HIDE DEFAULTS ) INTO i_cl FROM dual; dbms_output.put_line( i_cl); end; / 我想要实现的是仅当节点 amount4 不为空时才添加节点 amount4 。此 xquery 添加空节点 ( <amount-3/> )。它不会破坏任何东西,只是试图不发送不必要的空节点。 也许有人对此有一些快速、聪明的解决方案。 谢谢。 在 FLOWR 表达式中使用 if .. then .. else ..: declare l_xml_response xmltype; i_cl clob; l_flag number(1) := 1; l_product_type varchar2(5) := 'P'; begin l_xml_response := xmltype('<?xml version="1.0"?> <main-node> <node1> <node2> <node3 product-type="PGZ"> <id>3</id> </node3> </node2> </node1> </main-node>'); SELECT XMLQUERY (' copy $res := $req modify insert nodes ( <amount>{$amount1}</amount>, <amount-1>{$amount2}</amount-1>, <amount-2>{$amount3}</amount-2>, if ($amount4) then <amount-3>{$amount4}</amount-3> else () ) after $res/main-node/node1/node2/node3/id return $res ' PASSING l_xml_response AS "req", 1 AS "amount1", 2 AS "amount2", 3 AS "amount3", NULL AS "amount4" RETURNING CONTENT ) INTO l_xml_response FROM dual; SELECT XMLSERIALIZE ( CONTENT l_xml_response AS CLOB VERSION '1.0' INDENT SIZE = 2 HIDE DEFAULTS ) INTO i_cl FROM dual; dbms_output.put_line( i_cl); end; / 输出: <?xml version="1.0"?> <main-node> <node1> <node2> <node3 product-type="PGZ"> <id>3</id> <amount>1</amount> <amount-1>2</amount-1> <amount-2>3</amount-2> </node3> </node2> </node1> </main-node> 小提琴

回答 1 投票 0

XQUERY() 用于 SQL 协助

我有一个以 XML 格式存储数据的表。我需要来自两个节点的数据。 示例脚本: 选择MARKUP_MESSAGE 来自 TABLE_NAME 其中 row_uno = 6599064 结果示例: <

回答 1 投票 0

更新 SQL 表中的 Xml 值

在 SQL 中,我没有使用 XML 列和值的经验。 我需要更新(使用 SQL 查询) 截止日期详情 读书:

回答 2 投票 0

XQuery 在属性中拉取数据

我有这个疑问 ;WITH XMLNAMESPACES ('http://schemas.microsoft.com/sqlserver/DMF/2007/08'AS DMF) 选择 Res.Expr.value('(../DMF:ResultDetail/Operator/Attribute/@ResultValue)[1...

回答 1 投票 0

BaseX 中禁用工具栏选项

我正在使用 BaseX 9.7.2,我不知道为什么我的大多数工具栏选项都被禁用,所以除了“新建”、“打开和管理”、“编辑器”、“结果”之外我无法使用它们...

回答 1 投票 0

如何在 SQL Server 中读取 XML

<Result xmlns="uri:SomeNamespace"> <PD:Summary xmlns:PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"> <p1:p xmlns:p1="http://www.w3.org/1999/xhtml"> Our top-of-the-line competition mountain bike. Performance- enhancing options include the innovative HL Frame, super-smooth front suspension, and traction for all terrain.</p1:p> </PD:Summary> </Result> 如何在 SQL Server 中使用 XQuery 读取此 XML 的元素和属性? 假设您的 XML 数据位于 SQL 变量中 - 您可以尝试这样的操作 尊重所有定义的 XML 命名空间 深入 XML 代码: DECLARE @XmlData XML = '<Result xmlns="uri:SomeNamespace"> <PD:Summary xmlns:PD="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"> <p1:p xmlns:p1="http://www.w3.org/1999/xhtml"> Our top-of-the-line competition mountain bike. Performance- enhancing options include the innovative HL Frame, super-smooth front suspension, and traction for all terrain.</p1:p> </PD:Summary> </Result>'; -- setup the XML namespaces in play WITH XMLNAMESPACES('uri:SomeNamespace' AS ns1, 'https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription' AS pd, 'http://www.w3.org/1999/xhtml' AS p1) -- select the /Result/Summary/p element respecting all the involved namespaces SELECT BodyText = @XmlData.value('(/ns1:Result/pd:Summary/p1:p/text())[1]', 'varchar(2000)') 你会得到类似的结果: BodyText ------------------------------------------------------------------------ Our top-of-the-line competition mountain bike. Performance- enhancing options include the innovative HL Frame, super-smooth front suspension, and traction for all terrain.

回答 1 投票 0

使用 CROSS APPLY 进行 XML 解析

我一直在研究这个 XML,它嵌套在 SQL Server 中表的一列中。 我有一个代码直到几天前才对我有用,但我目前遇到的问题是我无法解决

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.