SSIS XMLSource 只看到 XML 变量中的空值

2021-12-30 00:00:00 package sql-server ssis dts

我有一个数据流任务,其中的 XMLSource 引用了一个 XML 变量.DataFlow 任务确实识别出变量中有 x 行,但它只看到每一行中的空值:

I have a Data Flow task with an XMLSource that references an XML Variable. The DataFlow task does recognize that there are x number of rows in the variable, but it only sees null values in every row:

xml 变量值:

<?xml version="1.0" encoding="utf-8"?>
<words>
   <word>butter</word>
   <word>crispy</word>
</words>

我使用此源在 XMLSource 编辑器中生成 XSD - 这是自动生成的 XSD:

I used this source to generate the XSD within the XMLSource Editor - here is the auto-generated XSD:

<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="words">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="word" type="xs:string" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

该包编译、执行和处理我的 XML 中的所有行,但只看到空值而不是实际的文本字符串......这是 DataViewer 在读取 XML 变量后显示 2 行的截图:

The package compiles, executes, and processes all the rows in my XML, but only sees nulls rather than the actual text strings... Here is a shot of the DataViewer displaying 2 rows after reading the XML variable:

推荐答案

我发现了一种让值填充的方法...我将把它贴在这里而不给自己加分,以防其他人遇到同样的问题.这只是一个如何解决",但我会感谢任何能够解释更深层次原因"的人.

I discovered a way to get the values to populate... I'll post it here without giving myself points, in case anyone else encounters the same problem. This is just a "how to fix", but I'll give credit to anyone who can explain the "deeper whys".

本质上,XML 需要包装在另一个根节点中:

Essentially, the XML needed to be wrapped in another root node:

<?xml version="1.0" encoding="utf-8"?>
<datarows>
   <words>
      <word>bacon</word>
      <word>roasted</word>
      <word>pork</word>
      <word>edamame</word>
   </words>
</datarows>

即使我使用的原始 XML 是有效的,SSIS 还是希望将它包装在一个额外的根节点中,我将其命名为 datarows.一旦我这样做了,程序包就会识别词值并成功完成.

Even though the original XML I used was valid, SSIS wanted it to be wrapped in an additional root node, which I named datarows. Once I did that the package recognized the word values and completed successfully.

关联的架构:

<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="datarows">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="1" name="words">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="0" maxOccurs="unbounded" name="word" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

相关文章