Package com.iizix
Class XMLUtilities
java.lang.Object
com.iizix.XMLUtilities
Helper class containing utility methods used when processing XML documents.
- Author:
- Christopher Mindus
- Field SummaryFields
- Constructor SummaryConstructors
- Method SummaryModifier and TypeMethodDescription- static DocumentCreates 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 String- getNodeString- (Node node) Gets a Node as a String.- static String- getXMLDocument- (Document document) Gets a Document as a String.- static voidLists a Document.- static voidLists a Node and it's tree.- static Document- loadXMLDocument- (File file) Loads an XML document from a file into a- Documentwithout schema validation.- static DocumentLoads an XML document from a file into a- Documentwithout 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- Documentwithout schema validation.- static DocumentBuilderCreate a new XML parser without schema, namespace aware for W3C XML Schema 1.0.- 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.
- Field Details- XML_FILE_ENCODINGThe encoding (UTF-8 or ISO-8859-1).- See Also:
 
 
- Constructor Details- XMLUtilitiespublic XMLUtilities()
 
- Method Details- newDocumentBuilderWithoutSchemaCreate a new XML parser without schema, namespace aware for W3C XML Schema 1.0. The error handler does not accept warnings or errors and throws the exception.- Returns:
- A new Document Builder that can parse XML.
 
- createDocumentCreates a new empty Document from the document builder factory.- Returns:
- The new Document.
 
- createLoaderCreates a transformer from an XSL schema used to load multiple XML files to be validated.- Parameters:
- schemaURL- The schema URL for the XSL schema.
- Returns:
- The XML transformer to use.
- Throws:
- IOException- For failures in creating the transformer for the URL.
 
- loadXMLDocumentLoads an XML document from a String into a- Document.- Parameters:
- data- The String.
- Returns:
- the loaded document.
- Throws:
- IOException- for file errors.
- SAXException- a SAX exception when loading/parsing the XML file.
 
- loadXMLDocumentLoads an XML document from a file into a- Documentwithout schema validation.- Parameters:
- file- The file to load.
- Returns:
- the loaded document.
- Throws:
- IOException- for file errors.
- SAXException- a SAX exception when loading/parsing the XML file.
 
- loadXMLDocumentLoads an XML document from a file into a- Documentwithout schema validation.- Parameters:
- url- The file to load.
- Returns:
- the loaded document.
- Throws:
- IOException- for file errors.
- SAXException- a SAX exception when loading/parsing the XML file.
 
- loadXMLDocumentLoads an XML document from a file into a- Documentwithout schema validation.- Parameters:
- in- The input stream.
- Returns:
- the loaded document.
- Throws:
- IOException- for file errors.
- SAXException- a SAX exception when loading/parsing the XML file.
 
- getXMLDocumentGets a Document as a String.- Parameters:
- document- The document to save.
- Returns:
- The XML representation of the document.
- Throws:
- TransformerException- For document errors.
- TransformerFactoryConfigurationError- For XML factory errors.
 
- getNodeStringGets a Node as a String.- Parameters:
- node- The document to save.
- Returns:
- The XML representation of the node.
- Throws:
- TransformerException- For document errors.
- TransformerFactoryConfigurationError- For XML factory errors.
 
- saveXMLDocumentpublic static void saveXMLDocument- (Document document, File file) throws IOException, TransformerException Saves a Document to a File.- Parameters:
- document- The document to save.
- file- The file to use for document saving.
- Throws:
- IOException- For file errors.
- TransformerException- For document errors.
 
- saveXMLDocumentpublic static void saveXMLDocument- (Document document, OutputStream output) throws IOException, TransformerException Saves a Document to an output stream.- Parameters:
- document- The document to save.
- output- The output stream.
- Throws:
- IOException- For file errors.
- TransformerException- For document errors.
 
- saveXMLDocumentpublic static void saveXMLDocument- (Document document, Writer writer) throws IOException, TransformerException Saves a Document to a writer.- Parameters:
- document- The document to save.
- writer- The writer.
- Throws:
- IOException- For file errors.
- TransformerException- For document errors.
 
- listLists a Document.- Parameters:
- doc- The document to list.
 
- listLists a Node and it's tree.- Parameters:
- node- The node to list.
- indent- The indent level.
 
- getAttributeStringGets an attribute from a node.- Parameters:
- node- the node.
- name- name of attribute.
- Returns:
- the string value of the attribute or null if it's not found.
 
- getAttributeStringGets an attribute from a node attribute list.- Parameters:
- namedNodeMap- the node's attributes.
- name- name of attribute.
- Returns:
- the string value of the attribute or null if it's not found.
 
- getAttributeStringGets an attribute from a node.- Parameters:
- node- the node.
- name- name of attribute.
- defaultValue- the default value to use if attribute is not found.
- Returns:
- the string value of the attribute or defaultValueif it's not found.
 
- getAttributeStringpublic static String getAttributeString- (NamedNodeMap namedNodeMap, String name, String defaultValue) Gets an attribute from a node attribute list.- Parameters:
- namedNodeMap- the node's attributes.
- name- name of attribute.
- defaultValue- the default value to use if attribute is not found.
- Returns:
- the string value of the attribute or defaultValueif it's not found.
 
- getFirstElementGets the first Element with the specified name.- Parameters:
- parent- The parent element.
- name- The name.
- Returns:
- null if not found.