Public Sub Click()
Dim objOtherTbls As AdditionalData
Set objOtherTbls = Application.CreateAdditionalData
objOtherTbls.Add "vessels"
objOtherTbls.Add "Export"
Application.ExportXML ObjectType:=acExportTable, _
DataSource:="orderSummary", _
DataTarget:="pls.xml", _
AdditionalData:=objOtherTbls
End Sub
如何使XML嵌套,重复字段只重复一次?
I would like something like:
<vessels>
<vessels ID>
<product Id>
<quantity>
<product Id>
<quantity>
<product Id>
<quantity>
如何合并表格并使它们像上面提到的那样,以便每个船只的名称只有一次,并且该船只的所有物品都列在下面并以标签显示?
答案 0 :(得分:1)
Access在导出到XML时使用“Relationships”来标识父/子层次结构。您的数据库显然缺少[血管]和[导出]之间的关系,因此您可以在问题中显示两个表的“平面”XML导出。
如果您将关系添加到数据库...
...然后您将获得您寻求的“嵌套”XML导出:
<vessels>
<vessel_id>2</vessel_id>
<vessel_name>B</vessel_name>
</vessels>
<vessels>
<vessel_id>3</vessel_id>
<vessel_name>C</vessel_name>
<Export>
<product_id>10</product_id>
<Quantity>10</Quantity>
<vessel_id>3</vessel_id>
</Export>
<Export>
<product_id>100</product_id>
<Quantity>20</Quantity>
<vessel_id>3</vessel_id>
</Export>
<Export>
<product_id>1000</product_id>
<Quantity>1</Quantity>
<vessel_id>3</vessel_id>
</Export>
<Export>
<product_id>10000</product_id>
<Quantity>10</Quantity>
<vessel_id>3</vessel_id>
</Export>
<Export>
<product_id>10001</product_id>
<Quantity>20</Quantity>
<vessel_id>3</vessel_id>
</Export>
<Export>
<product_id>10002</product_id>
<Quantity>10</Quantity>
<vessel_id>3</vessel_id>
</Export>
</vessels>
答案 1 :(得分:0)
这里快速草图(SQL DDL需要ANSI-92查询模式,但可以使用Access GUI工具重现):
CREATE TABLE vessels
( vessel_id INT NOT NULL UNIQUE,
vessel_name CHAR(1) WITH COMPRESSION NOT NULL UNIQUE );
CREATE TABLE Export
( product_id INT NOT NULL UNIQUE,
Quantity INT NOT NULL, CHECK ( Quantity >= 0 ),
vessel_id INT NOT NULL
REFERENCES vessels ( vessel_id ) );
INSERT INTO vessels VALUES ( 1, 'A' );
INSERT INTO vessels VALUES ( 2, 'B' );
INSERT INTO vessels VALUES ( 3, 'C' );
INSERT INTO vessels VALUES ( 4, 'D' );
INSERT INTO vessels VALUES ( 5, 'E' );
INSERT INTO Export VALUES ( 10, 10, 3 );
INSERT INTO Export VALUES ( 100, 20, 3 );
INSERT INTO Export VALUES ( 1000, 1, 3 );
INSERT INTO Export VALUES ( 10000, 10, 3 );
INSERT INTO Export VALUES ( 10001, 20, 3 );
INSERT INTO Export VALUES ( 10002, 10, 3 );