gpt4 book ai didi

xml - 如何使用 ssis 从多个 XML 文件中删除命名空间?

转载 作者:行者123 更新时间:2023-12-04 17:01:16 25 4
gpt4 key购买 nike

试图从多个 xml 文件中删除命名空间。从文件夹导入 xml 文件并尝试将转换后的 xml 文件导出到输出文件夹。
我在 ssis 中用于每个循环容器和 xml 任务,但不确定为什么它会给我错误。任何循序渐进的过程都会有所帮助。谢谢
这是我对最终结果所做的分步过程。
1.三个xml文件-
enter image description here
使用 xml 任务可以轻松删除一个文件中的命名空间,如下所示 enter image description here
enter image description here
这里我在输出文件夹中有没有命名空间的文件
enter image description here
要从我用于每个循环容器的所有三个文件中删除命名空间,并通过定义变量进行配置:
enter image description here
enter image description here
然后变量映射enter image description here
[![在此处输入图像描述][8]][8]
然后配置源连接管理器和目标连接管理器,然后运行包
enter image description here
enter image description here
enter image description here
enter image description here

Example 1 xml






Example 2 xml
<AMOUNT_MONEY xmlns="http://www.somewhere.com/ABC" version="5.252">
<NAMES>
<BORROWER home_country="USA" work_phone="" d3p1:internal_borrower_id="fec5645fc4cgd982" xmlns:d3p1="http://www.somewhere.com/Intern">
<CURRENT_ADDRESS occupancy_status="OWN" occupancy_description="">
<FORMER_ADDRESS street_address_1="111 MAIN LN" county="" />
</CURRENT_ADDRESS>
</BORROWER>
</NAMES>
</AMOUNT_MONEY>

Example 3 xml

<AMOUNT_MONEY xmlns="http://www.somewhere.com/ABC" version="5.252">
<NAMES>
<BORROWER home_country="CA" work_phone="" d3p1:internal_borrower_id="8fec53vfg982845bf" xmlns:d3p1="http://www.somewhere.com/Intern">
<CURRENT_ADDRESS occupancy_status="RENTTOOWN" occupancy_description="">
<FORMER_ADDRESS street_address_1="985 CHERRY ST" county="" />
</CURRENT_ADDRESS>
</BORROWER>
</NAMES>
</AMOUNT_MONEY>
评论:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="no" />
<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>

最佳答案

我在我的机器上运行 XSLT 没有任何问题。它根据需要删除命名空间。
XSLT

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
让我们专注于 SSIS 方面。 User::FILEPATH变量将包含 Foreach 循环容器中源 XML 文件的完全限定路径。所以你不能直接将它与目标目录连接起来。
您需要做的是修复目标文件连接表达式,如下所示:
"c:\\destinationDirectory\\" + TOKEN(@[User::FILEPATH], "\\", TOKENCOUNT(@[User::FILEPATH], "\\"))

关于xml - 如何使用 ssis 从多个 XML 文件中删除命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64109947/

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