Hi, firstly my english is not very good so ım sory about that.
ı want to parse a web source. ı got the source code with urlconnection in jTextArea but ı cant get between two html tag
for ex.
<p class="asd">asdasdasdas </p>
<p class="asd2">bdfgfdgdfgf </p>
<p class="AltBaslik">I want to this </p>
<p class="bbb">bbbbbbbb</p>

ı cant get " ı want to this "

how can ı get this string please some help.

Use some XML library to help you with parsing, also some current code would be helpful to find out what you doing and where you going wrong

ı can get only full source. ı cant get any selected two tag

If you want to do parsing manually from text, read it in line-by-line and try to find an index of the matching open and close tag. Of course, this would assume that all tags are done correctly (no invalid nested tags or no open-with-no-close tags).

Edited 6 Years Ago by Taywin: n/a

// Assumptions
//   1.Tags in the string are valid (have open & close including no invalid nested)
//   2.There is only 1 open & close tag of an HTML tag in the string.
//   3.The string must not contain '>' if the line does not have a tag
// If the string doesn't follow the assumption, this example won't work!

// create a sample string --> '<p class="asd">asdasdasdas </p>'
String ex1 = "<p class=\"asd\">asdasdasdas </p>";

int idx = ex1.indexOf(">");
String res = "";
if (idx>1) {  // known that '>' cannot be at position 0 or 1
  int nextIdx = ex1.indexOf("<", idx);  // search for '<' starting from idx
  res = ex1.substring(idx+1, nextIdx-1);
}
// now 'res' contains the substring inside the tag

Edited 6 Years Ago by Taywin: n/a

its working good but cant read jtextarea only read from string variable..

That's the part you need to implement. You need to getText() from your text area and use it as string in the code portion.

This article has been dead for over six months. Start a new discussion instead.