|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.dmonix.xml.XMLUtil
XML utility class.
The class provides functionality for easy management of XML data
Copyright: Copyright (c) 2003
Company: dmonix.org
| Constructor Summary | |
XMLUtil()
|
|
| Method Summary | |
static org.w3c.dom.Element |
appendChildElement(org.w3c.dom.Document doc,
org.w3c.dom.Element element,
java.lang.String elementName)
Append a child element to the given element. |
static org.w3c.dom.Element |
appendChildElement(org.w3c.dom.Document doc,
org.w3c.dom.Element element,
java.lang.String elementName,
java.lang.String elementValue)
Append a child element with a single text node to the given element. |
static void |
appendChildElement(org.w3c.dom.Document doc,
java.lang.String name,
java.lang.String value)
Append an element with a text node to the given document root. |
static void |
documentToFile(org.w3c.dom.Document doc,
java.io.File file)
Writes the document to a file. |
static void |
documentToFile(org.w3c.dom.Document doc,
java.lang.String file)
Writes the document to a file. |
static java.util.Hashtable |
documentToHashtable(org.w3c.dom.Document doc)
Converts the input document into a Hashtable. |
static void |
documentToStream(org.w3c.dom.Document doc,
java.io.OutputStream ostream)
Writes the document to a given outputstream. |
static void |
documentToStream(org.w3c.dom.Document doc,
java.io.OutputStream ostream,
boolean closeStream)
Writes the document to a given outputstream. |
static java.lang.String |
documentToString(org.w3c.dom.Document doc)
Gets the string representation of an XML document. |
static void |
documentToWriter(org.w3c.dom.Document doc,
java.io.Writer writer)
Writes the document to a given writer. |
static org.w3c.dom.Element |
getChildElementByTagName(org.w3c.dom.Element parent,
java.lang.String name)
Returns the first occurens of a child element whith a specific name. |
static org.w3c.dom.Element |
getCreateChildElementByTagName(org.w3c.dom.Element el,
java.lang.String name)
Get the first occurence of an element with a specified name, if a element with the specified name can't be found it will be created. |
static org.w3c.dom.Document |
getDocument(java.io.File file)
Parse an XML document from a file. |
static org.w3c.dom.Document |
getDocument(org.xml.sax.InputSource is)
Parse an XML document from a file. |
static org.w3c.dom.Document |
getDocument(java.io.InputStream istream)
Parse an XML document from an input stream. |
static org.w3c.dom.Document |
getDocument(java.lang.String path)
Parse an XML document from a file. |
static org.w3c.dom.Document |
getDocument(java.net.URL url)
Parse an XML document from a URL. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.NodeList list)
Returns the first element if it exist and null if it does
not exist. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.Node node,
java.lang.String path)
|
static java.lang.String |
getElementValue(org.w3c.dom.Element element)
Get the value of the element. |
static java.lang.String |
getElementValue(org.w3c.dom.Element element,
java.lang.String defaultValue)
Get the value of the element. |
static java.lang.String |
getElementValue(org.w3c.dom.NodeList list)
Get the node value from the first element in the node list. |
static java.lang.String |
getElementValue(org.w3c.dom.NodeList list,
java.lang.String defaultValue)
Get the node value from the first element in the node list. |
static java.lang.String |
getFirstParameterValue(org.w3c.dom.Document doc,
java.lang.String name)
Returns the value of the first <Paramter> element
that has an name attribute maching the supplied parameter. |
static java.lang.String |
getFirstParameterValue(org.w3c.dom.Element parent,
java.lang.String name)
Returns the value of the first <Paramter> element
that has an name attribute maching the supplied parameter. |
static org.w3c.dom.Element[] |
getParameters(org.w3c.dom.Document doc,
java.lang.String name)
Returns an array with all child <Parameter> elements
that have a name matching the given parameter value. |
static org.w3c.dom.Element[] |
getParameters(org.w3c.dom.Element parent,
java.lang.String name)
Returns an array with all child <Parameter> elements
that have a name matching the given parameter value. |
static java.lang.String |
getTransformerProperty(java.lang.String name)
Gets a property for the XML transformer. |
static boolean |
isBlank(java.lang.String value)
Checks if a node value is blank (contains only white spaces). |
static org.w3c.dom.Document |
loadFromResource(java.lang.String path)
Load an XML document from a resource. |
static org.w3c.dom.Document |
newDocument()
Creates a new empty XML document. |
static org.w3c.dom.Document |
newDocument(java.lang.String s)
Creates a new XML document out of the provided string. |
static void |
nodeToStream(org.w3c.dom.Node node,
java.io.OutputStream ostream)
Writes the XML node to a given outputstream. |
static java.lang.String |
nodeToString(org.w3c.dom.Node node)
Gets the string representation of an XML node. |
static void |
nodeToWriter(org.w3c.dom.Node node,
java.io.Writer writer)
Writes the XML node to a given writer. |
static void |
normalizeDocument(org.w3c.dom.Node node)
Recursively removes all empty child text nodes. |
static void |
removeAllChildElements(org.w3c.dom.Element element)
Removes all child elements to the given element |
static void |
saveToFile(org.w3c.dom.Document doc,
java.io.File file)
Save the specified document to file. |
static void |
saveToFile(org.w3c.dom.Document doc,
java.lang.String path)
Save the specified document to file. |
static void |
setElementValue(org.w3c.dom.Element el,
java.lang.String value)
Set the value of an element. |
static org.w3c.dom.Element |
setRootElement(org.w3c.dom.Document doc,
java.lang.String elementName)
Creates a new root element for the document. |
static void |
setTransformerProperty(java.lang.String name,
java.lang.String value)
Sets a property for the XML transformer. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public XMLUtil()
| Method Detail |
public static org.w3c.dom.Document newDocument()
public static org.w3c.dom.Document newDocument(java.lang.String s)
throws java.io.IOException,
org.xml.sax.SAXException
s - The string to parse
java.io.IOException
org.xml.sax.SAXException
public static void nodeToStream(org.w3c.dom.Node node,
java.io.OutputStream ostream)
throws java.io.IOException,
javax.xml.transform.TransformerException
node - The nodeostream - The target stream
java.io.IOException
javax.xml.transform.TransformerExceptionpublic static java.lang.String nodeToString(org.w3c.dom.Node node)
node - The node
documentToWriter(Document, Writer)
public static void nodeToWriter(org.w3c.dom.Node node,
java.io.Writer writer)
throws java.io.IOException,
javax.xml.transform.TransformerException
node - The nodewriter - The target writer
java.io.IOException
javax.xml.transform.TransformerExceptionpublic static void normalizeDocument(org.w3c.dom.Node node)
node - The node to normalize
public static org.w3c.dom.Element setRootElement(org.w3c.dom.Document doc,
java.lang.String elementName)
doc - the document to which to append the root elementelementName - the name of the root element
public static void setTransformerProperty(java.lang.String name,
java.lang.String value)
name - Property namevalue - Property valueOutputKeyspublic static java.lang.String getTransformerProperty(java.lang.String name)
name - Property name
OutputKeys
public static org.w3c.dom.Element getCreateChildElementByTagName(org.w3c.dom.Element el,
java.lang.String name)
el - the parent elementname - the name of the child element
public static org.w3c.dom.Element getChildElementByTagName(org.w3c.dom.Element parent,
java.lang.String name)
parent - the parent elementname - the name of the child element to look for
public static org.w3c.dom.Element getElement(org.w3c.dom.NodeList list)
null if it does
not exist.
list - the list
public static org.w3c.dom.Element getElement(org.w3c.dom.Node node,
java.lang.String path)
node - -path - -
public static org.w3c.dom.Element appendChildElement(org.w3c.dom.Document doc,
org.w3c.dom.Element element,
java.lang.String elementName,
java.lang.String elementValue)
doc - the documentelement - the element to append the child toelementName - the name of the elementelementValue - the value of the element
public static org.w3c.dom.Element appendChildElement(org.w3c.dom.Document doc,
org.w3c.dom.Element element,
java.lang.String elementName)
doc - the documentelement - the element to append the child toelementName - the name of the element
public static void appendChildElement(org.w3c.dom.Document doc,
java.lang.String name,
java.lang.String value)
doc - The document to append the element toname - The name of the new elementvalue - The textual value of the elementpublic static java.util.Hashtable documentToHashtable(org.w3c.dom.Document doc)
doc - The input document
public static java.lang.String documentToString(org.w3c.dom.Document doc)
doc - The document
documentToWriter(Document, Writer)
public static void documentToFile(org.w3c.dom.Document doc,
java.io.File file)
throws java.io.IOException,
javax.xml.transform.TransformerException
doc - The documentfile - The target file
java.io.IOException
javax.xml.transform.TransformerExceptiondocumentToStream(Document, OutputStream)
public static void documentToFile(org.w3c.dom.Document doc,
java.lang.String file)
throws java.io.IOException,
javax.xml.transform.TransformerException
doc - The documentfile - The target file name
java.io.IOException
javax.xml.transform.TransformerExceptiondocumentToStream(Document, OutputStream)
public static void documentToStream(org.w3c.dom.Document doc,
java.io.OutputStream ostream)
throws java.io.IOException,
javax.xml.transform.TransformerException
doc - The documentostream - The target stream
java.io.IOException
javax.xml.transform.TransformerException
public static void documentToStream(org.w3c.dom.Document doc,
java.io.OutputStream ostream,
boolean closeStream)
throws java.io.IOException,
javax.xml.transform.TransformerException
doc - The documentostream - The target streamcloseStream - If the outputstream is to be closed after write
java.io.IOException
javax.xml.transform.TransformerException
public static void documentToWriter(org.w3c.dom.Document doc,
java.io.Writer writer)
throws java.io.IOException,
javax.xml.transform.TransformerException
doc - The documentwriter - The target writer
java.io.IOException
javax.xml.transform.TransformerException
public static java.lang.String getElementValue(org.w3c.dom.Element element,
java.lang.String defaultValue)
TEXT node as child, if
so the value of the text node is returned otherwise an empty String
is returned.
element - The elementdefaultValue - The value to return in case no value was found
public static java.lang.String getElementValue(org.w3c.dom.Element element)
TEXT node as child, if
so the value of the text node is returned otherwise an empty String
is returned.
element - The element
public static java.lang.String getElementValue(org.w3c.dom.NodeList list,
java.lang.String defaultValue)
Text that may be extracted.
list - The node listdefaultValue - The value to return in case no value was found
public static java.lang.String getElementValue(org.w3c.dom.NodeList list)
list - The node list
public static java.lang.String getFirstParameterValue(org.w3c.dom.Document doc,
java.lang.String name)
<Paramter> element
that has an name attribute maching the supplied parameter.
doc - The input Documentname - Name of the paramter to find
public static java.lang.String getFirstParameterValue(org.w3c.dom.Element parent,
java.lang.String name)
<Paramter> element
that has an name attribute maching the supplied parameter.
parent - The input Elementname - Name of the paramter to find
public static void setElementValue(org.w3c.dom.Element el,
java.lang.String value)
el - the elementvalue - the value
public static org.w3c.dom.Document loadFromResource(java.lang.String path)
throws java.io.IOException,
org.xml.sax.SAXException,
javax.xml.parsers.ParserConfigurationException
path - the path to load from
java.io.IOException
org.xml.sax.SAXException
javax.xml.parsers.ParserConfigurationException
public static org.w3c.dom.Element[] getParameters(org.w3c.dom.Document doc,
java.lang.String name)
<Parameter> elements
that have a name matching the given parameter value.
doc - Input documentname - value of the name attribute
public static org.w3c.dom.Element[] getParameters(org.w3c.dom.Element parent,
java.lang.String name)
<Parameter> elements
that have a name matching the given parameter value.
parent - Input elementname - value of the name attribute
public static boolean isBlank(java.lang.String value)
value - The value to check
public static org.w3c.dom.Document getDocument(java.io.File file)
throws java.io.IOException,
org.xml.sax.SAXException
file - The file
java.io.IOException
org.xml.sax.SAXException
public static org.w3c.dom.Document getDocument(org.xml.sax.InputSource is)
throws java.io.IOException,
org.xml.sax.SAXException
is - The input source
java.io.IOException
org.xml.sax.SAXException
public static org.w3c.dom.Document getDocument(java.lang.String path)
throws java.lang.Exception
path - the file
java.lang.Exception
public static org.w3c.dom.Document getDocument(java.net.URL url)
throws java.io.IOException,
org.xml.sax.SAXException
url - The URL from where to parse the document
java.io.IOException
org.xml.sax.SAXException
public static org.w3c.dom.Document getDocument(java.io.InputStream istream)
throws java.io.IOException,
org.xml.sax.SAXException
istream - The stream from where to parse the document
java.io.IOException
org.xml.sax.SAXExceptionpublic static void removeAllChildElements(org.w3c.dom.Element element)
element - The element
public static void saveToFile(org.w3c.dom.Document doc,
java.lang.String path)
doc - the document to savepath - the path to the filesaveToFile(Document, File)
public static void saveToFile(org.w3c.dom.Document doc,
java.io.File file)
doc - the document to savefile - the file to save to
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||