Creating multiple xml elements in tXMLMap under specific circumstances

Six Stars

Creating multiple xml elements in tXMLMap under specific circumstances

Hello Talend experts,

I'm a newcommer in Talend. I need to create an integration SOAP->SOAP synchronous scenario but because of both sides limitations I need to create <fieldsToIgnore> element for each element that is not present in inbound soap envelope. 

mapping.pngSo for example when there is no <LastName>, <Gender> and <Phone> element in inbound message, outbound structure has to contain 

<fieldsToIgnore>LastName</fieldsToIgnore><fieldsToIgnore>Gender</fieldsToIgnore><fieldsToIgnore>Phone</fieldsToIgnore>

before the <sap_acc> element.

And my question is: what's the best practice to approach this kind of problem? How to construct that kind of expression?

 

Thanks in advance,

Michał


Accepted Solutions
Ten Stars

Re: Creating multiple xml elements in tXMLMap under specific circumstances

You are probably the first (here) to encounter this kind of problem... you are The ONE to create the best practice! ...

 

Suggestion ... extra steps and if element==null then ... 

You probably have to do it for each element to find out if its null

And if its null ... build up a xml string... put it into a global var and inject it into the final xml with a regex replace... 

 

Or javacode (I would use something like this):

tXMLMap with final complete xml doc and alter/transform it.

 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 DocumentBuilder builder = factory.newDocumentBuilder();
 Document doc = builder.parse(xmlFile);
 TransformerFactory tFactory = TransformerFactory.newInstance();
 Transformer tFormer = tFactory.newTransformer();

 

 

 

Ten Stars

Re: Creating multiple xml elements in tXMLMap under specific circumstances

 

> Is there a way to get element name, no it's value, in mapping expression?

Yes, but not sure how XPath works and version in tXMLMap -  but it's name()

 

XPath 2.0 only:

//userprofilesettings/*/name()

XPath 1.0 and 2.0:

name(//userprofilesettings/*)

 

> And how can I iterate over source elements

There's a loop over which you can set, but I suggest make two steps (tXMLMap) one for the missing elements to loop over and one for the actual data/output...

 

 


All Replies
Ten Stars

Re: Creating multiple xml elements in tXMLMap under specific circumstances

You are probably the first (here) to encounter this kind of problem... you are The ONE to create the best practice! ...

 

Suggestion ... extra steps and if element==null then ... 

You probably have to do it for each element to find out if its null

And if its null ... build up a xml string... put it into a global var and inject it into the final xml with a regex replace... 

 

Or javacode (I would use something like this):

tXMLMap with final complete xml doc and alter/transform it.

 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 DocumentBuilder builder = factory.newDocumentBuilder();
 Document doc = builder.parse(xmlFile);
 TransformerFactory tFactory = TransformerFactory.newInstance();
 Transformer tFormer = tFactory.newTransformer();

 

 

 

Six Stars

Re: Creating multiple xml elements in tXMLMap under specific circumstances

Thanks for the answer! It's really helpful.

I have two more (I hope simple) question then:

Is there a way to get element name, no it's value, in mapping expression?

And how can I iterate over source elements, is there some kind of java collection with the elements available in the expression field?

Because if the answer is yes for both questions then it will be relatively easy to do the way I need to.

Thanks once more for your advice.

Ten Stars

Re: Creating multiple xml elements in tXMLMap under specific circumstances

 

> Is there a way to get element name, no it's value, in mapping expression?

Yes, but not sure how XPath works and version in tXMLMap -  but it's name()

 

XPath 2.0 only:

//userprofilesettings/*/name()

XPath 1.0 and 2.0:

name(//userprofilesettings/*)

 

> And how can I iterate over source elements

There's a loop over which you can set, but I suggest make two steps (tXMLMap) one for the missing elements to loop over and one for the actual data/output...