Mail me if you are looking for IBM Datastage quality stage with realtime stages like xml,json,mq,Webservices training and assistance/Support
Monday, September 11, 2017
Thursday, July 7, 2016
XML Output Stage
Xml Output
stage is one of the most used stage of XML pack of IBM Datastage
Quality stage.It can be used to generate xml from tabular data.its
most useful and easily configurable. All you need to know is the
structure of your xml and appropriate XML paths in your xsd. Assuming
you have basic knowledge on XPaths and different types of
elements,attributes possible on a xml document,I am going to explain
Xml stage with an example below.
Input data:
And we
trying to generate Xmls as per below xsd.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Book_Info" type="BInfoType" />
<xs:complexType name="BInfoType">
<xs:sequence>
<xs:element name="BookName"
<xs:element name="Author"
<xs:element name="Version"
<xs:element name="Release Date"
</xs:sequence>
</xs:complexType>
</xs:schema>
In above xsd only two attributes are mandatory BookName and Author other two are optional as we can see minOccurs value is zero.Now lets see the configuration requried to make in Xml output stage to generate a xml as per this xsd. As we have in every other stage in datastage even Xml output stage has 3 tabs as below.
The term XPATH in Xml document refers to the hierarchy of the element/attribute you are interested to read or create/refer to.for example in our sample xsd the XPATH for BookName attribute is “/ Book_Info/BookName”,which mean starting from top most attribute of xml to the attribute which you are referring is called XPATH.
In input tab of Xml input stage columns tab there is column named “Derivation” in that you need to mention the XPATH,its like mapping your input /column to its path in XML. Once it is done you are almost done with stage. all you left with now is output tab configuration.
<Author>E.F.Codd</Author>
<Author>Kalam</Author>
Input data:
Book Name
|
Author
|
Version
|
Release
Date
|
Let Us C
|
Yashwant
|
1
|
07-07-2016
|
DBMS
|
E.F.Codd
|
2
|
08-07-2016
|
Wings Of Fire
|
Kalam
|
3
|
09-07-2016
|
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Book_Info" type="BInfoType" />
<xs:complexType name="BInfoType">
<xs:sequence>
<xs:element name="BookName"
type="xs:string"
minOccurs="1"
maxOccurs="1" /><xs:element name="Author"
type="xs:string"
minOccurs="1"
maxOccurs="1" /><xs:element name="Version"
type="xs:string"
minOccurs="0"
maxOccurs="1" /><xs:element name="Release Date"
type="xs:string"
minOccurs="0"
maxOccurs="1"
/></xs:sequence>
</xs:complexType>
</xs:schema>
In above xsd only two attributes are mandatory BookName and Author other two are optional as we can see minOccurs value is zero.Now lets see the configuration requried to make in Xml output stage to generate a xml as per this xsd. As we have in every other stage in datastage even Xml output stage has 3 tabs as below.
- Stage Tab
- Input Tab
- Output Tab
The term XPATH in Xml document refers to the hierarchy of the element/attribute you are interested to read or create/refer to.for example in our sample xsd the XPATH for BookName attribute is “/ Book_Info/BookName”,which mean starting from top most attribute of xml to the attribute which you are referring is called XPATH.
In input tab of Xml input stage columns tab there is column named “Derivation” in that you need to mention the XPATH,its like mapping your input /column to its path in XML. Once it is done you are almost done with stage. all you left with now is output tab configuration.
Output
tab has 6 tabs internally,Out of which only 4 are important,which are
described below.
- Document Settings.
- Transformation Settings.
- Options.
- Columns.
Document
Settings tab has options to configure all the documentation related
information like name space declarations and Adding comments to
generated xml document. Under Transformation settings you have
options to “Replace Nulls with Empty values” and “Replace Empty
values with Nulls”,Options related to trigger Columns. This trigger
columns has a significance as when you choose a column in this
option,for every change in value of this column will result in new
output row from this stage. so make sure you sort the data before xml
output stage and choose the same key columns which you have used in
sort as part of trigger column. Under options tab you very less to do
that to if you want a formatted xml in output ,if yes then choose the
appropriately. Finally under columns tab define a column for holding
your generated xml document and it is suggested to define the data
type as longvarchar as normally xml documents are lengthy and in
derivation put “/” which denotes an output column. with this you
are all set to go ahead and test your job.
Below
is the sample output as per the discussed settings and using BookName
as trigger column
Row
1:
<Book_Info>
<BookName>Let
Us C</BookName>
<Author>Yashwant</Author>
<Version>1</Version>
<ReleaseDate>07-07-2016</ReleaseDate>
</Book_info>
Row
2:
<Book_Info>
<BookName>DBMS</BookName><Author>E.F.Codd</Author>
<Version>2</Version>
<ReleaseDate>08-07-2016</ReleaseDate>
</Book_info>
Row
3:
<Book_Info>
<BookName>Wings
Of Fire</BookName><Author>Kalam</Author>
<Version>3</Version>
<ReleaseDate>09-07-2016</ReleaseDate>
</Book_info>
Subscribe to:
Posts (Atom)