我从ws:consumer和mulexml: XML -to-dom-transformer获得了转义的XML结果,我不知道如何通过mule组件来解压缩它,或者可能是我做错了什么?以下是相关流程:
<ws:consumer config-ref="Web_Service_Consumer" operation="Login" doc:name="Web Service Consumer"/>
<mulexml:xml-to-dom-transformer doc:name="XML to DOM" returnClass="java.lang.String"/>
和我的结果:
........<?xml version="1.0" encoding="UTF-8"?><LoginResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ..........
我该怎么办?
我使用mule anypoint studio 6.1.2
更新:基于https://docs.mulesoft.com/mule-user-guide/v/3.6/web-service-consumer我在ws:consumer
之前和之后使用dw:transform-message
,并使用DataSense
映射输入和输出结果
<dw:transform-message metadata:id="92383237-87b0-42ed-b794-b8f247cc3af5" doc:name="Transform Message">
<dw:input-payload mimeType="application/csv"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://tempuri.org/
---
{
ns0#Login: {
ns0#Username: payload.Username,
ns0#Password: payload.pass
}
}]]></dw:set-payload>
</dw:transform-message>
<ws:consumer config-ref="Web_Service_Consumer" operation="Login" doc:name="Web Service Consumer"/>
<dw:transform-message metadata:id="39ba326e-a6f4-4e3f-8de9-b42ddc0f19b2" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 http://tempuri.org/
%namespace ns1 http://www.w3.org/2001/XMLSchema
%namespace ns2 http://www.w3.org/XML/1998/namespace
---
{
ns0#LoginResponse: {
ns0#LoginResult: {
ns1#schema @(targetNamespace: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@targetNamespace , version: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@version , finalDefault: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@finalDefault , blockDefault: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@blockDefault , attributeFormDefault: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@attributeFormDefault ,
elementFormDefault: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@elementFormDefault , id: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@id , lang: payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.@ns2#lang): {
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#notation map ((notation , indexOfNotation) -> {
ns1#notation: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#attribute map ((attribute , indexOfAttribute) -> {
ns1#attribute: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#element map ((element , indexOfElement) -> {
ns1#element: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#attributeGroup map ((attributeGroup , indexOfAttributeGroup) -> {
ns1#attributeGroup: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#group map ((group , indexOfGroup) -> {
ns1#group: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#complexType map ((complexType , indexOfComplexType) -> {
ns1#complexType: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#simpleType map ((simpleType , indexOfSimpleType) -> {
ns1#simpleType: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#annotation map ((annotation , indexOfAnnotation) -> {
ns1#annotation: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#redefine map ((redefine , indexOfRedefine) -> {
ns1#redefine: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#import map ((import , indexOfImport) -> {
ns1#import: {
}
})),
(payload.ns0#LoginResponse.ns0#LoginResult.ns1#schema.*ns1#include map ((include , indexOfInclude) -> {
ns1#include @(id: include.@id , schemaLocation: include.@schemaLocation): {
ns1#annotation: include.ns1#annotation
}
}))
}
}
}
}]]></dw:set-payload>
</dw:transform-message>
但是这个错误发生了:
Root Exception stack trace:
javax.xml.stream.XMLStreamException: Trying to bind URI http://www.w3.org/XML/1998/namespace to prefix "{0}" (can only bind to xml)
根据我的理解,转换webservice结果是基于您的需求,而不是必需的步骤。消费者之后你真的需要变压器吗?尝试在消费者之后移除变压器并查看修复问题。也试着在用户使用和不使用变压器后进行调试,并验证结果。对于xml转义字符问题,我在骡子交换(https://www.mulesoft.com/exchange#!/global-global-weather-wsdl?types=WSDL)上尝试了SOAP web服务,并得到了与转义字符相似的结果,但原因是,web服务响应(但您的结果看起来不同,即使您的结果在xml声明中也有转义字符)来自具有转义字符的数据库,可能骡子不是原因。我在webservicex.net (http://webservicex.net/New/Home/ServiceDetail/23)上尝试了不同的服务,它工作得很好,没有任何问题。