首页 > 解决方案 > 如何将 JSON 解析或读入 BaseX 的 XML 文档?

问题描述

这个单线实现了从topowershell转换的目的,尽管格式可能不同:JSONTwitterXML

$tweets = Get-Content 'tweets.json' | Out-String | ConvertFrom-Json | Export-Clixml "./tweets.xml"

此外,使用以下文件从文件创建文档当然很容易XMLJSONorg.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));
    }
}

但是如何使用API创建XML文档?虽然听起来可行,但它究竟是如何实现的?BaseX

标签: javajsonxmlbasex

解决方案


推荐阅读