gpt4 book ai didi

xml - 如何将具有父/子关系的 XML 导入 Access?

转载 作者:数据小太阳 更新时间:2023-10-29 02:25:44 25 4
gpt4 key购买 nike

我正在尝试将 XML 文件导入 Access,但它创建了 9 个不相关的表。即子记录被导入到子表中,但无法知道哪些子记录属于哪个父表。

如何导入数据来维护父子节点(记录)之间的关系?

这是 XML 数据的示例:

<?xml version="1.0" encoding="UTF-8"?>
<iavmNotice xmlns="http://stuff.com" noticeId="138643">
<xmlUrl>https://fakexmlurl.xml</xmlUrl>
<htmlUrl>https://fakehtmlurl.htm</htmlUrl>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<title>Cisco Vulnerability</title>
<type>B</type>
<state>FINAL</state>
<lastSaved>2012-08-24T10:34:13</lastSaved>
<precoordDueDate>2012-08-23T11:00:00</precoordDueDate>
<releaseDate>2012-08-23</releaseDate>
<acknowledgeDate>2012-08-28</acknowledgeDate>
<knownExploits>true</knownExploits>
<knownDodIncidents>false</knownDodIncidents>
<executiveSummary>Cisco incidents.</executiveSummary>
<techOverview>
<entry>
<title>2012-2490</title>
<description>Cisco ID 71.</description>
</entry>
<entry>
<title>2012-2525</title>
<description>Cisco ID 69.</description>
</entry>
</techOverview>
<fixAction>Apply appropriate vendor update</fixAction>
<note>&lt;b&gt;Upgrade later&lt;/b&gt;&lt;br&gt;&lt;br&gt;</note>
<tempMitStrat>
<header>&lt;b&gt;Cisco &lt;/b&gt;</header>
<body>&lt;br&gt;None</body>
</tempMitStrat>
<vulnAppsSysAndCntrmsrs>Cisco IP Communicator 8.6&lt;br&gt;&lt;br&gt;</vulnAppsSysAndCntrmsrs>
<references>
<reference>
<title>Release Notes for Cisco IP Communicator Release 8.6</title>
<url>http://www.fakeurl.com/html</url>
</reference>
</references>
<deepSightBids>
<bid>54850</bid>
</deepSightBids>
<revisions>
<revision>
<majorNum>0</majorNum>
<minorNum>0</minorNum>
<type>MAJOR</type>
<date>2012-08-23</date>
<details>Initial Release</details>
</revision>
<revision>
<majorNum>0</majorNum>
<minorNum>1</minorNum>
<type>MINOR</type>
<date>2012-08-24</date>
<details>Updated Retina Audit</details>
</revision>
</revisions>
<patches>
<patch>
<type>V</type>
<title>Cisco</title>
<url>http://www.fake.com</url>
</patch>
</patches>
<scanners>
<retina>Audit 2548</retina>
</scanners>
<vms>
<stigFindingSeverity>1</stigFindingSeverity>
<affectedEnvs>B</affectedEnvs>
<posture>1029</posture>
<posture>1712</posture>
<posture>59</posture>
</vms>
</iavmNotice>

我很难理解如何将其转换为 xslt 文件

最佳答案

您的主要问题是未声明的 namespace 前缀 xmlns="http://stuff.com"。在 XSLT 中,您可以使用 xmlns:stuff="http://stuff.com" 分配一个前缀,然后为每个子元素添加前缀以 Access 其内容。

您的下一个问题是检索共享的 id,以便所有表都可以关联。考虑首先运行 Identity Transform按原样复制文档,然后在选择的节点中,运行 ancestor::* 以检索根目录下的 iavmNoticeNumber,并将其与原始内容一起复制到节点中。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:stuff="http://stuff.com" exclude-result-prefixes="stuff">
<xsl:output version="1.0" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*"/>

<!-- Identity Transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="stuff:entry|stuff:tempMitStrat|stuff:reference|stuff:deepSightBids|
stuff:revision|stuff:patch|stuff:scanners">
<xsl:copy>
<xsl:copy-of select="ancestor::stuff:iavmNotice/stuff:iavmNoticeNumber"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="stuff:vms">
<xsl:copy>
<xsl:copy-of select="ancestor::stuff:iavmNotice/stuff:iavmNoticeNumber"/>
<xsl:copy-of select="stuff:stigFindingSeverity|stuff:affectedEnvs"/>
<xsl:element name="posture" namespace="http://stuff.com">
<xsl:for-each select="stuff:posture">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:element>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

输出

<?xml version="1.0" encoding="utf-8"?>
<iavmNotice noticeId="138643" xmlns="http://stuff.com">
<xmlUrl>https://fakexmlurl.xml</xmlUrl>
<htmlUrl>https://fakehtmlurl.htm</htmlUrl>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<title>Cisco Vulnerability</title>
<type>B</type>
<state>FINAL</state>
<lastSaved>2012-08-24T10:34:13</lastSaved>
<precoordDueDate>2012-08-23T11:00:00</precoordDueDate>
<releaseDate>2012-08-23</releaseDate>
<acknowledgeDate>2012-08-28</acknowledgeDate>
<knownExploits>true</knownExploits>
<knownDodIncidents>false</knownDodIncidents>
<executiveSummary>Cisco incidents.</executiveSummary>
<techOverview>
<entry>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<title>2012-2490</title>
<description>Cisco ID 71.</description>
</entry>
</techOverview>
<fixAction>Apply appropriate vendor update</fixAction>
<note>&lt;b&gt;Upgrade later&lt;/b&gt;&lt;br&gt;&lt;br&gt;</note>
<tempMitStrat>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<header>&lt;b&gt;Cisco &lt;/b&gt;</header>
<body>&lt;br&gt;None</body>
</tempMitStrat>
<vulnAppsSysAndCntrmsrs>Cisco IP Communicator 8.6&lt;br&gt;&lt;br&gt;</vulnAppsSysAndCntrmsrs>
<references>
<reference>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<title>Release Notes for Cisco IP Communicator Release 8.6</title>
<url>http://www.fakeurl.com/html</url>
</reference>
</references>
<deepSightBids>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<bid>54850</bid>
</deepSightBids>
<revisions>
<revision>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<majorNum>0</majorNum>
<minorNum>0</minorNum>
<type>MAJOR</type>
<date>2012-08-23</date>
<details>Initial Release</details>
</revision>
<revision>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<majorNum>0</majorNum>
<minorNum>1</minorNum>
<type>MINOR</type>
<date>2012-08-24</date>
<details>Updated Retina Audit</details>
</revision>
</revisions>
<patches>
<patch>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<type>V</type>
<title>Cisco</title>
<url>http://www.fake.com</url>
</patch>
</patches>
<scanners>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<retina>Audit 2548</retina>
</scanners>
<vms>
<iavmNoticeNumber>2012-B-0080</iavmNoticeNumber>
<stigFindingSeverity>1</stigFindingSeverity>
<affectedEnvs>B</affectedEnvs>
<posture>1029</posture>
<posture>1712</posture>
<posture>59</posture>
</vms>
</iavmNotice>

关于xml - 如何将具有父/子关系的 XML 导入 Access?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41967865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com