diff --git a/src/edu/stanford/nlp/ie/machinereading/common/DomReader.java b/src/edu/stanford/nlp/ie/machinereading/common/DomReader.java index e8a7f371cb..fb570470fd 100644 --- a/src/edu/stanford/nlp/ie/machinereading/common/DomReader.java +++ b/src/edu/stanford/nlp/ie/machinereading/common/DomReader.java @@ -16,6 +16,8 @@ import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import edu.stanford.nlp.util.XMLUtils; + /** * Generic DOM reader for an XML file */ @@ -127,7 +129,7 @@ public static String getAttributeValue(Node node, String attributeName) { public static Document readDocument(File f) throws IOException, SAXException, ParserConfigurationException { Document document = null; - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilderFactory factory = XMLUtils.safeDocumentBuilderFactory(); // factory.setValidating(true); // factory.setNamespaceAware(true); diff --git a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java b/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java index 7fb9aa3f80..69d3965349 100644 --- a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java +++ b/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java @@ -27,6 +27,7 @@ import edu.stanford.nlp.semgraph.semgrex.ssurgeon.pred.*; import edu.stanford.nlp.semgraph.semgrex.SemgrexPattern; import edu.stanford.nlp.util.Generics; +import edu.stanford.nlp.util.XMLUtils; import edu.stanford.nlp.util.logging.Redwood; @@ -397,7 +398,7 @@ public static String writeToString(SsurgeonPattern pattern) { private static Document createPatternXMLDoc(List patterns) { try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilderFactory dbf = XMLUtils.safeDocumentBuilderFactory(); DocumentBuilder db = dbf.newDocumentBuilder(); Document domDoc = db.newDocument(); Element rootElt = domDoc.createElement(SsurgeonPattern.ELT_LIST_TAG); @@ -452,7 +453,7 @@ private static Document createPatternXMLDoc(List patterns) { @SuppressWarnings("unchecked") public List readFromFile(File file) throws Exception { List retList = new ArrayList<>(); - Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file); + Document doc = XMLUtils.safeDocumentBuilderFactory().newDocumentBuilder().parse(file); if (VERBOSE) System.out.println("Reading ssurgeon file="+file.getAbsolutePath());