cancel
Showing results for 
Search instead for 
Did you mean: 

Convert XML String to Message

Former Member
0 Kudos

Hi,

My scenario is JDBC to RFC. The table say "XXX" has a field which contain an XML string. This is the message that is required to be send to RFC. How will I convert this string to a message for mapping?

regards

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

write a small UDF which has input field 'a' you are getting

StringBuffer sb = new StringBuffer("");
return a.toString();

Assign it to the target field

Is this what your requirement is. let me know if I am wrong

Former Member
0 Kudos

You got my requirement wrong. I have the xml already in a String, need to convert to a message.

for example my pay load is as below

<row>

<MESSAGE>

<header><firstName>UK</firstName><lastName>kk</lastName></header>

<MESSAGE>

</row>

The <MESSAGE> is the oracle column of a table that contain the xml string what you see in <header></header>.

Former Member
0 Kudos

Oops, My Bad. let me understand again.Correct me If I am wrong

<header><firstName>UK</firstName><lastName>kk</lastName></header>

So you want to extract the values like "UK" and "kk" from that XML string and map them to the target.

Former Member
0 Kudos

Hi,

You got it this time :). I will have multiple such rows of data coming in for each polling.

regards

Unni

justin_santhanam
Active Contributor
0 Kudos

Unni,

So you will get like the below structure is it?

<row>

<MESSAGE>

<header><firstName>UK</firstName><lastName>kk</lastName></header>

<MESSAGE>

</row>

<row>

<MESSAGE>

<header><firstName>US</firstName><lastName>RJ</lastName></header>

<MESSAGE>

</row>

<row>

<MESSAGE>

<header><firstName>IN</firstName><lastName>PI</lastName></header>

<MESSAGE>

</row>

You won't have any other stuff apart from FirstName and last name tag is it? Also FirstName must go to one target field and Last Name must go to other Target field , Am I correct?

raj.

Former Member
0 Kudos

Unni:

<header><firstName>UK</firstName><lastName>kk</lastName></header>

One more question, if there is value missing, like there is no value for Middle name then how it will be represented

<header><firstName>UK</firstName></MiddleName><lastName>kk</lastName></header>

or

<header><firstName>UK</firstName><MiddleName></MiddleName><lastName>kk</lastName></header>

Former Member
0 Kudos

Hi raj

My xml structure is quiet complex and its not wht i showed is eg. Your points are correct. Thats what I require to do.

Guru: My structure would be as below

<header><firstName>UK</firstName><MiddleName></MiddleName><lastName>kk</lastName></header>

For info sake it would good if you could explain the case where it occurs as <header><firstName>UK</firstName></MiddleName><lastName>kk</lastName></header>

also.

Thanks

prateek
Active Contributor
0 Kudos

U have to use java mapping for this. The data would be passed to the java code and should be accessed using parser e.g. DOM

Regards,

Prateek

justin_santhanam
Active Contributor
0 Kudos

Unni,

If you have less number of nodes then you can go for UDF, if not Java mapping would be the option. I will take an example and explain the same.

Example

Source

<Row>0..Unbounded

<Header/>1..1

</Row>

Target

<Records>0..Unbounded

<Fname/>0..1

<Mname/>0..1

<Lname/>0..1

</Records>

UDF1



// This UDF used to genereate no.of Records in the target.

//one input parameter, lets consider parameter name as Header- Advanced UDF

for(int i=0;i<Header.length;i++)
{
if( (Header<i>.indexOf("<Fname>") !=-1) || (Header<i>.indexOf("<mname>") !=-1) || (Header<i>.indexOf("<Lname>") !=-1) )
{
result.addValue("");
}
}

Header(Change Context)----->UDF1--


>Records

UDF2



// This UDF used to genereate nodes in the target. 

//Two input parameter, lets consider parameter name as *Header*, and second as *node*- Advanced UDF

for(int i=0;i<Header.length;i++)
{

if(node.equals("1"))
{
// This if condition used to generate Fname node
if(str.indexOf("<Fname>")!=-1)
		{
		result.addValue(""+str.substring(str.indexOf("<Fname>")+7,str.indexOf("</Fname>"))+"");
result.addContextChange();
		}
		else
		{
                                     result.addSuppress();
                                     result.addContextChange();

		}

}

else if(node.equals("2"))
{
// This if condition used to generate Mname node

if(str.indexOf("<Mname>")!=-1)
		{
		result.addValue(""+str.substring(str.indexOf("<Mname>")+7,str.indexOf("</Mname>"))+"");
result.addContextChange();
		}
		else
		{
                                     result.addSuppress();
                                     result.addContextChange();
		}

}

else if(node.equals("3"))
{
// This if condition used to generate Lname node

if(str.indexOf("<Lname>")!=-1)
		{
		result.addValue(""+str.substring(str.indexOf("<Lname>")+7,str.indexOf("</Lname>"))+"");
result.addContextChange();
		}
		else
   		{
                                     result.addSuppress();
                                     result.addContextChange();

		}

}

}

The logic is

Header(Change Context) , Constant (1) -


>UDF2----


>Fname

Header(Change Context) , Constant (2) -


>UDF2----


>Mname

Header(Change Context) , Constant (3) -


>UDF2----


>Lname

Since, I don't have a system right now, I couldn't able to give u snapshot, sorry abt that.

But I'm sure, it will work!

Hope it helps a bit.

raj.

Former Member
0 Kudos

Hi Raj,

Thanks a lot for the snippet. It helped.

Can you also give me some link to Java Mapping development.

regards

Unni

justin_santhanam
Active Contributor
0 Kudos

Unni,

I haven't tested the code for all cases. Check it and let me know if you face some issues.

There are bunch of solutions which I gave to the SDN problems, you can have a look

http://flickr.com/photos/8764045@N06/

http://flickr.com/photos/23855877@N07/

raj.