是否可以使用ssis将XML文件上传到SQL Server

时间:2019-04-18 14:32:42

标签: xml ssis xsd etl

我公司使用的软件生成了数千个XML文件。我需要将其中包含的数据上传到SQL Server进行报告。

我打算使用SSIS上载数据。我为每个循环创建了一个,以读取每个文件并将文件名作为变量传递给数据流任务。 DFT将读取每个XML,并将其上传到SQL表。我很难让DFT读取XML。

我生成了一个XSD文件,但是它没有按我的需要读取XML。不幸的是,该软件是第三方软件,并且已被其他公司使用,因此我们无法调整XML。我唯一可以更改的是XSD或SSIS软件包。

这是XML

<SOFTWAREDATA>
  <version>4</version>
  <date>2018-04-26</date>
  <start_time>13:39:15</start_time>
  <end_time>13:40:14</end_time>
  <user>user</user>
  <group>stn</group>
  <sequence>stn</sequence>
  <line_path>company</line_path>
  <line_path>location</line_path>
  <line_path>productionline</line_path>
  <training_file>filename.txt</training_file>
  <model>model</model>
  <variant>model-RHD</variant>
  <difficulty_level>1</difficulty_level>
  <no_of_operations>1</no_of_operations>
  <no_of_overview_questions>0</no_of_overview_questions>
  <no_of_correct_operations>1</no_of_correct_operations>
  <no_of_wrong_operation>0</no_of_wrong_operation>
  <no_of_missed_operation>0</no_of_missed_operation>
  <no_of_wrong_tool>0</no_of_wrong_tool>
  <no_of_wrong_prop>0</no_of_wrong_prop>
  <no_of_wrong_answers>0</no_of_wrong_answers>  
  <no_of_wrong_overview_answers>0</no_of_wrong_overview_answers>
  <no_of_wrong_direction>0</no_of_wrong_direction>
  <no_of_tool_help>0</no_of_tool_help>
  <no_of_part_help>0</no_of_part_help>
  <no_of_show_operation_help>0</no_of_show_operation_help>
  <no_of_info_help>0</no_of_info_help>
  <no_of_navigation_help>0</no_of_navigation_help>
  <no_of_operation_list_help>0</no_of_operation_list_help>
  <was_sequence_completed_ok>true</was_sequence_completed_ok>
  <priority_mode>false</priority_mode>
  <version_info>info</version_info>
  <build>404</build>
  <revision>51</revision>
  <errors>0</errors>
</SOFTWAREDATA>

这是XSD

<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="SOFTWAREDATA">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" name="version" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="date" type="xs:date" />
        <xs:element minOccurs="0" name="start_time" type="xs:time" />
        <xs:element minOccurs="0" name="end_time" type="xs:time" />
        <xs:element minOccurs="0" name="user" type="xs:string" />
        <xs:element minOccurs="0" name="group" type="xs:string" />
        <xs:element minOccurs="0" name="sequence" type="xs:string" />
        <xs:element minOccurs="0" maxOccurs="unbounded" name="line_path" type="xs:string" />
        <xs:element minOccurs="0" name="training_file" type="xs:string" />
        <xs:element minOccurs="0" name="model" type="xs:string" />
        <xs:element minOccurs="0" name="variant" type="xs:string" />
        <xs:element minOccurs="0" name="difficulty_level" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_operations" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_overview_questions" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_correct_operations" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_wrong_operation" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_missed_operation" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_wrong_tool" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_wrong_prop" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_wrong_answers" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_wrong_overview_answers" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_wrong_direction" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_tool_help" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_part_help" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_show_operation_help" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_info_help" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_navigation_help" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="no_of_operation_list_help" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="was_sequence_completed_ok" type="xs:boolean" />
        <xs:element minOccurs="0" name="priority_mode" type="xs:boolean" />
        <xs:element minOccurs="0" name="version_info" type="xs:string" />
        <xs:element minOccurs="0" name="build" type="xs:unsignedShort" />
        <xs:element minOccurs="0" name="revision" type="xs:unsignedByte" />
        <xs:element minOccurs="0" name="errors" type="xs:unsignedByte" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

除了在Power查询中读取文件没有问题(文件太多,无法使用Power查询)之外,我刚开始使用XML。我本来希望看到一张表,其中有一行,每个元素名称作为列标题,而该行中的值。

当我尝试在SSIS中读取文件时,它只会显示“ line_path”列:

enter image description here

是否可以通过更改软件包或XSD来实现我想要的目标?

1 个答案:

答案 0 :(得分:0)

对于可能偶然发现这篇文章的人,我已经找到了解决方案...

我没有使用XML源,而是在Excel Power Query中创建了一些M代码,并在Power查询源中使用了M代码。我能够一次访问一个表中的所有XML,并将其上传到SQL,而不必单独遍历每个文件。

如果需要有关此解决方案的更多详细信息,请随时与我联系。