我有一个 SOAP 网络服务,它将 XML 作为输入并发送 XML 作为响应.现在我有一个与 XML 请求相同的 JSON 对象.如何将 JSON 对象转换为 XML,以便将 XML 请求发送到我的 SOAP Web 服务.我有 WSDL 文件.换句话说,我想在 SOAP 之上提供一个额外的 REST 层
I Have a SOAP web services which takes XML as input and send XML as response. Now I have a JSON object which is the same as XML request. How can I convert JSON Object to XML so that I can send the XML request to my SOAP web service. I have the WSDL file. In other terms, I wanted to provide a extra layer of REST on top of SOAP
推荐答案JSON 对象永远不能与 XML 文档相同",因为数据模型不同.它可能包含相同的信息,但问题是没有从 JSON 到 XML 的明确映射可以保证生成您所追求的 XML 表示.
A JSON object can never be "the same as" an XML document, because the data models are different. It may hold the same information, but the problem is that there is no definitive mapping from JSON to XML that is guaranteed to produce the XML representation that you are after.
有许多库可以将 JSON 转换为 XML:试一试,但您可能需要调整"XML 以使其成为所需的形式.当然,这总是可以使用 XSLT 来完成.
There are a number of libraries available that do JSON to XML conversion: give them a try, but you will probably have to "tweak" the XML to get it into the required form. That can always be done using XSLT, of course.
如果您使用 XSLT 3.0,那么您可以在一个步骤中完成 JSON 到 XML 的转换和后续处理(调整").
If you use XSLT 3.0 then you can do the JSON to XML conversion and subsequent processing ("tweaking") in a single step.
更多推荐
使用 WSDL 将 JSON 转换为 XML 请求
发布评论