Добрый день, вроде пишут что должно работать, а не работает. Тестирую на разных файлах - у меня все работает корректно.
Только костылить свой парсер?
package com.javarush.task.task19.task1918;
import java.io.*;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.jsoup.parser.Parser;
import static javax.swing.text.html.parser.Parser.*;
/*
Знакомство с тегами
*/
public class Solution {
public static String ourTag = "";
public static StringBuilder line = new StringBuilder();
public static void main(String[] args) {
ourTag = args[0];
int countOpen = 0;
int countClose = 0 ;
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader fileReader = new BufferedReader(new FileReader(bufferedReader.readLine()))
){
while (fileReader.ready()){
String currentLine = fileReader.readLine();
Pattern pattern = Pattern.compile("<"+ ourTag+ "\\b.*?>");
Matcher matcher = pattern.matcher(currentLine);
while (matcher.find()){
countOpen++;
}
//found closed tags
pattern = Pattern.compile("<\\/"+ ourTag+ "\\b.*?>");
matcher = pattern.matcher(currentLine);
while (matcher.find()){
countClose++;
}
if (countOpen == countClose ){
line.append(currentLine);
parseHtml(line.toString());
line = new StringBuilder();
}
else {
line.append(currentLine);
}
}
}
catch (IOException e){
}
}
public static void parseHtml(String line){
Document document = Jsoup.parse(line,"",Parser.xmlParser());
Elements elements = document.select(ourTag);
for (Element element: elements){
System.out.println(element.toString());
}
}
}