public class XMLUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static String |
XML_FILE_ENCODING
The encoding (UTF-8 or ISO-8859-1).
|
Constructor and Description |
---|
XMLUtilities() |
Modifier and Type | Method and Description |
---|---|
static Document |
createDocument()
Creates a new empty Document from the document builder factory.
|
static Transformer |
createLoader(URL schemaURL)
Creates a transformer from an XSL schema used to load multiple XML files
to be validated.
|
static String |
getAttributeString(NamedNodeMap namedNodeMap,
String name)
Gets an attribute from a node attribute list.
|
static String |
getAttributeString(NamedNodeMap namedNodeMap,
String name,
String defaultValue)
Gets an attribute from a node attribute list.
|
static String |
getAttributeString(Node node,
String name)
Gets an attribute from a node.
|
static String |
getAttributeString(Node node,
String name,
String defaultValue)
Gets an attribute from a node.
|
static Element |
getFirstElement(Element parent,
String name)
Gets the first Element with the specified name.
|
static JAXBContext |
getJAXBContext()
Gets the JAXBContext for the "com.iizix" Core.
|
static Marshaller |
getMarshaller()
Gets the "com.iizix" Core JAXB marshaller.
|
static String |
getNodeString(Node node)
Gets a Node as a String.
|
static Unmarshaller |
getUnmarshaller()
Gets the "com.iizix" Core JAXB unmarshaller.
|
static String |
getXMLDocument(Document document)
Gets a Document as a String.
|
static void |
list(Document doc)
Lists a Document.
|
static void |
list(Node node,
int indent)
Lists a Node and it's tree.
|
static Object |
loadObject(Element parent)
Loads a serializable "com.iizix" Core Object into an Element.
|
static Document |
loadXMLDocument(File file)
Loads an XML document from a file into a
Document without schema validation. |
static Document |
loadXMLDocument(InputStream in)
Loads an XML document from a file into a
Document without schema validation. |
static Document |
loadXMLDocument(String data)
Loads an XML document from a String into a
Document . |
static Document |
loadXMLDocument(URL url)
Loads an XML document from a file into a
Document without schema validation. |
static DocumentBuilder |
newDocumentBuilderWithoutSchema()
Create a new XML parser without schema, namespace aware for W3C XML Schema 1.0.
|
static void |
saveObject(Element parent,
Object obj)
Saves a serializable "com.iizix" Core Object into an Element.
|
static void |
saveXMLDocument(Document document,
File file)
Saves a Document to a File.
|
static void |
saveXMLDocument(Document document,
OutputStream output)
Saves a Document to an output stream.
|
static void |
saveXMLDocument(Document document,
Writer writer)
Saves a Document to a writer.
|
public static final String XML_FILE_ENCODING
public static DocumentBuilder newDocumentBuilderWithoutSchema()
public static Document createDocument()
public static Transformer createLoader(URL schemaURL) throws IOException
schemaURL
- The schema URL for the XSL schema.IOException
- For failures in creating the transformer for the URL.public static Document loadXMLDocument(String data) throws IOException, SAXException
Document
.data
- The String.IOException
- for file errors.SAXException
- a SAX exception when loading/parsing the XML file.public static Document loadXMLDocument(File file) throws IOException, SAXException
Document
without schema validation.file
- The file to load.IOException
- for file errors.SAXException
- a SAX exception when loading/parsing the XML file.public static Document loadXMLDocument(URL url) throws IOException, SAXException
Document
without schema validation.url
- The file to load.IOException
- for file errors.SAXException
- a SAX exception when loading/parsing the XML file.public static Document loadXMLDocument(InputStream in) throws IOException, SAXException
Document
without schema validation.in
- The input stream.IOException
- for file errors.SAXException
- a SAX exception when loading/parsing the XML file.public static String getXMLDocument(Document document) throws TransformerException
document
- The document to save.TransformerException
- For document errors.TransformerFactoryConfigurationError
- For XML factory errors.public static String getNodeString(Node node) throws TransformerException
node
- The document to save.TransformerException
- For document errors.TransformerFactoryConfigurationError
- For XML factory errors.public static void saveXMLDocument(Document document, File file) throws IOException, TransformerException
document
- The document to save.file
- The file to use for document saving.IOException
- For file errors.TransformerException
- For document errors.public static void saveXMLDocument(Document document, OutputStream output) throws IOException, TransformerException
document
- The document to save.output
- The output stream.IOException
- For file errors.TransformerException
- For document errors.public static void saveXMLDocument(Document document, Writer writer) throws IOException, TransformerException
document
- The document to save.writer
- The writer.IOException
- For file errors.TransformerException
- For document errors.public static void list(Document doc)
doc
- The document to list.public static void list(Node node, int indent)
node
- The node to list.indent
- The indent level.public static String getAttributeString(Node node, String name)
node
- the node.name
- name of attribute.public static String getAttributeString(NamedNodeMap namedNodeMap, String name)
namedNodeMap
- the node's attributes.name
- name of attribute.public static String getAttributeString(Node node, String name, String defaultValue)
node
- the node.name
- name of attribute.defaultValue
- the default value to use if attribute is not found.defaultValue
if it's not found.public static String getAttributeString(NamedNodeMap namedNodeMap, String name, String defaultValue)
namedNodeMap
- the node's attributes.name
- name of attribute.defaultValue
- the default value to use if attribute is not found.defaultValue
if it's not found.public static Element getFirstElement(Element parent, String name)
parent
- The parent element.name
- The name.public static JAXBContext getJAXBContext() throws JAXBException
JAXBException
- For serialization errors.public static Marshaller getMarshaller() throws JAXBException
JAXBException
- For serialization errors.public static Unmarshaller getUnmarshaller() throws JAXBException
JAXBException
- For serialization errors.public static void saveObject(Element parent, Object obj) throws JAXBException
parent
- The parent elementobj
- The object to save in the parent element.JAXBException
- For serialization errors.public static Object loadObject(Element parent) throws JAXBException
parent
- The parent element to retrieve the object from using the unmarshaller.JAXBException
- For serialization errors.iizi® is a registered trademark of Mindus SARL. © Copyright Mindus SARL, 2020. All rights reserved.