访问“字符串数组"来自 tExtractXMLField(具有 +1 值的 XML 标记) [英] Access a "String Array" from tExtractXMLField (XML tag with +1 value)

查看:15
本文介绍了访问“字符串数组"来自 tExtractXMLField(具有 +1 值的 XML 标记)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Talend Job 具有以下结构:

My Talend Job has the following structure:

  • tREST 组件执行 POST HTTP 请求并接收 XML 文件.

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

tExtractXMLField 组件,从该 XML 文件中读取标签,例如:

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

现在,我想保存 tagX 中的所有值,然后访问它们.对于 tagX 的每个值,我将在正文中使用该值执行 HTTP POST.我该怎么做?

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?

谢谢

推荐答案

您需要一个名为 tHttpRequest 的组件.但是这个组件不允许连接到行流.但是有办法实现.

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.

假设您提取了您的 tagX 字段并将值放在一个名为tagX"的字符串字段上,您将其提供给传出连接.然后,您需要组件tFlowToIterate"将行连接转换为迭代连接.将迭代连接视为一种不包含数据的信号;它在每次传入迭代时触发.下面的这个子作业为从 tExtractXMLField 传入的每一行调用 tJava 代码(反过来在控制台上打印hello world"):

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:

现在魔法.在 tFlowToIterate 的参数中,您可以定义一个或多个全局变量,这些变量由传入连接的字段提供.上面的示例将全局变量 foo 设置为连接 row2 的字段 customer 的值:

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:

现在可以使用 (String)globalMap.get("foo") 在您的 Talend 作业中随处访问此变量.请注意转换为正确的类型,因为 globalMap 是一个仅限对象的集合.

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.

要参数化您的 HTTP 后调用,您只需要一个带有您刚刚设置的变量的 tHttpRequest 组件:

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

现在由您来处理 tHttpRequest 输出(包含整个响应的单个大字符串字段).请记住,输入中的行在转换为 Iterate 信号时会丢失其数据(您保存到 globalMap 中的字段在技术上不再属于流),但总数不变.因此,假设您有 4 个传入的行,您将触发 Iterate 信号 4 次,导致所涉及的 globalMap 变量被刷新,并且 tHttpRequest 组件自动发出 4 个(参数化的)http 请求.

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.

这篇关于访问“字符串数组"来自 tExtractXMLField(具有 +1 值的 XML 标记)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆