Add command: name of the input will be set as path?

Monday, 3 February 2020 · 5 messages · last reply 4 Feb 2020
T
thufir3 Feb 2020 10:56 #
What does it mean that "if null, the name of input will be set as the path"? Javadoc: Add public Add(java.lang.String path, java.lang.String input) Constructor, specifying a target path and an input. Parameters: path - target path, optionally terminated by a new file name. If null, the name of the input will be set as path. input - input file or XML string I'm looking to add an xml file, so am using "null" for the path: https://stackoverflow.com/q/60035605/262852 but what are the implications? the "name of the input" will be "set as path"? Where is the "name of the input"? What is "path" in relation to a String which exists only in memory? Just pass a string like: new Add(null, stringXml).execute(context); and that should add to the currently open database? thanks, Thufir
CG
Christian Grün3 Feb 2020 15:46 #
Quoted text · thufir · 1 line
> What does it mean that "if null, the name of input will be set as the path"?
If your path argument points to a directory or a single file, and if you specify no argument for the input variable, the filenames resulting from your first argument will be adopted as database paths. If you run the command "ADD myfile.xml", the input argument will be null. If you run "ADD TO /db/path myfile.xml", input will be "/db/path".
CG
Christian Grünin reply to thufir, 3 Feb 2020, 23:163 Feb 2020 22:42 #
Quoted text · thufir · 1 line
> In this case there's no path argument, but there is an input argument of
stringXml. Is that how to pass a String to Add()? There are various ways; one is as follows:
    String json = "{ \"A\": 123 }";
    Context ctx = new Context();
    new CreateDB("test").execute(ctx);
    new Set("parser", "json").execute(ctx);
    Command add = new Add("json.xml");
    add.setInput(new ArrayInput(json));
    add.execute(ctx);
    System.out.println(new XQuery(".").execute(ctx));
Quoted text · thufir · 31 lines
On Mon, Feb 3, 2020 at 10:16 PM thufir <hawat.thufir at gmail.com> wrote: > > > > On 2020-02-03 6:46 a.m., Christian Grün wrote: > >> What does it mean that "if null, the name of input will be set as the path"? > > > > If your path argument points to a directory or a single file, and if > > you specify no argument for the input variable, the filenames > > resulting from your first argument will be adopted as database paths. > > > > If you run the command "ADD myfile.xml", the input argument will be > > null. If you run "ADD TO /db/path myfile.xml", input will be > > "/db/path". > > > > > Right, but I'm not looking to run the command "ADD myfile.xml" from the > console but rather: > > > new Add(null, stringXml).execute(context); > > In this case there's no path argument, but there is an input argument of > stringXml. Is that how to pass a String to Add()? > > > > thanks, > > Thufir
T
thufirin reply to Christian Grün, 3 Feb 2020, 15:463 Feb 2020 23:16 #
Quoted text · Christian Grün · 11 lines
On 2020-02-03 6:46 a.m., Christian Grün wrote: >> What does it mean that "if null, the name of input will be set as the path"? > > If your path argument points to a directory or a single file, and if > you specify no argument for the input variable, the filenames > resulting from your first argument will be adopted as database paths. > > If you run the command "ADD myfile.xml", the input argument will be > null. If you run "ADD TO /db/path myfile.xml", input will be > "/db/path". >
Right, but I'm not looking to run the command "ADD myfile.xml" from the console but rather: new Add(null, stringXml).execute(context); In this case there's no path argument, but there is an input argument of stringXml. Is that how to pass a String to Add()? thanks, Thufir
T
thufirin reply to Christian Grün, 3 Feb 2020, 22:424 Feb 2020 00:00 #
I got it to work in a very kludgy way:
         new Open(databaseName).execute(context);
         for (int i = 0; i < tweets.length(); i++) {
             jsonStringTweet = tweets.get(i).toString();
             jsonObjectTweet = new org.json.JSONObject(jsonStringTweet);
             stringXml = XML.toString(jsonObjectTweet);
             stringXml = wrap(stringXml);
             write(stringXml,fileName);
             String stringFromFile = read(fileName);
             log.fine(stringFromFile);
             new Add(fileName, stringXml).execute(context);
         }
     }
buth there I'm passing the fileName -- certainly I can just pass stringXml by itself somehow? see also: https://stackoverflow.com/a/60047738/262852 thanks, Thufir
Quoted text · Christian Grün · 49 lines
On 2020-02-03 1:42 p.m., Christian Grün wrote: >> In this case there's no path argument, but there is an input argument of > stringXml. Is that how to pass a String to Add()? > > There are various ways; one is as follows: > > String json = "{ \"A\": 123 }"; > Context ctx = new Context(); > new CreateDB("test").execute(ctx); > new Set("parser", "json").execute(ctx); > Command add = new Add("json.xml"); > add.setInput(new ArrayInput(json)); > add.execute(ctx); > System.out.println(new XQuery(".").execute(ctx)); > > > > > On Mon, Feb 3, 2020 at 10:16 PM thufir <hawat.thufir at gmail.com> wrote: >> >> >> >> On 2020-02-03 6:46 a.m., Christian Grün wrote: >>>> What does it mean that "if null, the name of input will be set as the path"? >>> >>> If your path argument points to a directory or a single file, and if >>> you specify no argument for the input variable, the filenames >>> resulting from your first argument will be adopted as database paths. >>> >>> If you run the command "ADD myfile.xml", the input argument will be >>> null. If you run "ADD TO /db/path myfile.xml", input will be >>> "/db/path". >>> >> >> >> Right, but I'm not looking to run the command "ADD myfile.xml" from the >> console but rather: >> >> >> new Add(null, stringXml).execute(context); >> >> In this case there's no path argument, but there is an input argument of >> stringXml. Is that how to pass a String to Add()? >> >> >> >> thanks, >> >> Thufir

⚡Generated with XQuery