简体   繁体   English

Dataweave:打开和关闭标签命名空间

[英]Dataweave: Opening and Closing Tags Namespace

I have a namespace on my DataWeave map.我的 DataWeave map 上有一个命名空间。 I would like the namespace attribute on the opening tag but not as an attribute on the closing tag.我想要开始标签上的命名空间属性,而不是结束标签上的属性。

{ 'trace xsi:type="trace"':

Closing XML Tag to should be关闭 XML 标签应该是

</trace>

But currently getting但目前得到

</trace xsi:type="trace">

Please provide a more complete example of your data-weave.请提供更完整的数据编织示例。 I'm going to assume you're doing something like this:我假设你正在做这样的事情:

%dw 2.0
output application/xml
---
{ 
    'trace xsi:type="trace"': {
        'somethingElse': null
    }
}

Which produces:产生:

<?xml version='1.0' encoding='UTF-8'?>
<trace xsi:type="trace">
  <somethingElse/>
</trace xsi:type="trace">

It is doing this because you've told data-weave the entire string ( 'trace xsi:type="trace"' ) consisting of your key, namespace, and attribute key/value are all one string, representing the key.这样做是因为您告诉 data-weave 包含您的键、命名空间和属性键/值的整个字符串 ( 'trace xsi:type="trace"' ) 都是一个字符串,代表键。 It doesn't know that that is an attribute key/value with a namespace because you've hardcoded it.它不知道这是具有命名空间的属性键/值,因为您已经对其进行了硬编码。

Here is how you SHOULD be doing this (see docs: https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-insert-attribute and https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-include-xml-namespaces )这是您应该如何执行此操作(请参阅文档: https://docs.mulesoft.com/mule-runtime/4.3/dataweave-cookbook-insert-attributehttps://docs.mulesoft.com/mule-runtime 4.3/dataweave-cookbook-include-xml-namespaces )

%dw 2.0
output application/xml
ns xsi http://www.w3.org/2001/XMLSchema-instance
---
{
    trace @(xsi#'type': 'trace'): {
        'somethingElse': null
    }
}

Which produces:产生:

<?xml version='1.0' encoding='UTF-8'?>
<trace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="trace">
  <somethingElse/>
</trace>

Don't manually put in your namespaces and attributes, let data-weave handle it by using the appropriate data structure.不要手动放入命名空间和属性,让 data-weave 使用适当的数据结构来处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM