我有一个数据流任务,其中的 XMLSource 引用了一个 XML 变量。 DataFlow 任务确实识别出变量中有 x 行,但它只会在每一行中看到空值:
xml变量值:
<?xml version="1.0" encoding="utf-8"?>
<words>
<word>butter</word>
<word>crispy</word>
</words>
我使用此源在 XMLSource 编辑器中生成 XSD - 这是自动生成的 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 行的截图:
最佳答案
我发现了一种获取填充值的方法...我会在此处发布它而不给自己加分,以防其他人遇到同样的问题。这只是一个“如何解决”,但我会感谢任何可以解释“更深层原因”的人。
本质上,XML 需要包装在另一个根节点中:
<?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。一旦我这样做了,包就会识别出 word 值并成功完成。
相关架构:
<?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>
关于sql-server - SSIS XMLSource 只看到 XML 变量中的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4028373/