java - 如何将 JSON 解析或读入 BaseX 的 XML 文档?
问题描述
这个单线实现了从topowershell
转换的目的,尽管格式可能不同:JSON
Twitter
XML
$tweets = Get-Content 'tweets.json' | Out-String | ConvertFrom-Json | Export-Clixml "./tweets.xml"
此外,使用以下文件从文件创建文档当然很容易:XML
JSON
org.json
package basex;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.logging.Logger;
import org.basex.core.MainOptions;
import org.basex.io.IOFile;
public class JsonToXmlTransformer {
private static final Logger log = Logger.getLogger(JsonToXmlTransformer.class.getName());
public JsonToXmlTransformer() {
}
private void baseXparseJsonFile(String fileName) throws IOException {
org.basex.build.json.JsonParser jsonParser = new org.basex.build.json.JsonParser(new IOFile(fileName), new MainOptions());
//where is the xml?
}
public void transform(String fileName) throws IOException {
String content = new String(Files.readAllBytes(Paths.get(fileName)), StandardCharsets.UTF_8);
org.json.JSONObject json = new org.json.JSONObject(content);
log.info(org.json.XML.toString(json));
}
}
解决方案
推荐阅读
- java - 在 Java 中寻找最短路径 - Dijkstra 算法
- microsoft-ajax-minifier - 从哪里获得 ajaxmin.exe?
- android - 在 Fragment 外部的类中调用 getViewById 会生成空指针异常和内容
- android - RecyclerView - 在用户开始滚动之前,有什么方法可以在屏幕上显示多少项目?
- neural-network - 我得到这个 keras 神经网络的 0% 准确率
- android - 无法使用 HttpURLConnection 和 OkHttp 跟踪上传进度
- uml - UML 状态机图:从复合状态触发退出
- php - 使用 php 群发邮件脚本发送附件
- scala - 将 Seq[Seq[String,String]] 转换为 Map[String,Seq[String]]
- sql - Impala SQL中的分区引发错误