【问题标题】:How i can convert json into xml without the elements index numbers?我如何在没有元素索引号的情况下将 json 转换为 xml?
【发布时间】:2020-05-28 17:44:41
【问题描述】:

我正在尝试实现以下允许我将 json 转换为 xml 的代码。但我不想以元素索引的形式获得输出,例如从 开始,结束标记作为类似的第二个节点,从 开始,以 .我有大 xml 大 json 代码,这就是它创建索引标签(例如 等)的原因。我想在没有这些索引标签的情况下显示我的 xml。代码如下:-

function convertJSon2XML() 
{
$("#xmlArea").val(x2js.json2xml_str($.parseJSON($("#jsonArea").val())));
}

$("#xmlArea").val("<root><child><textNode>First &amp; Child</textNode></child><child><textNode>Second 
Child</textNode></child><testAttrs attr1='attr1Value'/></root>");

convertJSon2XML();

$("#convertToXmlBtn").click(convertJSon2XML);

作为参考,我还附上了索引标签所指的输出。一开始就有标签 ,这样下去。例如 然后 等等。因此,由于 等这些索引标签,我无法在浏览器中读取我的 xml。我想将 json 转换为 xml 没有这些索引标签,例如 等等。请帮忙。

输出:-

【问题讨论】:

    标签: javascript json xml browser xml-parsing


    【解决方案1】:

    它可能会被转换成这个 JSON。

    {
      "root": {
        "child": [
          {
            "textNode": "First & Child"
          }, 
          {
           "textNode": "Second \nChild"
          }
        ], 
        "testAttrs": {
          "-attr1": "attr1Value", 
          "-self-closing": "true"
        }
      }, 
      "#omit-xml-declaration": "yes"
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-01
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 2019-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多