【问题标题】:COnvert xml to json using command line or using shell script使用命令行或使用 shell 脚本将 xml 转换为 json
【发布时间】:2020-05-07 20:12:25
【问题描述】:
<?xml version="1.0" encoding="utf-8"??>
<resources>
  <data id="V701">
    <string name="MSG_V701_ID">V701</string>
    <string name="MSG_V701_TITLE">abc</string>
    <string name="MSG_V701_BODY">This title is currently unable</string>
  </data>
  <data id="V702">
    <string name="MSG_V702_ID">V702</string>
    <string name="MSG_V702_TITLE">Play</string>
    <string name="MSG_V702_BODY">This title is currently unable to play</string>
  </data>
</resources>

如何在 ubuntu 或 shell 脚本中使用该命令行来执行此操作

【问题讨论】:

    标签: json xml shell xml-parsing sh


    【解决方案1】:

    没有本地 Bash 工具可以做到这一点。所以你必须使用像这样的专用工具。

    你没有解释你想要 JSON 的样子,所以是这样的......

    xidel -s input.xml -e '{|//data/{@* :{|string/{@* :text()}|}}|}'
    {
      "V701": {
        "MSG_V701_ID": "V701",
        "MSG_V701_TITLE": "abc",
        "MSG_V701_BODY": "This title is currently unable"
      },
      "V702": {
        "MSG_V702_ID": "V702",
        "MSG_V702_TITLE": "Play",
        "MSG_V702_BODY": "This title is currently unable to play"
      }
    }
    

    ...您在寻找什么?

    【讨论】:

      猜你喜欢
      • 2021-11-14
      • 2011-09-04
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-14
      相关资源
      最近更新 更多