You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
41 lines
1.1 KiB
package seng302;
|
|
|
|
import org.w3c.dom.Document;
|
|
import org.w3c.dom.Element;
|
|
import org.xml.sax.SAXException;
|
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
/**
|
|
* Created by fwy13 on 26/03/2017.
|
|
*/
|
|
public abstract class XMLReader {
|
|
|
|
protected Document doc;
|
|
|
|
public XMLReader(String filePath) throws ParserConfigurationException, IOException, SAXException {
|
|
InputStream fXmlFile = getClass().getClassLoader().getResourceAsStream(filePath);
|
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
|
doc = dBuilder.parse(fXmlFile);
|
|
doc.getDocumentElement().normalize();
|
|
}
|
|
|
|
public Document getDocument() {
|
|
return doc;
|
|
}
|
|
|
|
public String getTextValueOfNode(Element n, String tagName) {
|
|
return n.getElementsByTagName(tagName).item(0).getTextContent();
|
|
}
|
|
|
|
public String getAttribute(Element n, String attr) {
|
|
return n.getAttribute(attr);
|
|
}
|
|
|
|
}
|