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