net.sf.mmapps.commons.util
Class XmlUtil

java.lang.Object
  extended by net.sf.mmapps.commons.util.XmlUtil

public class XmlUtil
extends java.lang.Object

Common utilities for handling XML.

Author:
Nico Klasens

Method Summary
static void createAttribute(org.w3c.dom.Element root, java.lang.String name, boolean value)
           
static void createAttribute(org.w3c.dom.Element root, java.lang.String name, double value)
           
static void createAttribute(org.w3c.dom.Element root, java.lang.String name, float value)
           
static void createAttribute(org.w3c.dom.Element root, java.lang.String name, int value)
           
static void createAttribute(org.w3c.dom.Element root, java.lang.String name, long value)
           
static void createAttribute(org.w3c.dom.Element element, java.lang.String name, java.lang.String value)
           
static org.w3c.dom.Element createChild(org.w3c.dom.Element root, java.lang.String elementName)
           
static org.w3c.dom.Element createChild(org.w3c.dom.Element root, java.lang.String elementName, java.lang.String namespaceURI)
           
static org.w3c.dom.Element createChildText(org.w3c.dom.Element element, java.lang.String name, boolean value)
           
static org.w3c.dom.Element createChildText(org.w3c.dom.Element element, java.lang.String name, double value)
           
static org.w3c.dom.Element createChildText(org.w3c.dom.Element element, java.lang.String name, float value)
           
static org.w3c.dom.Element createChildText(org.w3c.dom.Element element, java.lang.String name, int value)
           
static org.w3c.dom.Element createChildText(org.w3c.dom.Element element, java.lang.String name, long value)
           
static org.w3c.dom.Element createChildText(org.w3c.dom.Element element, java.lang.String name, java.lang.String value)
           
static org.w3c.dom.Document createDocument()
           
static org.w3c.dom.Element createElement(org.w3c.dom.Document doc, java.lang.String elementName)
           
static org.w3c.dom.Element createElement(org.w3c.dom.Document doc, java.lang.String elementName, java.lang.String namespaceURI)
           
static org.w3c.dom.Element createRoot(org.w3c.dom.Document doc, java.lang.String elementName)
           
static org.w3c.dom.Element createRoot(org.w3c.dom.Document doc, java.lang.String elementName, java.lang.String namespaceURI)
           
static void createText(org.w3c.dom.Element root, boolean text)
           
static void createText(org.w3c.dom.Element root, double text)
           
static void createText(org.w3c.dom.Element root, float text)
           
static void createText(org.w3c.dom.Element root, int text)
           
static void createText(org.w3c.dom.Element root, long text)
           
static void createText(org.w3c.dom.Element root, java.lang.String text)
           
static java.util.List getElements(org.w3c.dom.Element element)
           
static java.lang.String getText(org.w3c.dom.Node node)
           
static java.lang.String getText(org.w3c.dom.Node node, java.lang.String defaultvalue)
           
static org.apache.xml.serialize.OutputFormat getXmlOutput(boolean indent, boolean omitComments, boolean omitDocumentType, boolean omitXMLDeclaration)
          create Output format for xml Be caregull, Textnodes will be fomormatted and indented too.
static java.lang.String serializeDocument(org.w3c.dom.Document doc)
          Serialize Document instance to pretty printed String.
static java.lang.String serializeDocumentFragment(org.w3c.dom.DocumentFragment docfrag)
          Serialize DocumentFragment instance to pretty printed String.
static java.lang.String serializeElement(org.w3c.dom.Element element)
          Serialize Document instance to pretty printed String.
static java.lang.String serializeElement(org.w3c.dom.Element element, boolean omitxml)
          Serialize Document instance to pretty printed String.
static org.w3c.dom.Document toDocument(java.io.InputStream stream)
          Returns a W3C Document representation of the string.
static org.w3c.dom.Document toDocument(java.lang.String str)
          Returns a W3C Document representation of the string.
static java.lang.String xmlEscape(java.lang.String fragment)
           
static java.lang.String xmlUnescape(java.lang.String escapedFragment)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

serializeDocument

public static java.lang.String serializeDocument(org.w3c.dom.Document doc)
Serialize Document instance to pretty printed String.

Parameters:
doc - Source object.
Returns:
document as String.

serializeDocumentFragment

public static java.lang.String serializeDocumentFragment(org.w3c.dom.DocumentFragment docfrag)
Serialize DocumentFragment instance to pretty printed String.

Parameters:
docfrag - Source object.
Returns:
documentfragment as String.

serializeElement

public static java.lang.String serializeElement(org.w3c.dom.Element element)
Serialize Document instance to pretty printed String.

Parameters:
element - Source object.
Returns:
Element as String.

serializeElement

public static java.lang.String serializeElement(org.w3c.dom.Element element,
                                                boolean omitxml)
Serialize Document instance to pretty printed String.

Parameters:
element - Source object.
omitxml - Omit the xml declaration from the returned xml
Returns:
Element as String.

getXmlOutput

public static org.apache.xml.serialize.OutputFormat getXmlOutput(boolean indent,
                                                                 boolean omitComments,
                                                                 boolean omitDocumentType,
                                                                 boolean omitXMLDeclaration)
create Output format for xml Be caregull, Textnodes will be fomormatted and indented too.

Parameters:
indent - - indent xml
omitComments - - omit tcomments
omitDocumentType - - omit document type
omitXMLDeclaration - - omit xml declaration
Returns:
output format

createDocument

public static org.w3c.dom.Document createDocument()

createChild

public static org.w3c.dom.Element createChild(org.w3c.dom.Element root,
                                              java.lang.String elementName)

createChild

public static org.w3c.dom.Element createChild(org.w3c.dom.Element root,
                                              java.lang.String elementName,
                                              java.lang.String namespaceURI)

createRoot

public static org.w3c.dom.Element createRoot(org.w3c.dom.Document doc,
                                             java.lang.String elementName)

createRoot

public static org.w3c.dom.Element createRoot(org.w3c.dom.Document doc,
                                             java.lang.String elementName,
                                             java.lang.String namespaceURI)

createElement

public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc,
                                                java.lang.String elementName)

createElement

public static org.w3c.dom.Element createElement(org.w3c.dom.Document doc,
                                                java.lang.String elementName,
                                                java.lang.String namespaceURI)

createAttribute

public static void createAttribute(org.w3c.dom.Element element,
                                   java.lang.String name,
                                   java.lang.String value)

createText

public static void createText(org.w3c.dom.Element root,
                              java.lang.String text)

createChildText

public static org.w3c.dom.Element createChildText(org.w3c.dom.Element element,
                                                  java.lang.String name,
                                                  java.lang.String value)

createAttribute

public static void createAttribute(org.w3c.dom.Element root,
                                   java.lang.String name,
                                   boolean value)

createAttribute

public static void createAttribute(org.w3c.dom.Element root,
                                   java.lang.String name,
                                   int value)

createAttribute

public static void createAttribute(org.w3c.dom.Element root,
                                   java.lang.String name,
                                   float value)

createAttribute

public static void createAttribute(org.w3c.dom.Element root,
                                   java.lang.String name,
                                   long value)

createAttribute

public static void createAttribute(org.w3c.dom.Element root,
                                   java.lang.String name,
                                   double value)

createText

public static void createText(org.w3c.dom.Element root,
                              boolean text)

createText

public static void createText(org.w3c.dom.Element root,
                              int text)

createText

public static void createText(org.w3c.dom.Element root,
                              float text)

createText

public static void createText(org.w3c.dom.Element root,
                              long text)

createText

public static void createText(org.w3c.dom.Element root,
                              double text)

createChildText

public static org.w3c.dom.Element createChildText(org.w3c.dom.Element element,
                                                  java.lang.String name,
                                                  boolean value)

createChildText

public static org.w3c.dom.Element createChildText(org.w3c.dom.Element element,
                                                  java.lang.String name,
                                                  int value)

createChildText

public static org.w3c.dom.Element createChildText(org.w3c.dom.Element element,
                                                  java.lang.String name,
                                                  float value)

createChildText

public static org.w3c.dom.Element createChildText(org.w3c.dom.Element element,
                                                  java.lang.String name,
                                                  long value)

createChildText

public static org.w3c.dom.Element createChildText(org.w3c.dom.Element element,
                                                  java.lang.String name,
                                                  double value)

getText

public static java.lang.String getText(org.w3c.dom.Node node)

getText

public static java.lang.String getText(org.w3c.dom.Node node,
                                       java.lang.String defaultvalue)

toDocument

public static org.w3c.dom.Document toDocument(java.lang.String str)
Returns a W3C Document representation of the string.

Parameters:
str - Xml which should be converted
Returns:
DOM structure

toDocument

public static org.w3c.dom.Document toDocument(java.io.InputStream stream)
Returns a W3C Document representation of the string.

Parameters:
stream - The input stream with the xml to convert
Returns:
DOM structure

getElements

public static java.util.List getElements(org.w3c.dom.Element element)

xmlEscape

public static java.lang.String xmlEscape(java.lang.String fragment)

xmlUnescape

public static java.lang.String xmlUnescape(java.lang.String escapedFragment)


Copyright © 2003-2006 mmapps. All Rights Reserved.