BAEL-3219

Parsing an XML File Using SAX Parser
This commit is contained in:
yassin.hajaj 2019-08-31 21:48:19 +02:00 committed by Yassin Hajaj
parent 21804927e3
commit 08da9be666
1 changed files with 8 additions and 2 deletions

View File

@ -7,6 +7,11 @@ import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import static org.junit.Assert.*;
@ -14,12 +19,13 @@ import static org.junit.Assert.*;
public class SaxParserMainUnitTest {
@Test
public void parse_baeldung_xml_document() throws IOException, SAXException, ParserConfigurationException {
public void parse_baeldung_xml_document() throws IOException, SAXException, ParserConfigurationException, URISyntaxException {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
SaxParserMain.BaeldungHandler baeldungHandler = new SaxParserMain.BaeldungHandler();
saxParser.parse("src\\test\\resources\\sax\\baeldung.xml", baeldungHandler);
Path path = Paths.get(new URL("src\\test\\resources\\sax\\baeldung.xml").toURI());
saxParser.parse(path.toFile(), baeldungHandler);
SaxParserMain.Baeldung result = baeldungHandler.getWebsite();