简体   繁体   English

为相应的XML编写JSON

[英]Write JSON for corresponding XML

I want to write JSON code which can be converted in fix format kind of XML 我想编写可以以固定格式的XML格式转换的JSON代码

    <function>foo
      <return>uint32_t</return>
      <param>count
        <type>uint32_t</type>
      </param>
    </function>

I have tried multiple ways to develop a JSON which can be formatted like as in above but failed to get perfection because no separate key is required for foo and count which are orphan values otherwise. 我尝试了多种方法来开发可以像上面一样格式化的JSON,但是由于没有必要为foo和count分配单独的键(否则它们是孤立值),因此无法完美实现。

Tried ways: Way 1: 尝试的方式:方法1:

{
"function" : 
  {"foo":
    {"return":"uint32_t"},
    "param":
      {"count":
        {"type":"uint32_t"}
      }
     }
   }

Way 2: 方式2:

{
"function" : 
  ["foo",{"return":"uint32_t"}],
  "param":
    ["count",{"type":"uint32_t"}]
}

Way 3: But i do not need name tag :( 方式3:但是我不需要名称标签:(

{
"function": 
  {"name": "foo",
   "return": "uint32_t",
   "param": "count",
   "type": "uint32_t"
  }
}

For generating output and testing please use: JSON to XML convertor 为了生成输出和测试,请使用: JSON到XML转换器

Requesting your help.. I later have a script to convert the formatted excel to C header files. 请求您的帮助。. 后来我有了一个脚本,可以将格式化的excel转换为C头文件。

It is very rare for a JSON-to-XML conversion library to give you precise control over the XML that is generated, or conversely, for an XML-to-JSON converter to give you precise control over the JSON that is generated. 很少有JSON到XML转换库为您提供对所生成的XML的精确控制,或者相反,对于XML到JSON转换器则为您提供对所生成的JSON的精确控制。 It's basically not possible because the data models are very different. 基本上是不可能的,因为数据模型非常不同。

Typically you have to accept what the JSON-to-XML converter gives you, and then use XSLT to transform it into the flavour of XML that you actually want. 通常,您必须接受JSON-to-XML转换器提供的功能,然后使用XSLT将其转换为您实际想要的XML风格。

(Consider using the json-to-xml() conversion function in XSLT 3.0 and then applying template rules to the result.) (考虑在XSLT 3.0中使用json-to-xml()转换函数,然后将模板规则应用于结果。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM