如何在 Orbeon 中将 JSON 转换为 XML? [英] How to convert JSON to XML in Orbeon?

查看:65
本文介绍了如何在 Orbeon 中将 JSON 转换为 XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助 JSON 支持,我可以调用 Web 服务.Orbeon 将在内部将 JSON 更改为 XML.问题是,在 XML 内部,有一个包含 JSON 字符串的节点元素.如何将其转换为 XML 并为其分配一个变量(以便我可以使用 XPath 进行进一步查询)?有可以调用的Orbeon转换器吗?

With JSON support, I'm able to call a web service. Orbeon will internally change the JSON to XML. Question is, inside the XML, there is a node element that contains JSON string. How do I convert that into XML and assign it an variable(so I can use XPath for further query)? Is there any Orbeon converter that can be called?

提交到网络服务后的实例数据示例:

Example of instance data after submission to the web service:

<json type="object"> 
   <data>
   { "name": "Mark", "age": 21 }
   </data>
 </json>

推荐答案

虽然这没有记录在案,并且可能会发生变化,但您可以使用来自 XPath 的原生 Scala 函数:

Although this is not documented, and is subject to change, you could use the native Scala function from XPath:

converter:jsonStringToXml(instance('json'))

这是一个完整的例子:

<xh:html
    xmlns:xh="http://www.w3.org/1999/xhtml"
    xmlns:xf="http://www.w3.org/2002/xforms"
    xmlns:xxf="http://orbeon.org/oxf/xml/xforms">
    <xh:head>
        <xf:model>
            <xf:instance id="json">
                <json type="object">
                   <data>{ "name": "Mark", "age": 21 }</data>
                 </json>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>
        <xf:output
            xmlns:converter="org.orbeon.oxf.json.Converter"
            value="
                xxf:serialize(
                    converter:jsonStringToXml(instance('json')/data),
                    'xml'
                )"/>
    </xh:body>
</xh:html>

在 Orbeon Forms 2016.3 中,我们计划包括 XPath 函数来执行此操作.

In Orbeon Forms 2016.3, we plan to include XPath functions to do this.

这篇关于如何在 Orbeon 中将 JSON 转换为 XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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