Package org.apache.jempbox.impl
Class XMLUtil
java.lang.Object
org.apache.jempbox.impl.XMLUtil
This class with handle some simple XML operations.
- Version:
- $Revision: 1.4 $
- Author:
- Ben Litchfield, Christopher Oezbek
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]asByteArray(Document doc, String encoding) Convert the document to an array of bytes.static ElementgetElement(Element parent, String elementName) Get the first instance of an element by name.static IntegergetIntValue(Element parent, String nodeName) Get the integer value of a subnode.static StringgetStringValue(Element node) This will get the text value of an element.static StringgetStringValue(Element parent, String nodeName) Get the value of a subnode.static DocumentCreate a new blank XML document.static Documentparse(InputStream is) This will parse an XML stream and create a DOM document.static DocumentThis will parse an XML stream and create a DOM document.static Documentparse(InputSource is) This will parse an InputSource and create a DOM document.static voidSave the XML document to a file.static voidsave(Node doc, OutputStream outStream, String encoding) Save the XML document to an output stream.static voidsetElementableValue(Element parent, String name, Elementable node) Set an XML element document.static voidsetIntValue(Element parent, String nodeName, Integer intValue) Set the integer value of an element.static voidsetStringValue(Element node, String value) This will set the text value of an element.static voidsetStringValue(Element parent, String nodeName, String nodeValue) Set the value of an element.
-
Method Details
-
parse
This will parse an XML stream and create a DOM document.- Parameters:
is- The stream to get the XML from.- Returns:
- The DOM document.
- Throws:
IOException- It there is an error creating the dom.
-
parse
This will parse an InputSource and create a DOM document.- Parameters:
is- The stream to get the XML from.- Returns:
- The DOM document.
- Throws:
IOException- It there is an error creating the dom.
-
parse
This will parse an XML stream and create a DOM document.- Parameters:
fileName- The file to get the XML from.- Returns:
- The DOM document.
- Throws:
IOException- It there is an error creating the dom.
-
newDocument
Create a new blank XML document.- Returns:
- The new blank XML document.
- Throws:
IOException- If there is an error creating the XML document.
-
getElement
Get the first instance of an element by name.- Parameters:
parent- The parent to get the element from.elementName- The name of the element to look for.- Returns:
- The element or null if it is not found.
-
getIntValue
Get the integer value of a subnode.- Parameters:
parent- The parent element that holds the values.nodeName- The name of the node that holds the integer value.- Returns:
- The integer value of the node.
-
setIntValue
Set the integer value of an element.- Parameters:
parent- The parent element that will hold this subelement.nodeName- The name of the subelement.intValue- The value to set.
-
getStringValue
Get the value of a subnode.- Parameters:
parent- The parent element that holds the values.nodeName- The name of the node that holds the value.- Returns:
- The value of the sub node.
-
setStringValue
Set the value of an element.- Parameters:
parent- The parent element that will hold this subelement.nodeName- The name of the subelement.nodeValue- The value to set.
-
getStringValue
This will get the text value of an element.- Parameters:
node- The node to get the text value for.- Returns:
- The text of the node.
-
setStringValue
This will set the text value of an element.- Parameters:
node- The node to get the text value for.value- The new value to set the node to.
-
setElementableValue
Set an XML element document.- Parameters:
parent- The parent document to set the value in.name- The name of the XML element to set.node- The node to set or clear.
-
save
Save the XML document to a file.- Parameters:
doc- The XML document to save.file- The file to save the document to.encoding- The encoding to save the file as.- Throws:
TransformerException- If there is an error while saving the XML.
-
save
public static void save(Node doc, OutputStream outStream, String encoding) throws TransformerException Save the XML document to an output stream.- Parameters:
doc- The XML document to save.outStream- The stream to save the document to.encoding- The encoding to save the file as.- Throws:
TransformerException- If there is an error while saving the XML.
-
asByteArray
Convert the document to an array of bytes.- Parameters:
doc- The XML document.encoding- The encoding of the output data.- Returns:
- The XML document as an array of bytes.
- Throws:
TransformerException- If there is an error transforming to text.
-