Json to XML工具? [英] Json to XML tool?

查看:57
本文介绍了Json to XML工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个json文件,但是我使用的应用程序仅从xml文件中导入数据.那么,有人知道将json文件转换为xml的工具吗?我一直在寻找这样的工具几个小时,只能找到从xml创建json文件的工具.

I have one json file but an application that I use imports data only from xml files. So does somebody know of a tool that converts json files to xml? I've been looking for such tool for a few hours and could only find tools that create json files from xml.

谢谢!

推荐答案

纯XSLT 2.0实现:

看看 f:json-document() "rel =" nofollow> FXSL 2. x库 .

Have a look at the f:json-document() from the FXSL 2.x library.

使用此功能非常容易合并JSon并将其用作XML.

Using this function it is extremely easy to incorporate JSon and use it just as... XML.

例如,一个人可以编写以下XPath表达式:

For example, one can just write the following XPath expression:

f:json-document($vstrParam)/Students/*[sex = 'Female']

使用sex = 'Female'

and get all children of Students with sex = 'Female'

以下是完整的示例:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:f="http://fxsl.sf.net/"
 exclude-result-prefixes="f xs"
 >
 <xsl:import href="../f/func-json-document.xsl"/>

 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:variable name="vstrParam" as="xs:string">
{

  "teacher":{
    "name":
      "Mr Borat",
    "age":
      "35",
    "Nationality":
      "Kazakhstan"
             },


  "Class":{
    "Semester":
      "Summer",
    "Room":
      null,
    "Subject":
      "Politics",
    "Notes":
      "We're happy, you happy?"
           },

  "Students":
    {
      "Smith":
        {"First Name":"Mary","sex":"Female"},
      "Brown":
        {"First Name":"John","sex":"Male"},
      "Jackson":
        {"First Name":"Jackie","sex":"Female"}
    }
    ,


  "Grades":

    {
      "Test":
      [
        {"grade":"A","points":68,"grade":"B","points":25,"grade":"C","points":15},

        {"grade":"C","points":2, "grade":"B","points":29, "grade":"A","points":55},

        {"grade":"C","points":2, "grade":"A","points":72, "grade":"A","points":65}
       ]
    }


}
 </xsl:variable>

 <xsl:template match="/">
    <xsl:sequence select=
     "f:json-document($vstrParam)/Students/*[sex = 'Female']"/>

 </xsl:template>
</xsl:stylesheet>

将上述转换应用于任何XML文档(忽略)时,会产生正确的结果:

<Smith>
   <First_Name>Mary</First_Name>
   <sex>Female</sex>
</Smith>
<Jackson>
   <First_Name>Jackie</First_Name>
   <sex>Female</sex>
</Jackson>

这篇关于Json to XML工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆