Class XmlInputOutputUtils

java.lang.Object
eu.kartoffelquadrat.svgpatcher.XmlInputOutputUtils

public class XmlInputOutputUtils extends Object
Util class to handle import of xml filed from disk. Based on this tutorial: https://mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/
  • Constructor Details

    • XmlInputOutputUtils

      public XmlInputOutputUtils()
      Default constructor.
  • Method Details

    • parseXmlToDocument

      public static Document parseXmlToDocument(String fileLocation) throws ParserConfigurationException, IOException, SAXException
      Helper method to parse a given xml file.
      Parameters:
      fileLocation - as the location of the target xml file on disk.
      Returns:
      document object representing the in-ram tree structure of the parsed file.
      Throws:
      ParserConfigurationException - in case the provided parser arguments cannot be applied.
      IOException - in case the provided input file location cannot be accessed.
      SAXException - in case the provided svg file cannot be parsed.
    • writeXmlDocumentToDisk

      public static void writeXmlDocumentToDisk(Document xmlDocument, String fileLocation) throws TransformerException, IOException
      Based on this tutorial: https://www.baeldung.com/java-write-xml-document-file
      Parameters:
      xmlDocument - the in-memory xml tree.
      fileLocation - the file location on disk as string.
      Throws:
      TransformerException - in case the modified file cannot be persisted to disk
      IOException - in case the modified file cannot be persisted to disk