0

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?

mklement0
  • 382,024
  • 64
  • 607
  • 775
Thufir
  • 8,216
  • 28
  • 125
  • 273
  • 1
    How about using something from the [BaseX JSON_MODULE](http://docs.basex.org/wiki/JSON_Module). – rickhg12hs Feb 02 '20 at 08:20
  • 1
    ... like as shown at http://docs.basex.org/wiki/Twitter – rickhg12hs Feb 02 '20 at 08:27
  • must be blind, @rickhg12hs, but I'm not seeing how to use that module from Java? Perhaps I'm not understanding your meaning. – Thufir Feb 02 '20 at 21:05
  • 1
    Ahhh, I didn't realize you wanted to do this from Java. I'm not familiar with using BaseX from Java, but I have found the developers to be shockingly responsive and helpful. Really, they respond to just about everyone and incrementally improve BaseX continuously. If you don't receive a good response here, seriously consider posting your issue to the [BaseX talk maillist](https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk). – rickhg12hs Feb 03 '20 at 03:41

0 Answers0