J
Jeff Kish
Greetings
I'd like to be able to take a filename that represents a text file containing a query for the XQuery
language (that means it can have spaces, lt, gt signs, etc. but no binary data).
What I expect the file to contain is an XQUERY, and possibly (no guarantee), a place holder that I'd
like to replace with a set of fully qualified filenames in a loop, processing the XQuery with each
file I have in a String.
So for example, my program will have a parameter that specifies a fully qualified file xquery file
that looks like this:
{--
returns this data:
<theElement>include<theAttribute id="pageHeader">include</theAttribute></theElement>
--}
for $b in document("%1l")//presentation
for $a in $b//*
where $a[fn:lower-case(@* as xs:string)="pageHeader"]
return
<theElement> {name($a)}
<theAttributes>
{ $a/@*, name($a)}
</theAttributes> </theElement>
Another parameter for the program contains a wildcard that will result in a list of fully qualified
filenames.
And I have a nice little qexo app that will loop through the list of fully qualified filenames, and
for each file will:
put the data from the xquery into a string
substituting the first occurence (if any) of %1 with the current fully qualified filename
pass the resulting transformed string to the qexo object that will process the XQuery.
Can someone help me out with the best way to read in the file, and do the substitution?
I was thinking of FileReader object, and read line by line, but I'm not sure about the string
substitution.
Something like this which I picked up on the Internet (thank you for the tutorials
http://home.cogeco.ca/~ve3ll/jatutorc.htm ):
// Create streams
FileReader fr = new FileReader (args[0]);
BufferedReader br = new BufferedReader(fr); //wrap the basic object
String finalOutput = new String();
String buf; // the buffer
boolean bSubstituted = false;
while ((buf = br.readLine()) != null)
{
if (!bSubstituted)
{
if buf contains a '%1'
replace it with the filename
bSubstituted = true;
}
finalOutput = finalOutput + buf;
}
br.close(); bw.close();
Thanks
I'd like to be able to take a filename that represents a text file containing a query for the XQuery
language (that means it can have spaces, lt, gt signs, etc. but no binary data).
What I expect the file to contain is an XQUERY, and possibly (no guarantee), a place holder that I'd
like to replace with a set of fully qualified filenames in a loop, processing the XQuery with each
file I have in a String.
So for example, my program will have a parameter that specifies a fully qualified file xquery file
that looks like this:
{--
returns this data:
<theElement>include<theAttribute id="pageHeader">include</theAttribute></theElement>
--}
for $b in document("%1l")//presentation
for $a in $b//*
where $a[fn:lower-case(@* as xs:string)="pageHeader"]
return
<theElement> {name($a)}
<theAttributes>
{ $a/@*, name($a)}
</theAttributes> </theElement>
Another parameter for the program contains a wildcard that will result in a list of fully qualified
filenames.
And I have a nice little qexo app that will loop through the list of fully qualified filenames, and
for each file will:
put the data from the xquery into a string
substituting the first occurence (if any) of %1 with the current fully qualified filename
pass the resulting transformed string to the qexo object that will process the XQuery.
Can someone help me out with the best way to read in the file, and do the substitution?
I was thinking of FileReader object, and read line by line, but I'm not sure about the string
substitution.
Something like this which I picked up on the Internet (thank you for the tutorials
http://home.cogeco.ca/~ve3ll/jatutorc.htm ):
// Create streams
FileReader fr = new FileReader (args[0]);
BufferedReader br = new BufferedReader(fr); //wrap the basic object
String finalOutput = new String();
String buf; // the buffer
boolean bSubstituted = false;
while ((buf = br.readLine()) != null)
{
if (!bSubstituted)
{
if buf contains a '%1'
replace it with the filename
bSubstituted = true;
}
finalOutput = finalOutput + buf;
}
br.close(); bw.close();
Thanks