Mule DataWeave转换消息失败,缺少元数据:id属性 [英] Mule DataWeave transform-message failing with missing metadata:id attribute

查看:90
本文介绍了Mule DataWeave转换消息失败,缺少元数据:id属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的哈希映射有效载荷,将其转换为application/json.在其他流程中,我只是通过拖动dataweave组件并编写映射表达式来做到这一点.

I have a very simple hashmap payload being converted to application/json. I have done this in other flows by just dragging the dataweave component in, and writing the mapping expression.

现在由于某种原因,出现以下错误:

now for some reason, I am getting the following error:

与元素类型"dw:transform-message"相关联的属性"metadata:id"的前缀"metadata"未绑定.

The prefix "metadata" for attribute "metadata:id" associated with an element type "dw:transform-message" is not bound.

当我查看xml时,我发现新的dataweave组件没有metadata:id属性,但是我使用的其他dataweave组件却具有metadata:id属性.

when I look at the xml, I see that my new dataweave component does not have a metadata:id attribute, but the other dataweave component i used does have a metadata:id attribute.

  1. 为什么这些人的行为有所不同?
  2. 为什么没有像其他流程那样自动生成metadata:id?
  3. 为什么我首先需要metadata:id属性?在这两种情况下,在调用映射器之前,我都使用JSON到Object组件.

推荐答案

使用DataWeave组件时,需要声明xml名称空间.如果您使用的是Studio设计器,那么只要将组件拖放到配置中,Studio就会添加相关的名称空间.

When you use DataWeave component, you need to declare xml namespaces. If you are using Studio designer, then Studio adds related namespaces as soon as you drag and drop components to your configuration.

因此,当您拖放dataweave组件时,studio会在配置中添加以下名称空间和架构位置-

So when you drag and drop dataweave component, studio would add below namespaces and schema location to config -

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).

In Mule, you can define MetaData for every component which would help to see data structure at design time. All these metadata definitions are stored under {project_home}\catalog folder with file names that looks like UUID. These file names are then added to your component definitions with metadata:id attribute. You need metadata namespace even if one component (doesnt have to DW as metadata is feature common to all components).

<dw:transform-message metadata:id="262e6569-8f38-4e0b-a61d-15550870101e" doc:name="Transform Message">

如果您从Studio设计器添加元数据,则Studio应该自动在名称空间和架构位置下方添加.如果您手动添加它或将它从一个xml复制粘贴到另一个不包含它的xml,那么您需要自己添加-

If you add metadata from Studio designer then Studio should automatically add below namespace and schema location. If you add it manually or copy-paste from one xml to another which doesn't have it then you would need to add it your self -

xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"

具有Dataweave和元数据的示例配置如下所示-

Example config with Dataweave and metadata can look like below -

<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">

这篇关于Mule DataWeave转换消息失败,缺少元数据:id属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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