How to convert JSON to XML in Orbeon?

余生颓废 提交于 2019-12-24 06:37:29

问题


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>

回答1:


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

converter:jsonStringToXml(instance('json'))

Here is a full example:

<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>

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



来源:https://stackoverflow.com/questions/39735209/how-to-convert-json-to-xml-in-orbeon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!