Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: read a file word by word

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default read a file word by word

    Hi all,
    I want read a xsl file and produce another xsl file with some tag replaced in it.I have tried with substring but it is not efficient that much,so i thought to read the file word by word.can anyone help me how to do it.i have given below the xsl
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0"
    xmlnssl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="mainpara">
    <html>
    <xsl:apply-templates/>
    </html>
    </xsl:template>

    <xsl:template match="epigraph">
    <div>
    <xsl:apply-templates/>
    </div>
    </xsl:template>

    <xsl:template match="para">
    <p>
    <xsl:apply-templates/>
    </p>
    </xsl:template>

    <xsl:template match="blockquote">
    <b>
    <xsl:apply-templates/>
    </b>
    </xsl:template></xsl:stylesheet>
    in this i need to replace a epigraph to html and html to epigraph and same like tat for other tags also.


  2. #2

    Default Re: read a file word by word

    You should read the entire file into a String and use the replace method for strings.
    String (Java Platform SE 6)
    Note that since you want to switch tags around you will need to create a temporary tag to change to and revert back

    ex: replace <b> with <i>
    //opening tags
    fileContents.replaceAll("<b>","<@@>");
    fileContents.replaceAll("<i>","<b>");
    fileContents.replaceAll("<@@>","<i>");
     
    //closing tags
    fileContents.replaceAll("</b>","<@@>");
    fileContents.replaceAll("</i>","</b>");
    fileContents.replaceAll("<@@>","</i>");
    Kenneth Walter
    Software Developer
    http://kennywalter.com

Similar Threads

  1. Unscrambler, trying to get the last word of a dictionary...
    By csharp100 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 1st, 2011, 03:44 AM
  2. Content in text file to MS Word file help!
    By ComputerSaysNo in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 27th, 2011, 11:39 AM
  3. Reading a text file word by word
    By dylanka in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 21st, 2011, 02:06 PM
  4. MS word file in Oracle
    By tandonpiyush in forum Java Servlet
    Replies: 2
    Last Post: July 28th, 2011, 07:41 AM
  5. Word Search Help
    By Tanner in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 3rd, 2011, 01:39 AM