blob: d8182d6932469ac3feb590a13ef5f6a433a08c64 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package edu.brown.cs.student.term.parsing;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
public abstract class XmlParser {
protected DocumentBuilder builder = null;
/**
* This constructor crates and saves the builder that turns the xml text into a tree stricture.
*/
protected XmlParser() {
// Builds the immutable factory
System.err.println("LOG: Constructor of " + getClass() + ". To make XML parser factory.");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);
// Creates the builder from the factory
try {
System.err.println("LOG: To make documentBuilder in " + getClass());
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
System.err.println("INTERNAL: " + getClass() + " : " + e.getClass());
}
}
/**
* Method used to parse the xml file.
* @param pathToXml The path to the xml text file.
* @return The tree structure parsed as an xml doc.
*/
public abstract Document parse(String pathToXml);
}
|