cancel
Showing results for 
Search instead for 
Did you mean: 

How to read the attribute of a XML element? Please help!

gopalkrishna_baliga
Participant
0 Kudos

Hi experts,

<Batch>

<BatchCode ID= AA>

<DeliveryNote>190098</DeliveryNote>

<LotQuantity>1560</LotQuantity>

</BatchCode>

<BatchCode ID= BB>

<DeliveryNote>190098</DeliveryNote>

<LotQuantity>1560</LotQuantity>

</BatchCode>

</Batch>

Target message:

<BatchDelivery>

<DeliveryNote>190098</DeliveryNote>

<DNQuantity>1560</LotQuantity>

</BatchDelivery>

From the source message I want to pull only those batch details where ID is BB.

How to handle thsi in mapping?

Thanks

Gopal

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi,

Map the fields <DeliveryNote> and <LotQuantity> directly.

For the target node <BatchDelivery> use the condition ifWithOutElse. In the condition part use equlsS function. This function has 2 inputs. a)Constant "BB"" b)ID(attribute). Your mapping should look like this

Constant "BB"----

equalsS----if

ID----


BatchCode----


then

the output of this is mapped to the target node <BatchDelivery>.

I guess we discussed the same yesterday.

Regards,

Jai Shankar

udo_martens
Active Contributor
0 Kudos

correction:


<xsl:copy-of select="//BatchCode/*[../@ID='BB']"/>  

udo_martens
Active Contributor
0 Kudos

If you want to copy, use <i>copy-of</i>


<xsl:copy-of select="//BatchCode/*[../@ID='BB']/>  

udo_martens
Active Contributor
0 Kudos

Hi Gopal,

if you wonder why nobody has a good and quick tip for you: the kind of mapping would be interesting to answer the question. You can solve that grafical, with Java, ABAP or XSL. But of coz it is easier to cry <b>PLEASE HELP!</b> than to think about required details.

grafical: just drag and drop

If you use XSL:

<xsl:value-of select="//BatchCode/@ID"/>

ABAP or Java is assumedly not used by you.

Regards,

Udo

gopalkrishna_baliga
Participant
0 Kudos

Hi Udo,

I am using graphical mapping. It will be great if you can explain a bit more on how do I handle this in graphical mapping.

Is there any function to get attribute value?

Thanks

Gopal

prabhu_s2
Active Contributor
0 Kudos
BatchCode ID 
                      ___equals----ifwithoputelse==>targetfields 
                      /                   |
constant(BB) /                          sourcefield

is this is the stuff u r luking in graphical mapping?

gopalkrishna_baliga
Participant
0 Kudos

Hi Prabhu,

I ma sorry I have two levels of checks in my source XML.

<Batch>

<BatchCode ID= AA>

<BatchLabel>Primary</BatchLabel>

<DeliveryNote>190098</DeliveryNote>

<LotQuantity>1560</LotQuantity>

</BatchCode>

<BatchCode ID= BB>

<BatchLabel>Secondary</BatchLabel>

<DeliveryNote>190098</DeliveryNote>

<LotQuantity>1560</LotQuantity>

</BatchCode>

<BatchCode ID= BB>

<BatchLabel>Primary</BatchLabel>

<DeliveryNote>190098</DeliveryNote>

<LotQuantity>1560</LotQuantity>

</BatchCode>

</Batch>

So I need to pull batch details where first the BatchCode ID= AA and then where BatchLabel value is 'Primary'

Target message:

<BatchDelivery>

<DeliveryNote>190098</DeliveryNote>

<DNQuantity>1560</LotQuantity>

</BatchDelivery>

How to do the graphical mapping for this situation?

Thanks

Gopal

Former Member
0 Kudos

Hi Gopal,

see in your data type of your source message, you can add an attribute to your node......then in message mapping you can use this attribute to check with constant BB for equalS function - send its output to IF-THEN and then create your target node.

Thanks,

Rajeev Gupta

Former Member
0 Kudos

Hi Gopal,

You need to parse this XML using XML parsers like DOM or SAX with Java Code. You can check the required node and its values in parsing..Then you can use your business logic...

You need to use Java Mapping to achieve the same..

I can send you a sample Java mapping code to you if you can give me your email id...

Hope this Helps..

Kiran..