Dataweave 中的输入变量

Input variables in Dataweave

我正在通读 Dataweave documentation 并且被下面的例子难住了。

文档说

Input directives allow you to make any number of input sources available in global variables, which can then be referenced in any part of the Transform’s body. To reference one of these, you can just call it by the name you defined in the directive.

接着下面的例子

%dw 1.0
%input in0
%output application/xml
---
payload

我的问题:

骡子会在哪些范围内寻找变量in0? Payload、Flow、Session 或其他什么,顺序是什么?

在这个例子中,in0用在哪里?它对这个例子有什么帮助?

为什么我需要一个输入变量? Dataweave 似乎允许 flowVars.hello.

我认为示例与正文不符。该示例应为:

%dw 1.0
%input in0
%output application/xml
---
in0

默认情况下,输入(无论您如何命名)都是有效负载。您可以只是显式的,也可以选择将有效负载定义为 header 中的输入指令,尽管这不是必需的。

%dw 1.0
%input payload application/xml
%output application/xml
---
{
  a: payload
}

文档中还有更好的示例:

CSV Input Directive When defining an input of type CSV, there are a few optional parameters you can add to the input directive to customize how the data will be parsed.

header: boolean that defines if the first line in the data contains headers

separatorChar: character that separates fields, ',' by default

quoteChar: character that defines quoted text, " " by default

escapeChar: character that escapes quotes, / by default

A CSV input directive with custom parameters set looks like this:

%input in0 application/csv header=true separatorChar=; When header=true you can then access the fields within the input anywhere by name. Ex: in0.userName.

When header=false you must access the fields by index, referencing first the entry and then the field, Ex: in0[107][2]

通常,您不需要使用 %input 指令声明任何内容。默认情况下,有效载荷、flowVars、inbound/outbound 属性、sessionVars 等在 dataweave 中可以像在 MEL 中一样访问。

MEL 与 Java 相同,您可以在 java 中编写任何内容进行调试 (System.out),您也可以在 MEL 中进行调试。

%dw 1.0
%output application/java
---
{
    GENDER: payload.gender,
    test:flowVars.test,
    testIp:inboundProperties.testIp,
    testOp:outboundProperties.testOp
}

查看此示例以了解多个输入 - Multiple Inputs