【问题标题】:MS Access Export XML but exclude ID element in vbaMS Access 导出 XML 但在 vba 中排除 ID 元素
【发布时间】:2017-03-14 22:15:28
【问题描述】:

我正在尝试找到一种方法将我的所有表导出到 XML 文件中,但只排除 ID 列。我可以从查找中发现,最好的解决方案是只进行一个只包含需要导出的列的查询。我的问题是我要导出几个表,查询会产生大约一百万条记录。那么有没有办法让我的代码只导出所有表并仅排除 ID 列?这是我的代码

Do Until rsR.EOF
    On Error GoTo ErrorHandle
    Set objOtherTbls = Application.CreateAdditionalData
    objOtherTbls.Add "entry"
    objOtherTbls.Add "patch"
    objOtherTbls.Add "reference"
    objOtherTbls.Add "remediations"
    objOtherTbls.Add "scanners"
    objOtherTbls.Add "tempMitStrat"
    objOtherTbls.Add "vms"
    Application.ExportXML ObjectType:=acExportTable, _
                DataSource:="iavmNotice", _
                DataTarget:="C:\Users\" & Environ("USERNAME") & "\Documents\iavms\" & rsR.Fields("iavmNoticeNumber").Value & " (ID " & rsR.Fields("count").Value & ").xml", _
                WhereCondition:="[iavmNoticeNumber] = '" & rsR.Fields("iavmNoticeNumber").Value & "'", _
                AdditionalData:=objOtherTbls

                rsR.MoveNext
                Loop
                rsR.Close

【问题讨论】:

    标签: xml vba ms-access export


    【解决方案1】:

    考虑在导出原始 XML 后使用 XSLT 删除 ID,方法是运行身份转换(按原样复制文档)并在 ID 元素上使用空模板:

    XSLT (另存为 .xsl 文件或嵌入的 VBA 字符串,使用双引号转义并使用 loadXML)

    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output version="1.0" encoding="UTF-8" indent="yes" method="xml"/>
    <xsl:strip-space elements="*"/>
    
      <!-- Identity Transform -->
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>  
    
      <!-- Removing IDs with Empty Templates (change to actual names) -->
      <xsl:template match="iavmNoticeID|entryID|patchID|referenceID|remediationsID|scannersID|tempMitStratID|vmsID"/>
    
    </xsl:transform>
    

    VBA

    Public Sub RunXSLT()
        Dim xmlDoc As New MSXML2.DOMDocument, xslDoc As New MSXML2.DOMDocument, newDoc As New MSXML2.DOMDocument
    
        xmlDoc.Load "C:\Path\To\Input.xml"
        xslDoc.Load "C:\Path\To\XSLT\SCript.xsl"
    
        xmlDoc.transformNodeToObject xslDoc, newDoc
        newDoc.Save "C:\Path\To\Output.xml"
    
        Set xmlDoc = Nothing: Set xslDoc = Nothing: Set newDoc = Nothing
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-14
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多