json - 使用命令行或使用 shell 脚本将 xml 转换为 json
问题描述
<?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 脚本中使用该命令行来执行此操作
解决方案
没有本地 Bash 工具可以做到这一点。所以你必须使用像xidel这样的专用工具。
你没有解释你希望 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"
}
}
...你在找什么?
推荐阅读
- node.js - npx create-strapi-app 找不到 package.json
- r - R Maply to unzip - 文件路径更改
- android - 如何从 GeoJSON 或 mapboxId 在 Mapbox Android 中突出显示 LineString(或多边形)
- linux - 如何使用 awk 命令在日志文件中添加“日期”作为列
- python - Python中的元素乘法相当于Matlab
- python - 使用列表定义的列名初始化 pandas 数据框
- javascript - 需要帮助修改代码以连接到 MongoDB Atlas 而不是 localhost
- entity-framework - EF Lambda 表达式如何访问多个表中的数据
- scala - scala项目中文件的编译顺序
- ruby-on-rails - Ruby on Rails 测试 - ActiveRecord::RecordNotUnique: PG::UniqueViolation: 错误:重复键值违反唯一约束“xxx_xxxx_xxxx_pkey”