Package cl.obcom.desktopfx.util
Class XmlUtil
java.lang.Object
cl.obcom.desktopfx.util.XmlUtil
Utility methods that perform general XML operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Document
bytesToXml
(byte[] bytes, URL schemaURL) Converts a XML bytes to a XML document validating with a schema.static Document
Create a new instance of a DOM Document object usied to build a DOM trees.static Transformer
Create a new Transformer object that performs a copy of the source to the result.static Document
stringToXml
(String xmlString, InputStream schemaSource) Converts a XML string to a XML document validating with a schema.
-
Method Details
-
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
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 isnull
.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.
-