如何在 Orbeon 中将 JSON 转换为 XML?
How to convert JSON to XML in Orbeon?
在 JSON 支持下,我可以调用 Web 服务。 Orbeon 将在内部将 JSON 更改为 XML。问题是,在 XML 中,有一个包含 JSON 字符串的节点元素。如何将其转换为 XML 并为其分配一个变量(以便我可以使用 XPath 进行进一步查询)?有没有Orbeon转换器可以调用?
提交到网络服务后的实例数据示例:
<json type="object">
<data>
{ "name": "Mark", "age": 21 }
</data>
</json>
虽然这没有记录,并且可能会更改,但您可以使用 XPath 中的本机 Scala 函数:
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 中,我们 plan to include XPath 函数可以做到这一点。
在 JSON 支持下,我可以调用 Web 服务。 Orbeon 将在内部将 JSON 更改为 XML。问题是,在 XML 中,有一个包含 JSON 字符串的节点元素。如何将其转换为 XML 并为其分配一个变量(以便我可以使用 XPath 进行进一步查询)?有没有Orbeon转换器可以调用?
提交到网络服务后的实例数据示例:
<json type="object">
<data>
{ "name": "Mark", "age": 21 }
</data>
</json>
虽然这没有记录,并且可能会更改,但您可以使用 XPath 中的本机 Scala 函数:
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 中,我们 plan to include XPath 函数可以做到这一点。