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

Discussion in 'Java' started by Jeff Kish, Nov 15, 2004.

  1. Jeff Kish

    Jeff Kish Guest

    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
    Jeff Kish, Nov 15, 2004
    #1
    1. Advertising

  2. Jeff Kish

    Chris Guest

    "Jeff Kish" <> wrote in message
    news:...
    > 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.
    Chris, Nov 15, 2004
    #2
    1. Advertising

  3. Jeff Kish

    Jeff Kish Guest

    On Sun, 14 Nov 2004 23:38:07 -0600, "Chris" <> wrote:

    >"Jeff Kish" <> wrote in message
    >news:...
    >> 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.
    >

    Thanks. This will give the app the ability to just replace the first occurrence? Perfect.
    Jeff Kish, Nov 15, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Otten
    Replies:
    0
    Views:
    417
    Peter Otten
    Nov 30, 2010
  2. Peter Otten
    Replies:
    10
    Views:
    865
    Nobody
    Dec 2, 2010
  3. Dan Stromberg
    Replies:
    0
    Views:
    924
    Dan Stromberg
    Dec 6, 2010
  4. Madu Nar
    Replies:
    2
    Views:
    106
    Madu Nar
    Sep 11, 2006
  5. Stefano Crocco
    Replies:
    0
    Views:
    146
    Stefano Crocco
    Nov 14, 2008
Loading...

Share This Page