Access a “String Array” from tExtractXMLField (XML tag with +1 value)

北战南征 提交于 2019-11-28 13:10:01

问题


My Talend Job has the following structure:

  • tREST component that executes a POST HTTP Request, and receives a XML file.

  • tExtractXMLField component that reads a tag from that XML file, like:

Now, I want to save all the values from the tagX, and then access them. For each value of the tagX, I will perform a HTTP POST with that value in the body. How can I do that?

Thanks


回答1:


You need a component called tHttpRequest. But this component doesn't allow to be connected to row flows. But there's a way to accomplish.

Let's say you extracted your tagX field and put the value on a String field called 'tagX' you fed to an outgoing connection. You then need the component 'tFlowToIterate' to convert a row connection to a iterate connection. Look the iterate connection as a kind of signal that doesn't contain data; it's triggered at each incoming iteration. This subjob below calls the tJava code (which in turn prints 'hello world' on console) for every row incoming from tExtractXMLField:

Now the magic. Inside the parameters of tFlowToIterate you can define one or more global variables fed with fields from the incoming connection. The example above set the global var foo with the value of the field customer of the connection row2:

This variable is now accessible everywhere in your Talend job using (String)globalMap.get("foo"). Be careful to cast to the proper type, as globalMap is a Object-only collection.

To parametrize your HTTP post call, you just need a tHttpRequest component with the variable you just set:

Now it's up to you to handle tHttpRequest output (a single big String field with the entire response). Remember that rows in in input, when converted to Iterate signal, lost their data (the fields you saved into the globalMap don't technically own to the flow anymore) but the total number is unchanged. So, if you have, let's say, 4 incoming rows, you will trig the Iterate signal 4 times, causing the involved globalMap variables to be refreshed and tHttpRequest component to make 4 (parametrized) http requests automatically.



来源:https://stackoverflow.com/questions/20334590/access-a-string-array-from-textractxmlfield-xml-tag-with-1-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!