How to parse or read JSON into an XML document for BaseX?

只谈情不闲聊 提交于 2020-03-05 00:34:47

问题


This one-liner in powershell achieves the purpose of converting JSON from Twitter to XML, albeit probably formatted differently:

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

Also, certainly it's easy enough to create an XML document from a JSON file using org.json below:

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));
    }
}

but how can I create an XML document using the BaseX API? While it sounds doable, how, exactly, is it accomplished?

来源:https://stackoverflow.com/questions/60022419/how-to-parse-or-read-json-into-an-xml-document-for-basex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!