2016-09-27 32 views
1

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

提交给Web服务后实例数据的实例:

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

因此,您收到本身包含JSON的JSON? – ebruchez

+0

是的,确切的;另外,我注意到ConverterTest中有Converter.jsonStringToXml方法。不知道如何从orbeon形式调用这个方法来解决我的问题? –

回答

1

虽然这是没有记录,并随时更改,你可以使用本地斯卡拉函数从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窗体2016.3,我们plan to include XPath函数执行此操作。

+0

很高兴知道它将在即将发布的版本中得到支持,谢谢! –

+1

2016.3中添加的功能文档:https://doc.orbeon.com/xforms/xpath/extension-json.html – awilkinson