MS Access VBA导出XML层次结构

时间:2015-11-27 16:22:24

标签: xml vba ms-access access-vba ms-access-2010

我有一个包含下表的数据库crdatabase:

releases
fields:
    name (datatype: string)
    release_status (datatype: string)
    year (datatype: string)

changerequests
fields:
    id (datatype: autonumber)
    description (datatype: string)
    release (datatype: string)
    cr_status (datatype: string)
    affectedcpid (datatype: string, multi-valued, delimited by comma)

affectedcomponents
fields:
    id (datatype: autonumber)
    name (datatype: string)

关系: 更改请求通过版本< - >链接到版本表名称字段。 变更请求通过affectedcpid< - >链接到受影响的组件表id字段

我想在层次结构中导出XML:

<crdatabase>
<release>
    <name>release1</name>
    <year>2016</year>
    <status>active</status>
    <changerequest>
        <id>1</id>
        <description>change1</description>
        <cr_status>open</cr_status>
        <affectedcomponent>comp1</affectedcomponent>
        <affectedcomponent>comp2</affectedcomponent>
        <affectedcomponent>comp3</affectedcomponent>
    </changerequest>
    <changerequest>
        <id>3</id>
        <description>change3</description>
        <cr_status>working</cr_status>
        <affectedcomponent>comp5</affectedcomponent>
   </changerequest>
</release>
<release>
    <name>release2</name>
    <year>2015</year>
    <status>nonactive</status>
    <changerequest>
        <id>2</id>
        <description>change2</description>
        <cr_status>closed</cr_status>
        <affectedcomponent>comp1</affectedcomponent>
        <affectedcomponent>comp2</affectedcomponent>
    </changerequest>
</release>
.....
</crdatabase>

我尝试在vba中使用AdditionalData,如下所示:

Public Sub exportToXML(pFileNAme As String)
    Dim objOrderInfo As AdditionalData
    Set objOrderInfo = Application.CreateAdditionalData
    objOrderInfo.Add("releases")
    objOrderInfo.Add ("changerequests").Add ("affectedcpid")
    objOrderInfo.Add ("affectedcomponents")

    Application.ExportXML ObjectType:=acExportTable, DataSource:="releases", _
                      DataTarget:=pFileNAme, _
                      AdditionalData:=objOrderInfo, WhereCondition:="Parameter='test'"
End Sub

它没有按预期工作,因为它不会在层次结构中导出,也不会导出搜索查询。

以下是实际出口的内容:

<crdatabase>
<releases>
    <name>release1</name>
    <year>2016</year>
    <release_status>active</release_status>
</releases>
<releases>
    <name>release2</name>
    <year>2015</year>
    <release_status>nonactive</release_status>
</releases>
...
<changerequests>
    <id>1</id>
    <description>change1</description>
    <release>2016</release>
    <cr_status>open</cr_status>
    <affectedcomponent>1,2,3</affectedcomponent>
</changerequests>
<changerequests>
    <id>3</id>
    <description>change3</description>
    <release>2015</release>
    <cr_status>working</cr_status>
    <affectedcomponent>5</affectedcomponent>
</changerequests>
...
</crdatabase>

有什么想法吗? DOM或打印(请提供示例代码)都可以接受,只要它可以在vba中处理。谢谢!

0 个答案:

没有答案