Read an XQuery file, substitute a filename for a symbol and save in a string

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
 
C

Chris

Jeff Kish said:
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.

<snip>

If all you're looking for is search and replace functionality, the
String.replaceAll() method will do the trick.
 
J

Jeff Kish

containing a query for the XQuery
guarantee), a place holder that I'd
processing the XQuery with each

<snip>

If all you're looking for is search and replace functionality, the
String.replaceAll() method will do the trick.
Thanks. This will give the app the ability to just replace the first occurrence? Perfect.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top