Mule DataWeave 转换消息因缺少 metadata:id 属性而失败
Mule DataWeave transform-message failing with missing metadata:id attribute
我有一个非常简单的 hashmap 负载正在转换为 application/json。我在其他流程中通过将数据编织组件拖入并编写映射表达式来完成此操作。
现在由于某种原因,我收到以下错误:
The prefix "metadata" for attribute "metadata:id" associated with an element type "dw:transform-message" is not bound.
当我查看 xml 时,我发现我的新数据编织组件没有 metadata:id 属性,但我使用的另一个数据编织组件确实有 metadata:id 属性.
- 为什么它们的行为不同?
- 为什么 metadata:id 不像其他流程那样自动生成?
- 为什么首先需要 metadata:id 属性?在这两种情况下,我都在调用映射器之前使用 JSON to Object 组件。
我认为包含 metadata
属性是为了指向一个资源,您在其中为示例文件后面的 DataWeave 输入 and/or 输出结构定义了一些元数据。您在上面详述的错误看起来像是模式验证,请检查您在 XML 配置中的开始 mule
标记中是否包含以下内容:
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
希望对您有所帮助!
使用DataWeave组件时,需要声明xml个命名空间。如果您使用的是 Studio 设计器,那么只要您将组件拖放到配置中,Studio 就会添加相关的命名空间。
因此,当您拖放 dataweave 组件时,studio 会将以下命名空间和架构位置添加到配置中 -
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
在 Mule 中,您可以为每个组件定义元数据,这有助于在设计时查看数据结构。所有这些元数据定义都存储在 {project_home}\catalog
文件夹下,文件名类似于 UUID
。然后将这些文件名添加到具有 metadata:id
属性的组件定义中。即使只有一个组件,您也需要元数据命名空间(不必 DW,因为元数据是所有组件共有的功能)。
<dw:transform-message metadata:id="262e6569-8f38-4e0b-a61d-15550870101e" doc:name="Transform Message">
如果您从 Studio 设计器添加元数据,Studio 应该会自动添加以下命名空间和架构位置。如果您手动添加它或从一个 xml 复制粘贴到另一个没有它的地方,那么您需要自己添加它 -
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"
使用 Dataweave 和元数据的示例配置如下所示 -
<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
我有一个非常简单的 hashmap 负载正在转换为 application/json。我在其他流程中通过将数据编织组件拖入并编写映射表达式来完成此操作。
现在由于某种原因,我收到以下错误:
The prefix "metadata" for attribute "metadata:id" associated with an element type "dw:transform-message" is not bound.
当我查看 xml 时,我发现我的新数据编织组件没有 metadata:id 属性,但我使用的另一个数据编织组件确实有 metadata:id 属性.
- 为什么它们的行为不同?
- 为什么 metadata:id 不像其他流程那样自动生成?
- 为什么首先需要 metadata:id 属性?在这两种情况下,我都在调用映射器之前使用 JSON to Object 组件。
我认为包含 metadata
属性是为了指向一个资源,您在其中为示例文件后面的 DataWeave 输入 and/or 输出结构定义了一些元数据。您在上面详述的错误看起来像是模式验证,请检查您在 XML 配置中的开始 mule
标记中是否包含以下内容:
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
希望对您有所帮助!
使用DataWeave组件时,需要声明xml个命名空间。如果您使用的是 Studio 设计器,那么只要您将组件拖放到配置中,Studio 就会添加相关的命名空间。
因此,当您拖放 dataweave 组件时,studio 会将以下命名空间和架构位置添加到配置中 -
xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
在 Mule 中,您可以为每个组件定义元数据,这有助于在设计时查看数据结构。所有这些元数据定义都存储在 {project_home}\catalog
文件夹下,文件名类似于 UUID
。然后将这些文件名添加到具有 metadata:id
属性的组件定义中。即使只有一个组件,您也需要元数据命名空间(不必 DW,因为元数据是所有组件共有的功能)。
<dw:transform-message metadata:id="262e6569-8f38-4e0b-a61d-15550870101e" doc:name="Transform Message">
如果您从 Studio 设计器添加元数据,Studio 应该会自动添加以下命名空间和架构位置。如果您手动添加它或从一个 xml 复制粘贴到另一个没有它的地方,那么您需要自己添加它 -
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"
使用 Dataweave 和元数据的示例配置如下所示 -
<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">