DocumentToStream
public static void DocumentToStream(Document doc,
OutputStream out)
DocumentToString
public static String DocumentToString(Document doc)
turn a whole DOM document into XML
- string representation of the document, including XML declaration
DocumentToWriter
public static void DocumentToWriter(Document doc,
Writer writer)
ElementToStream
public static void ElementToStream(Element element,
OutputStream out)
ElementToString
public static String ElementToString(Element element)
turn an element into an XML fragment
ElementToWriter
public static void ElementToWriter(Element element,
Writer writer)
PrettyDocumentToStream
public static void PrettyDocumentToStream(Document doc,
OutputStream out)
PrettyDocumentToString
public static String PrettyDocumentToString(Document doc)
PrettyDocumentToWriter
public static void PrettyDocumentToWriter(Document doc,
Writer writer)
PrettyElementToStream
public static void PrettyElementToStream(Element element,
OutputStream out)
PrettyElementToWriter
public static void PrettyElementToWriter(Element element,
Writer writer)
StringToElement
public static Element StringToElement(String namespace,
String name,
String string)
Convert a simple string to an element with a text node
namespace
- - element namespacename
- - element namestring
- - value of the text node
- element - an XML Element, null if no element was created
asElementArray
public static Element[] asElementArray(List list)
Converts a List with org.w3c.dom.Element objects to an Array
with org.w3c.dom.Element objects.
list
- List containing org.w3c.dom.Element objects
- Element[] Array with org.w3c.dom.Element objects
base64encode
public static final String base64encode(byte[] bytes)
findNode
public static Node findNode(Node node,
QName name)
Find a Node with a given QName
node
- parent nodename
- QName of the child we need to find
getChildCharacterData
public static String getChildCharacterData(Element parentEl)
Concat all the text and cdata node children of this elem and return
the resulting text.
(by Matt Duftler)
parentEl
- the element whose cdata/text node values are to
be combined.
getDocumentBuilder
public static DocumentBuilder getDocumentBuilder()
throws ParserConfigurationException
Gets a DocumentBuilder
getEmptyInputSource
public static InputSource getEmptyInputSource()
getEncoding
public static String getEncoding()
Get the current encoding in effect
getEncoding
public static String getEncoding(MessageContext msgContext)
Get the current encoding in effect
getFullQNameFromString
public static QName getFullQNameFromString(String str,
Node e)
Return a QName when passed a string like "foo:bar" by mapping
the "foo" prefix to a namespace in the context of the given Node.
If default namespace is found it is returned as part of the QName.
- a QName generated from the given string representation
getInnerXMLString
public static String getInnerXMLString(Element element)
get the inner XML inside an element as a string. This is done by
converting the XML to its string representation, then extracting the
subset between beginning and end tags.
- textual body of the element, or null for no inner body
getInputSourceFromURI
public static InputSource getInputSourceFromURI(String uri)
Utility to get the bytes uri.
Does NOT handle authenticated URLs,
use getInputSourceFromURI(uri, username, password)
uri
- the resource to get
getInputSourceFromURI(String uri, String username, String password)
getNamespace
public static String getNamespace(String prefix,
Node e)
getNamespace
public static String getNamespace(String prefix,
Node e,
Node stopNode)
Searches for the namespace URI of the given prefix in the given DOM range.
The namespace is not searched in parent of the "stopNode". This is
usefull to get all the needed namespaces when you need to ouput only a
subtree of a DOM document.
prefix
- the prefix to finde
- the starting nodestopNode
- null to search in all the document or a parent node where the search must stop.
- null if no namespace is found, or the namespace URI.
getPrefix
public static String getPrefix(String uri,
Node e)
getQNameFromString
public static QName getQNameFromString(String str,
Node e)
Return a QName when passed a string like "foo:bar" by mapping
the "foo" prefix to a namespace in the context of the given Node.
- a QName generated from the given string representation
getSAXParser
public static SAXParser getSAXParser()
Get a SAX parser instance from the JAXP factory.
getStringForQName
public static String getStringForQName(QName qname,
Element e)
Return a string for a particular QName, mapping a new prefix
if necessary.
getXMLEncoder
public static XMLEncoder getXMLEncoder(String encoding)
Get the XMLEncoder for specific encoding
initSAXFactory
public static void initSAXFactory(String factoryClassName,
boolean namespaceAware,
boolean validating)
Initialize the SAX parser factory.
factoryClassName
- The (optional) class name of the desired
SAXParserFactory implementation. Will be
assigned to the system property
javax.xml.parsers.SAXParserFactory
unless this property is already set.
If null
, leaves current setting
alone.namespaceAware
- true if we want a namespace-aware parservalidating
- true if we want a validating parser
newDocument
public static Document newDocument()
throws ParserConfigurationException
Get an empty new Document
newDocument
public static Document newDocument(InputSource inp)
throws ParserConfigurationException,
SAXException,
IOException
Get a new Document read from the input source
newDocument
public static Document newDocument(InputStream inp)
throws ParserConfigurationException,
SAXException,
IOException
Get a new Document read from the input stream
newDocument
public static Document newDocument(String uri)
throws ParserConfigurationException,
SAXException,
IOException
Get a new Document read from the indicated uri
newDocument
public static Document newDocument(String uri,
String username,
String password)
throws ParserConfigurationException,
SAXException,
IOException
Create a new document from the given URI, use the username and password
if the URI requires authentication.
uri
- the resource to getusername
- basic auth usernamepassword
- basic auth password
normalize
public static void normalize(Node node)
Trim all new lines from text nodes.
privateElementToWriter
public static void privateElementToWriter(Element element,
Writer writer,
boolean omitXMLDecl,
boolean pretty)
releaseDocumentBuilder
public static void releaseDocumentBuilder(DocumentBuilder db)
Releases a DocumentBuilder
releaseSAXParser
public static void releaseSAXParser(SAXParser parser)
Return a SAX parser for reuse.
parser
- A SAX parser that is available for reuse
sourceToInputSource
public static InputSource sourceToInputSource(Source source)
Utility to get the bytes uri
source
- the resource to get
trim
public static String trim(String str)
xmlEncodeString
public static String xmlEncodeString(String orig)
Encode a string appropriately for XML.
orig
- the String to encode
- a String in which XML special chars are repalced by entities