Class XmlUtil

java.lang.Object
cl.obcom.desktopfx.util.XmlUtil

public final class XmlUtil extends Object
Utility methods that perform general XML operations.
  • Method Details

    • getDocument

      public static Document getDocument()
      Create a new instance of a DOM Document object usied to build a DOM trees. The Document is created with a DocumentBuilder that is created the first time it is needed.
      Returns:
      a new Document instance.
    • getTransformer

      public static Transformer getTransformer()
      Create a new Transformer object that performs a copy of the source to the result. The Transformer is created with a TransformerFactory that is created the first time is needed.
      Returns:
      a new Transformer instance.
    • bytesToXml

      public static Document bytesToXml(byte[] bytes, URL schemaURL) throws ParserConfigurationException, SAXException, IOException
      Converts a XML bytes to a XML document validating with a schema.
      Parameters:
      bytes - the array of bytes to be converted to an XML document.
      schemaURL - the URL of the schema of the XML document.
      Returns:
      the XML document obtained from supplied bytes.
      Throws:
      NullPointerException - if an argument is null.
      ParserConfigurationException - if a configuration error occurs.
      SAXException - if a XML parse error occurs.
      IOException - if an I/O error occurs.
    • stringToXml

      public static Document stringToXml(String xmlString, InputStream schemaSource) throws SAXException, IOException, ParserConfigurationException
      Converts a XML string to a XML document validating with a schema.
      Parameters:
      xmlString - a string with a XML representation of the document.
      schemaSource - the input stream of a XML schema (can be null).
      Returns:
      the XML document obtained from supplied xmlString.
      Throws:
      ParserConfigurationException - if a configuration error occurs.
      SAXException - if a XML parse error occurs.
      IOException - if an I/O error occurs.