Static Public Member Functions | |
static Document | loadDocumentFromPath (Path filePath) throws IOException, ParserConfigurationException, SAXException |
static Document | loadDocumentFromData (String data) throws IOException, ParserConfigurationException, SAXException |
static Document | loadDocumentStream (InputStream stream) throws ParserConfigurationException, IOException, SAXException |
static List< Element > | getChildElementsWithName (Element ele, String name) |
static String | textOfElementByName (Element elem, String child) |
static int | integerOfElementByName (Element element, String child, int def) |
static Element | elementWithName (Element elem, String child) |
static String | getAttrOrNull (Element ele, String attr) |
static String | getAttributeOrDefault (Element elem, String val, Object def) |
static< T > List< T > | transformElements (Element root, String eleName, String childName, Function< Element, T > transform) |
static< T > List< T > | transformElements (Element root, String childName, Function< Element, T > transform) |
static void | writeXml (Document doc, OutputStream output) throws TransformerException |
static void | writeXml (Document doc, OutputStream output, boolean prettyPrint) throws TransformerException |
static Document | newDocumentRoot (String name) throws ParserConfigurationException |
static Element | appendElementWithNameValue (Element parent, String name, Object value) |
A series of static helper method that make dealing with XML easier, this is because many areas of tcMenu deal with XML documents, and these functions are generally useful.
|
static |
Append a new element into the parent provided with the name given.
parent | the parent where the new element is to be placed |
name | the name of the new element |
value | the value to set as text (can be null) |
|
static |
Gets an element with a given name or null
elem | the parent element |
child | the child to locate |
|
static |
Gets the text of an attribute or a default value.
elem | the element |
val | the attribute name |
def | the default value |
|
static |
Gets the text of attribute if it is available, or null
ele | the element |
attr | the attribute name |
|
static |
Find all child elements with a given name
ele | the parent element |
name | the name to search for |
name
|
static |
Gets the int value associated with the named child, or the default if it does not exist or can't be parsed.
element | the parent element |
child | the name of the child element |
def | the default value in case of problem |
|
static |
Load an XML document from a string of data
data | the data to load from |
IOException | for any IO problems |
ParserConfigurationException | if the document does not parse |
SAXException | if the document does not parse |
|
static |
Load an XML document from a file system path
filePath | the path to load from |
IOException | for any IO problems |
ParserConfigurationException | if the document does not parse |
SAXException | if the document does not parse |
|
static |
Load an XML document from a stream
stream | the steam to load from |
IOException | for any IO problems |
ParserConfigurationException | if the document does not parse |
SAXException | if the document does not parse |
|
static |
Creates a new document that has a root element with the name given
name | the root element name |
ParserConfigurationException | if the document cannot be created |
|
static |
Get the text of an element with the name child. Saves looking up the element and then getting text.
elem | the parent element |
child | the name of the child to get the text of |
|
static |
Transforms all elements that match childName
under root
, there is another overload that provides indirection. You provide the transformation function that takes an Element and returns the desired result.
root | the root element to start at |
childName | the items to filter for |
transform | the transformation to apply - returns T, takes an element |
<T> | can be any type you wish to return in your transformation |
|
static |
Transforms all elements that match childName
under either root
if eleName is null, or under root/eleName if eleName is provided. You provide the transformation function that takes an Element and returns the desired result
root | the root element to start at |
eleName | optionally, another level of indirection (can be null) EG root/eleName |
childName | the items to filter for |
transform | the transformation to apply - returns T, takes an element |
<T> | can be any type you wish to return in your transformation |
|
static |
Writes an XML document without reformatting it, this is good if you are working with a DOM that was previously loaded from a stream, where it may be already formatted.
doc | the document |
output | the output stream to write to |
TransformerException | if the XML cannot be transformed |
|
static |
Writes an XML document to a stream
doc | the document |
output | the stream to write to |
prettyPrint | if the document should be formatted |
TransformerException | if it cannot be written |