2016-09-27 34 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