階層パーサートランスフォーメーションの例
階層データをリレーショナルデータに変換し、そのデータをターゲットファイルにリレーショナル形式で書き込むとします。
スキーマファイルを使用して入力データの階層を定義する階層スキーマを設定する必要があります。
次の例は、使用するスキーマ階層を示しています。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.itemfield.com" targetNamespace="http://www.itemfield.com" elementFormDefault="qualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="Emp_Details" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="Employeeid" type="xs:short"/>
<xs:element name="Name">
<xs:complexType>
<xs:sequence>
<xs:element name="Firstname" type="xs:string"/>
<xs:element name="Lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Dependents" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="address" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Addressid" type="xs:byte"/>
<xs:element name="Employeeid" type="xs:short"/>
<xs:element name="Line1" type="xs:string"/>
<xs:element name="Line2" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="State" type="xs:string"/>
<xs:element name="Zipcode" type="xs:int"/>
<xs:element name="Fromdate" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="EmpAttribute" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
次の例は、使用する入力ファイルデータを示しています。
<itm:root xmlns:itm="http://www.itemfield.com">
<!--Zero or more repetitions:-->
<itm:Emp_Details EmpAttribute="string">
<itm:employee>
<itm:Employeeid>1</itm:Employeeid>
<itm:Name>
<itm:Firstname>Gina</itm:Firstname>
<itm:Lastname>Aniston</itm:Lastname>
</itm:Name>
<!--1 or more repetitions:-->
<itm:Dependents>anyType</itm:Dependents>
</itm:employee>
<!--Optional:-->
<itm:address>
<itm:Addressid>2</itm:Addressid>
<itm:Employeeid>1</itm:Employeeid>
<itm:Line1>Long Tech Park</itm:Line1>
<itm:Line2>Industrial Zone</itm:Line2>
<itm:City>Wichita</itm:City>
<itm:State>KA</itm:State>
<itm:Zipcode>773301</itm:Zipcode>
<itm:Fromdate>2011-09-29</itm:Fromdate>
</itm:address>
</itm:Emp_Details>
</itm:root>
データ統合で、使用するスキーマ階層を持つ階層スキーマを作成します。
入力データを解析するには、マッピングで階層パーサートランスフォーメーションを使用して階層入力のデータを変換します。Mapping Designerで、解析するデータへのパスが含まれているフラットファイルをソースオブジェクトとして追加します。
次の図に、選択したソーストランスフォーメーションを示します。
階層パーサートランスフォーメーションを追加し、NewHierarchyParserという名前を使用します。作成した階層スキーマを使用するようにこのトランスフォーメーションを設定します。
ソースオブジェクトをNewHierarchyParserトランスフォーメーションに接続します。受信データをトランスフォーメーションの各フィールドにマッピングするには、NewHierarchyParserトランスフォーメーションを選択します。[入力フィールド選択]タブで、選択した受信フィールドをソーストランスフォーメーションからNewHierarchyParser階層スキーマ入力フィールドにマッピングします。
データをリレーショナルフィールドにマッピングするには、[フィールドマッピング]タブで、出力へのリレーショナルフィールドとして反映されるスキーマ要素を選択します。
次の図に、フィールドマッピング選択を示します。
フィールドのファイルターゲットオブジェクトを追加します。
次の図に、マッピングを示します。
マッピングを実行して、リレーショナル形式のデータをターゲットトランスフォーメーションに書き込みます。
次の例は、リレーショナル出力を示しています。
EmpAttribute | Employeeid | Firstname | Lastname | Addressid | Employeeid1 | Line1 | Line2 |
---|
string | 1 | Gina | Aniston | 2 | 1 | Long Tech Park | Industrial Zone |
City | State | Zipcode | Fromdate |
---|
Wichita | KA | 773301 | 9/29/2008 12:00:00 AM |