Help, Substring not working, dont know why...

I need to load some xml file and extract some data from it.

I have this code.

I thing that this have to work but havent...it prints input error...

Any suggestion?

file is opened by this code it works

/////

if (e.getSource() == openButton) {

int returnVal = fc.showOpenDialog(FileChooserDemo.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {

file = fc.getSelectedFile();

////

/// this doesnt work

try {

String f;

FileInputStream fstream = new FileInputStream(file);

BufferedReader in = new BufferedReader(new inputStreamReader(fstream));

while ((f = in.readLine()) != null)

{

System.out.println(in.readLine());

String document = in.readLine().toString();

String startTag = "<Text>";

String endTag = "</Text>";

int start = document.indexOf(startTag) + startTag.length();

int end = document.indexOf(endTag) + 1;

String result = document.substring(start,end);

System.err.println(result);

}

in.close();

[1083 byte] By [Hempa] at [2007-11-27 4:35:58]
# 1
Some Advice for Your Future:Use harmless debugging outputsTry a few System.out.println()s and im sure youll tackle the problem.
TuringPesta at 2007-7-12 9:46:06 > top of Java-index,Java Essentials,Java Programming...
# 2

Also I think you want to change these readLines:

System.out.println(in.readLine());

String document = in.readLine().toString();

into "f". every time you call readLine you are getting the next line.

i dont know if you intend to or not but that means that your

while(){} loop is extracting a total of 3 lines.

TuringPesta at 2007-7-12 9:46:06 > top of Java-index,Java Essentials,Java Programming...
# 3
If your <Text> node appears more than once, that won't get you anywhere. String provides another method indexOf (substring, pos), that will look for the substring from a given position within the string. That will help out
kdajania at 2007-7-12 9:46:06 > top of Java-index,Java Essentials,Java Programming...
# 4

also what are you trying to accomplish with:

String document = in.readLine().toString();

whats with ".toString()"? it obviously already returns a String

seeing as how youve already assigned the previous readLine() to

a String variable named "f".

Are you trying to create a copy? If so you want "new String(String)"

TuringPesta at 2007-7-12 9:46:06 > top of Java-index,Java Essentials,Java Programming...
# 5
also, use more meaningful variable names than "f".id say a minimum of 3 letters, lol.
TuringPesta at 2007-7-12 9:46:06 > top of Java-index,Java Essentials,Java Programming...