cancel
Showing results for 
Search instead for 
Did you mean: 

How to filter data from a source XML? Please help!

gopalkrishna_baliga
Participant
0 Kudos

Hi Experts,

I have a source XML as shown below:

<Inventory>

<InventoryItem>

<ItemCode>InTransit</ItemCode>

<Quantity>1000</Quantity>

</InventoryItem>

<InventoryItem>

<ItemCode>Available</ItemCode>

<Quantity>1500</Quantity>

</InventoryItem>

<InventoryItem>

<ItemCode>Restricted</ItemCode>

<Quantity>2500</Quantity>

</InventoryItem>

</Inventory>

My Target XML is as below

<Inventory>

<stock>1500</stock>

</Inventory>

The stock element contains Quantity value where ItemCode is 'Available'.

But note that there are 3 InventoryItem nodes.

So how to get the desired target XML in XI mapping? Basically I have to filter data from source XML based on value of an element. What is the best approach to handle this?

Kindly help

Thanks

Gopal

Accepted Solutions (0)

Answers (6)

Answers (6)

prasanthi_chavala
Active Contributor
0 Kudos

Hi Gopal,

I tried using graphical mapping.I am getting the output.Just try this:

Map item and constant(available) to equals(text) and map this to ifwithoutelse(Boolean) and map quantity to other end of ifwithoutelse and map this to removecontext and this to stock.

Item----


____ equals>ifwithoutelse>removecontext-->stock |

Constant--- |

(available) quantity------

Note:equals should be from text fuction category and item,quantity context should be inventoryitem.

It will work.

Regards,

Prasanthi.

Former Member
0 Kudos

Hi,

For Target Field Stock, use the following Mapping (in Graphical Mapping):

If (ItemCode = Available), i.e.,

IfwithoutElse (equalsS (ItemCode, Constant (Available)))

Then map Stock to Quantity.

Note: Keep <b>Context</b> of ItemCode and Quantity as <b>Inventory</b>.

That should do it.

Regards,

Puloma.

Former Member
0 Kudos

Hi,

This can be done using Graphical mapping itself.


<itemCode>(context menu -> set context to Inventory)--
                                                      equalsS ------------
Constant(Available) ----------------------------------
                                                                              ifWithoutElse ------- CollapseContexts -------- splitByvalue --- stock
Quantity(context menu -> set context to Inventory)---------------------------

Note: stock should be unbounded

Regards,

P.Venkat

gopalkrishna_baliga
Participant
0 Kudos

Hi venkat,

Your solution does'nt work fine. But why are you using collapsecontext and splitbyvalue before putting the value into stock element?

Kindly explain your concept.

My target message is:

<?xml version="1.0" encoding="UTF-8"?>

<Inventory>

<InventoryItem>

<ItemCode>InTransit</ItemCode>

<Quantity>1500</Quantity>

</InventoryItem>

<InventoryItem>

<ItemCode>Available</ItemCode>

<Quantity>1000</Quantity>

</InventoryItem>

<InventoryItem>

<ItemCode>UnRestricted</ItemCode>

<Quantity>2000</Quantity>

</InventoryItem>

<InventoryItem>

<ItemCode>Available</ItemCode>

<Quantity>2500</Quantity>

</InventoryItem>

</Inventory>

I am getting the output even though stock is unbounded and I have used collapsecontext and splitbyvalue as:

<InvStock>

<Stock>1000</Stock>

</InvStock>

I should get:

<InvStock>

<Stock>1000</Stock>

<Stock>2500</Stock>

</InvStock>

Thanks

Gopal

Message was edited by:

gopalkrishna baliga

Former Member
0 Kudos

Hi,

>> am getting the output even though stock is unbounded and I have used collapsecontext and splitbyvalue as:

<InvStock>

<Stock>1000</Stock>

</InvStock>

I should get:

<InvStock>

<Stock>1000</Stock>

<Stock>2500</Stock>

</InvStock>

For this try with out the Splitby Value.

Also, it is possible to map the fields at root node level like I suggested. I tried this and got it working.

Regards,

Jai Shankar

Former Member
0 Kudos

Hi Gopal,

do the following in graphical mapping.

(ItemCode -equalS - constant( available) ) -> if -

constant[]-> then -> creatif -> InvStock

(ItemCode -equalS - constant( available) ) ->if

quantity then->Stock

Right click on quantity and change the context to Inventory.

This shall solve your query.

Thanks,

Rajeev Gupta

Former Member
0 Kudos

Gopal,

This is possible in Graphical mapping.

Use the condition at target node <Inventory>

Check for the condition "available" with a Text function equlsS here. If it is equal map the <ItemCode> to <Inventory. Use a ifwithoutElse for this purpose.

Regards,

Jai Shankar

former_member192343
Active Contributor
0 Kudos

i think it is possible in visual mapping using conditions. You have to create instruction like this: If ItemCode=Available then stock=quantity.

prasanthi_chavala
Active Contributor
0 Kudos

Hi Gopal,

You can go for java mapping and u can write conditions in parsings techniques based on ur requirements and can able to extract the required data.

Regards,

Prasanthi.