使用MarkLogicXQuery查询XBRL实例中存在的实体标识符



我正在使用MarkLogic的Xquery控制台来处理它并查询我的XBRL文档

这就是我的XBRL文档看起来像的样子

<xbrli:xbrl xml:lang="nl" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:bd-alg="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-algemeen" xmlns:bd-bedr="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedrijven" xmlns:bd-bedr-tuple="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedr-tuples" xmlns:bd-dim-mem="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-domain-members" xmlns:bd-dim-dim="http://www.nltaxonomie.nl/nt11/bd/20161207/validation/bd-axes" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:xlink="http://www.w3.org/1999/xlink">
<link:schemaRef xlink:type="simple" xlink:href="http://www.nltaxonomie.nl/nt11/bd/20161207/entrypoints/bd-rpt-vpb-aangifte-2016.xsd"/>
<xbrli:context id="ContextDurationDeclarant">
<xbrli:entity>
<xbrli:identifier scheme="www.belastingdienst.nl/identificatie">800004449</xbrli:identifier>
</xbrli:entity>
<xbrli:period>
<xbrli:startDate>2016-01-01</xbrli:startDate>
<xbrli:endDate>2016-12-31</xbrli:endDate>
</xbrli:period>
<xbrli:scenario>
<xbrldi:explicitMember dimension="bd-dim-dim:PartyDimension">bd-dim-mem:Declarant</xbrldi:explicitMember>
</xbrli:scenario>
</xbrli:context>
</xbrli:xbrl>

正如您所看到的,它是XML。

我想做的查询是

xquery version "1.0-ml";
declare namespace lang="nl";
declare namespace link="http://www.xbrl.org/2003/linkbase";
declare namespace bd-alg="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-algemeen";
declare namespace bd-bedr="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedrijven";
declare namespace bd-bedr-tuple="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedr-tuples";
declare namespace bd-dim-mem="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-domain-members";
declare namespace bd-dim-dim="http://www.nltaxonomie.nl/nt11/bd/20161207/validation/bd-axes";
declare namespace xbrldi="http://xbrl.org/2006/xbrldi";
declare namespace xbrli="http://www.xbrl.org/2003/instance";
declare namespace iso4217="http://www.xbrl.org/2003/iso4217";
declare namespace xlink="http://www.w3.org/1999/xlink";
declare namespace type="simple";
declare namespace href="http://www.nltaxonomie.nl/nt11/bd/20161207/entrypoints/bd-rpt-vpb-aangifte-2016.xsd";
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Database dump</title>
</head>
<body>
<b>XML Content</b>
{
for $xbrli:context in doc("test.xml")/xbrli:xbrl
return
<pre>
Identifier: { $xbrli:context/xbrli:entity/xbrli:identifier }
</pre>
}
</body>
</html>

我看不出有什么问题,但Xquery显然有,因为我只得到空序列。请帮帮我!

将其更改为:

for $xbrl in doc("test.xml")//xbrli:xbrl
return
<pre>
Identifier: { $xbrl/xbrli:context/xbrli:entity/xbrli:identifier/string() }
</pre>

您需要在末尾使用/string()来获取内容

我实现如下:

xquery version "1.0-ml";
declare namespace lang="nl";
declare namespace link="http://www.xbrl.org/2003/linkbase";
declare namespace bd-alg="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-algemeen";
declare namespace bd-bedr="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedrijven";
declare namespace bd-bedr-tuple="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedr-tuples";
declare namespace bd-dim-mem="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-domain-members";
declare namespace bd-dim-dim="http://www.nltaxonomie.nl/nt11/bd/20161207/validation/bd-axes";
declare namespace xbrldi="http://xbrl.org/2006/xbrldi";
declare namespace xbrli="http://www.xbrl.org/2003/instance";
declare namespace iso4217="http://www.xbrl.org/2003/iso4217";
declare namespace xlink="http://www.w3.org/1999/xlink";
declare namespace type="simple";
declare namespace href="http://www.nltaxonomie.nl/nt11/bd/20161207/entrypoints/bd-rpt-vpb-aangifte-2016.xsd";
let $doc :=
<xbrli:xbrl>
<xbrli:context id="ContextDurationDeclarant">
<xbrli:entity>
<xbrli:identifier scheme="www.belastingdienst.nl/identificatie">800004449</xbrli:identifier>
</xbrli:entity>
<xbrli:period>
<xbrli:startDate>2016-01-01</xbrli:startDate>
<xbrli:endDate>2016-12-31</xbrli:endDate>
</xbrli:period>
<xbrli:scenario>
<xbrldi:explicitMember dimension="bd-dim-dim:PartyDimension">bd-dim-mem:Declarant</xbrldi:explicitMember>
</xbrli:scenario>
</xbrli:context>
</xbrli:xbrl>
return
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Database dump</title>
</head>
<body>
<b>XML Content</b>
{
for $xbrl in $doc
return
<pre>
Identifier: { $xbrl/xbrli:context/xbrli:entity/xbrli:identifier/string() }
</pre>
}
</body>
</html>

XML文档确实需要命名空间声明的

<?xml version="1.0" encoding="UTF-8"?>
<xbrli:xbrl xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xbrldi="http://xbrl.org/2006/xbrldi">
<xbrli:context id="ContextDurationDeclarant">
<xbrli:entity>
<xbrli:identifier scheme="www.belastingdienst.nl/identificatie">800004449</xbrli:identifier>
</xbrli:entity>
<xbrli:period>
<xbrli:startDate>2016-01-01</xbrli:startDate>
<xbrli:endDate>2016-12-31</xbrli:endDate>
</xbrli:period>
<xbrli:scenario>
<xbrldi:explicitMember dimension="bd-dim-dim:PartyDimension">bd-dim-mem:Declarant</xbrldi:explicitMember>
</xbrli:scenario>
</xbrli:context>
</xbrli:xbrl>

您已经调用了变量$xbrli:context,但您只选择了doc("test.xml")/xbrli:xbrl,而不是您想要的doc("test.xml")/xbrli:xbrl/xbrli:context

Martin和Loren都有自己的观点,我还有一些关于XBRL的评论。

您需要在for子句的XPath中添加xbrli:context,并将/string()添加到标识符中以仅获得字符串值(否则它将嵌套一个元素)。

{
for $xbrli:context in doc("test.xml")/xbrli:xbrl/xbrli:context
return
<pre>
Identifier: { $xbrli:context/xbrli:entity/xbrli:identifier/string() }
</pre>
}

xbrli:context元素必须在return子句之外,因为在一般情况下,在同一个XBRL实例中有多个上下文,但如果该实例符合XBRL,则每个上下文只有一个实体。

此外,您可能需要执行一些重复消除,因为不同的上下文可能包含相同的实体。实际上,根据经验,一个XBRL实例在其所有上下文中通常只包含一个实体。美国证券交易委员会的文件和许多其他监管机构就是这样(当然,尽管XBRL没有限制,所以其他XBRL数据集每个实例可能有几个实体)。

则CCD_ 7变得多余。

{
for $entity in distinct-values(
doc("test.xml")/xbrli:xbrl/xbrli:context/xbrli:entity/xbrli:identifier
)
return <pre>Identifier: { $entity }</pre>
}

实际上,由于xbrli:identifier只会出现在符合XBRL的实例中的这些位置,因此您也可以直接在QName:上使用子代或自特性

{
for $entity in distinct-values(
doc("test.xml")//xbrli:identifier
)
return <pre>Identifier: { $entity }</pre>
}

最后,在许多文件中,XBRL事实甚至会为实体报告一个更友好的名称(在美国证券交易委员会的文件中,它是dei:EntityRegistrantName),而实体标识符会为您提供CIK(也称为dei:EntityCentralIndexKey)。

最新更新