0

I am trying to write a java program that parses xml file using jsoup. I downloaded the latest jsoup jar file from https://jsoup.org/download and also added it to the build path. All the imports were working fine , untill I used Element object from jsoup (jsoup.nodes.Element) Can you please help me out?


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
> import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import org.jsoup.select.Elements;


/**
 * Implementation for Spectrum-based Fault Localization (SBFL).
 *
 */
public class SBFL
{

    /**
     * Use Jsoup to parse the coverage file in the XML format.
     * 
     * @param file
     * @return a map from each test to the set of lines that it covers
     * @throws FileNotFoundException
     * @throws IOException
     */
    protected static Map<String, Set<String>> readXMLCov(File file)
            throws FileNotFoundException, IOException {
        Map<String, Set<String>> res = new HashMap<String, Set<String>>();
        
        FileInputStream fis= new FileInputStream(file);
        Document doc= Jsoup.parse(fis,null,"",Parser.xmlParser());
        
        
        for(Elements e: doc.select("body")){
             System.out.println(e);
         }
        
        
        
        // TODO
        return res;
    }
}
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 07 '22 at 09:33
  • Looks like a typo; try `for (Element e : …)`, for [example](https://stackoverflow.com/a/73528614/230513). – trashgod Nov 13 '22 at 17:32

0 Answers0