简体   繁体   中英

How to capture the repeating XML elements in a sequence using Datastage in the same order

I am using Datastage 9.1 version. I want to read the XML elements in the same sequence that they appear in the XML.

The XSD i have looks like this:

<xsd:complexType name="Optimization">        
    <xsd:sequence>     
        <xsd:element name="Values" type="Values" minOccurs="1" maxOccurs="1"/>        
    </xsd:sequence>        
    <xsd:attribute name="required" type="xsd:boolean" use="required"/>    
</xsd:complexType>
<xsd:complexType name="Values">       
    <xsd:sequence> 
        <xsd:element name="Value" type="xsd:String" maxOccurs="unbounded"/>        
    </xsd:sequence>   
    <xsd:attribute name="selection" type="SelectionAttr" use="required"/>    
</xsd:complexType>

Sample XML for this XSD is:

<Optimization required="false">
<Values>
<Value selected="true">abc</Value>
<Value selected="true">def</Value>
<Value selected="true">ghi</Value>
</Values>
</Optimization>

I want to read the optimizations values using datastage. But i want to associate a sequence number to each value that indicates the sequence in which the the value appeared in the XML as shown below:
SeqNo Value
1 abc
2 def
3 ghi

If the XML is different like below:

<Optimization required="false">
<Values>
<Value selected="true">ghi</Value>
<Value selected="true">abc</Value>
<Value selected="true">def</Value>
</Values>
</Optimization>

Then the output should be like this: SeqNo Value
1 ghi
2 abc
3 def

Is this possible using datastage XML stages? If so, can you please let me know how I can achieve this?

Thanks.

The XML stage / Hierarchical stage can help to get the values. The numbering can be done with a transformer for example. In the XML stage use the XML Parser step.

Check out some documentations available in the internet for a step by step description

Alternative: If your source is a relational database check out SQL options to SELECT the result you need.

If you're able to import the data, as it seems you can. Adding a seq number is easy.

Job design: [XML/Hierachical input stage] > Transformer Stage > [Output/Additional stage(s)]

Steps:

From your input stage, link to transformer, from transformer to additional stages or an output stage of some kind (file or database). Configure your input stage to have columns, making the source xml readable. Open transformer, drag you input links across so that the transformer has that/those link(s) as output. Create a new column in the output of the transformer named sequence_number (or something) of type int. In the derivation of that new link type @OUTROWNUM.

Go into the settings of the transformer (button on top left when you open the transformer) go to advanced tab. Set the stage to run in sequential mode. That will maintain the order of your rows as it gets it from your input source stage (assuming the transformer is immediately after your input stage and your input stage hasn't forcibly been set to run in parallel).

The output from the transformer should now have a sequence number.

Does that answer your question?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM