in:gaap xbrl具有多个attrributes的Selectsinglenode在VBA中不返回任何内容

时间:2014-08-11 19:06:51

标签: vba attributes selectsinglenode xbrl

我正在尝试从XBRL xml文件中提取值。我对VBA的MSXML功能没有诀窍。

是XML文件
    <?xml version="1.0" encoding="UTF-8"?>

    <!-- XBRL Instance Document Created By :- Relyon Softech Ltd. -->

    <!-- Date/time created: 29/10/2013 4:47:38 PM -->
    <xbrli:xbrl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns="http://www.xbrl.org/2003/instance" xmlns:in-ca-roles="http://www.icai.org/xbrl/taxonomy/2012-03-31/in-ca-roles" xmlns:negated="http://www.xbrl.org/2009/role/negated" xmlns:in-gaap="http://www.icai.org/xbrl/taxonomy/2012-03-31/in-gaap" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:iso4217="http://www.xbrl.org/2003/iso4217" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:num="http://www.xbrl.org/dtr/type/numeric" xmlns:net="http://www.xbrl.org/2009/role/net" xmlns:in-roles="http://www.icai.org/xbrl/taxonomy/2012-03-31/in-gaap-roles" xmlns:in-ca="http://www.icai.org/xbrl/taxonomy/2012-03-31/in-ca" xmlns:ref="http://www.xbrl.org/2006/ref" xmlns:in-ci-ent="http://www.icai.org/xbrl/taxonomy/2012-03-31/in-gaap/in-ci-ent" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:nonnum="http://www.xbrl.org/dtr/type/non-numeric" xmlns:xbrldt="http://xbrl.org/2005/xbrldt" xmlns:targetNamespace="http://www.icai.org/xbrl/taxonomy/2012-03-31/in-gaap/in-ci-ent">
       <link:schemaRef xlink:href="http://www.mca.gov.in/XBRL/2012/08/02/Taxonomy/CnI/in-ci-ent-2012-03-31.xsd" xlink:type="simple"/>
          <xbrli:context id="D2012">
             <xbrli:entity>
               <xbrli:identifier scheme="http://www.mca.gov.in/CIN">U63010MH1993PLC075480</xbrli:identifier>
             </xbrli:entity>
            .................
          </xbrli:context>
          <in-gaap:RevenueFromSaleOfProducts id="CYTAG60" unitRef="INR" contextRef="D2013" decimals="-3">0</in-gaap:RevenueFromSaleOfProducts>
          <in-gaap:RevenueFromSaleOfProducts id="PYTAG60" unitRef="INR" contextRef="D2012" decimals="-3">0</in-gaap:RevenueFromSaleOfProducts>
            .................
            <in-gaap:ProfitBeforePriorPeriodItemsExceptionalItemsExtraordinaryItemsAndTax id="CYTAG88" unitRef="INR" contextRef="D2013" decimals="-3">22163000</in-gaap:ProfitBeforePriorPeriodItemsExceptionalItemsExtraordinaryItemsAndTax>
            <in-gaap:ProfitBeforePriorPeriodItemsExceptionalItemsExtraordinaryItemsAndTax id="PYTAG88" unitRef="INR" contextRef="D2012" decimals="-3">-14284000</in-gaap:ProfitBeforePriorPeriodItemsExceptionalItemsExtraordinaryItemsAndTax>
            .................
     </xbrli:xbrl>

“...”包含其他不相关的代码。现在excel文件具有以下单元格值: C4(元素名称)= in-gaap:ProfitBeforePriorPeriodItemsExceptionalItemsExtraordinaryItemsAndTax,D4 =文档位置,E4 =上下文(比如'D2013'),G4 =输出值。 (应该是22163000)

我想在G4中提取C4中元素的值。

VBA代码:

   Sub XbrlExtract()

    Dim LoadFile As String
    LoadFile = Range("D4").Value

    Dim Concept As String
    Concept = Range("C4").Value

    Dim Context As String
    Context = Range("E4").Value

    Dim oDocument As MSXML2.DOMDocument60
    Dim oXbrlNode As MSXML2.IXMLDOMNode
    Dim oNode As MSXML2.IXMLDOMNode

    Set oDocument = New MSXML2.DOMDocument60
    oDocument.DocumentElement
    oDocument.async = False
    oDocument.validateOnParse = False
    oDocument.Load (LoadFile)

    oDocument.setProperty "SelectionNamespaces", "xmlns:xbrli = 'http://www.mca.gov.in/instance' xmlns:in-gaap = 'http://www.xbrl.org/instance'"
    oNode = oDocument.SelectSingleNode("/xbrli:xbrl/" & Concept & "[@contextRef = '" & Context & "']")
    If oNode Is Nothing Then
      MsgBox "No nodes selected"
    Else
     Range("G4").Select
     Debug.Print oNode.Text
    End If
    Set oDocument = Nothing

  End Sub

代码未检测到元素,oNode返回Nothing msgbox“未选择节点”,G4保持空白。我搜索了很多网站,但无法解决它。

1 个答案:

答案 0 :(得分:0)

在您的实例文档中,您有此命名空间声明:

xmlns:xbrli="http://www.xbrl.org/2003/instance"

但是您将此命名空间添加到selectionNamespaces

oDocument
xmlns:xbrli = 'http://www.mca.gov.in/instance'

是相同的前缀但名称空间不同。

提示:默认情况下,MSXML2.DOMDocument2允许您使用加载文档中声明的相同名称空间前缀,因此无需为oDocument.setProperty "SelectionNamespaces"或{{1}调用selectNodes工作。