问题描述
我在m子中的名称空间有问题。假设我有一个下面的xml,它在通过转换消息组件之后,名称空间从父标记更改为子标记。如果我的消息必须保持原样,该怎么办
Input:
```
**<root>
<abc xmlns:xsi="http://www.w3.org/.." xsi:type="q1:asdf" xmlns:q1="http://www.asd.com/asd/length" >
<q1:key>aaa</q1:key>
</abc>
</root>
```
Output:
```
<root>
<abc xsi:type="q1:asdf" >
<q1:key xmlns:q1="http://www.asd.com/asd/length">aaa</q1:key>
</abc>
</root>**
```
Here in `<abc xsi:type="q1:asdf">` the q1 namespace declaration moved to child tag key. For which I am getting error? can you please help how to retain the message as it is. And one more thing there is no guarantee that i get the same input message always,it changes dynamically. Only for this input I am getting issue.
解决方法
使用DataWeave语言实现的Transform Message组件在第一次使用元素时输出名称空间定义。这完全符合标准,并且不会对任何标准解析器造成任何问题。如果要在父元素中发出名称空间,则必须创建一个在该元素中使用它的伪属性(即@(q1#dummy: '')
)。
我不确定xsi:type="q1:asdf"
是否实际上需要在相同使用级别下使用该定义。
如果在处理该输出时遇到错误,则可以。如果由于某个其他应用程序需要父级名称空间而发生错误,则该应用程序的XML解析器似乎是一个错误。唯一可能是错误的情况是xsi:type
因为缺少名称空间而导致了某些错误。