0

我正在尝试从 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 保持空白。我搜索了很多网站,但无法解决。

4

1 回答 1

0

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

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

但是您将此命名空间添加selectionNamespacesoDocument

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

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

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

于 2014-08-12T19:41:06.400 回答