Results 1 to 8 of 8
  1. #1
    Cylab is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default To read tags from file

    From file read the data : <a><c><d>e</d></d></a>

    Output: ERROR: Mismatching tags on line 1: <c> and </d>!

    Code is:

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.util.*;

    class Test6{

    public static void main(String[] args)throws Exception{

    Stack<Character> stack = new Stack<Character>();

    BufferedReader br = new BufferedReader(new FileReader("c://test//assignment//input7.txt"));
    String s;
    int counter=0;
    while((s=br.readLine())!=null){
    char temp[] = s.toCharArray();
    for(int i=0;i<temp.length;i++){
    if(Character.isLetter(temp[i])){
    ...................
    ......................
    .................
    }}
    }
    br.close();
    }
    }

    Could anyone kindly provide any solution for it?? Anything at all.
    Or algorithm for it. I think I tried my best, unfortunately still could not do it:(
    Pleaseeeeeeeeeeeeeeeeeeeeee!!!!!!!!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,331
    Rep Power
    25

    Default

    Sounds like you need to keep track of the state of the scan (perhaps by using booleans).
    When you find a begin marker, set a flag to remember it.
    Then if you find an end marker without having read a begin marker, that would be an error.
    When you find the end marker, turn off the begin marker.
    You'd probably need a stack to keep the state of the scan organized. The top of the stack would be the current begin marker. As the end was found, pop off the begin.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Is this thread a sequel to this one?

    kind regards,

    Jos

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Eranga View Post
    Seems discussing the same in two different threads.
    Yep and the OP should've warned the potential repliers that some silly requirement doesn't allow him/her to use a simple xml parser (e.g. a SAXParser).

    kind regards,

    Jos

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I've remember that same user ask another related question to this. Have to check in my subscriptions.

  7. #7
    Cylab is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    Yeah, I keep asking same kind of question since no right solution has been found yet.
    Can anyone give a piece of code illustrate it. No need to have perfect answer, just need sth to push me to explore further. Thanks

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Cylab View Post
    Yeah, I keep asking same kind of question since no right solution has been found yet.
    Can anyone give a piece of code illustrate it. No need to have perfect answer, just need sth to push me to explore further. Thanks
    So that it's not the best way to work around. There is no chance at all to have more answers by posting the same multiple times.

Similar Threads

  1. Read a file and converting this file into a string
    By kostinio in forum New To Java
    Replies: 7
    Last Post: 12-26-2009, 03:54 PM
  2. Replies: 2
    Last Post: 05-11-2009, 10:07 AM
  3. Replies: 0
    Last Post: 02-11-2009, 09:53 AM
  4. Replies: 5
    Last Post: 02-05-2009, 10:28 AM
  5. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •