goldengate.common.xml
Class XmlUtil

java.lang.Object
  extended by goldengate.common.xml.XmlUtil

public class XmlUtil
extends Object

XML utility that handles simple cases as:

Author:
Frederic Bregier

Constructor Summary
XmlUtil()
           
 
Method Summary
static org.dom4j.Element addAndGetElementMultiple(org.dom4j.Document doc, String path)
          Add an element given by the path relative to the document
static org.dom4j.Element addAndGetElementMultiple(org.dom4j.Element ref, String path)
          Add an element given by the path relative to the referent element
static org.dom4j.Element addAndSetElementMultiple(org.dom4j.Document doc, String path, String value)
          Add an element given by the path relative to the document and set the value
static org.dom4j.Element addAndSetElementMultiple(org.dom4j.Element ref, String path, String value)
          Add an element given by the path relative to the referent element and set the value
static org.dom4j.Element addOrGetElement(org.dom4j.Document doc, String path)
          Add or Get (if already existing) an element given by the path relative to the document
static org.dom4j.Element addOrGetElement(org.dom4j.Element ref, String path)
          Add or Get (if already existing) an element given by the path relative to the referent element
static org.dom4j.Element addOrSetElement(org.dom4j.Document doc, String path, String value)
          Add or Get (if already existing) an element given by the path relative to the document and set the value
static org.dom4j.Element addOrSetElement(org.dom4j.Element ref, String path, String value)
          Add or Get (if already existing) an element given by the path relative to the referent element and set the value
static org.dom4j.Document createEmptyDocument()
           
static org.dom4j.Document getDocument(File file)
           
static org.dom4j.Document getDocument(String filename)
           
static org.dom4j.Element getElement(org.dom4j.Document doc, String path)
           
static org.dom4j.Element getElement(org.dom4j.Element ref, String path)
           
static List<org.dom4j.Element> getElementMultiple(org.dom4j.Document doc, String path)
           
static List<org.dom4j.Element> getElementMultiple(org.dom4j.Element ref, String path)
           
static org.dom4j.Element getParentElement(org.dom4j.Document doc, String path)
           
static org.dom4j.Element getParentElement(org.dom4j.Element ref, String path)
           
static org.dom4j.Element getRootElement(org.dom4j.Document document)
           
static void main(String[] args)
          Example (run test)
static XmlValue[] read(org.dom4j.Document doc, XmlDecl[] decls)
          Create the XmlValues from the XmlDevls and the Document
static XmlValue[] read(org.dom4j.Element ref, XmlDecl[] decls)
          Create the XmlValues from the XmlDevls and the reference Element
static org.dom4j.Document readDocument(String document)
          Read the document from the string
static void saveDocument(File file, org.dom4j.Document document)
          Save the document into the file
static void saveDocument(String filename, org.dom4j.Document document)
          Save the document into the file
static void saveElement(File file, org.dom4j.Element element)
          Save the branch from element into the file
static void saveElement(String filename, org.dom4j.Element element)
          Save the branch from element into the file
static void write(org.dom4j.Document doc, XmlValue[] values)
          Add all nodes from XmlValues into Document
static void write(org.dom4j.Element ref, XmlValue[] values)
          Add all nodes from XmlValues from the referenced Element
static String writeToString(org.dom4j.Document document)
           
static String writeToString(org.dom4j.Element element)
           
static void writeXML(String filename, String encoding, org.dom4j.Document document)
          Write the given XML document to filename using the encoding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtil

public XmlUtil()
Method Detail

getDocument

public static org.dom4j.Document getDocument(String filename)
                                      throws IOException,
                                             org.dom4j.DocumentException
Parameters:
filename -
Returns:
Existing Document from filename
Throws:
IOException
org.dom4j.DocumentException

getDocument

public static org.dom4j.Document getDocument(File file)
                                      throws IOException,
                                             org.dom4j.DocumentException
Parameters:
file -
Returns:
Existing Document from file
Throws:
IOException
org.dom4j.DocumentException

readDocument

public static org.dom4j.Document readDocument(String document)
                                       throws org.dom4j.DocumentException
Read the document from the string

Parameters:
document - as String
Returns:
the Document
Throws:
org.dom4j.DocumentException

writeToString

public static String writeToString(org.dom4j.Document document)
Parameters:
document -
Returns:
the document as an XML string

writeToString

public static String writeToString(org.dom4j.Element element)
Parameters:
element -
Returns:
the element as an XML string

createEmptyDocument

public static org.dom4j.Document createEmptyDocument()
Returns:
an empty new Document

saveDocument

public static void saveDocument(String filename,
                                org.dom4j.Document document)
                         throws IOException
Save the document into the file

Parameters:
filename -
document -
Throws:
IOException

saveDocument

public static void saveDocument(File file,
                                org.dom4j.Document document)
                         throws IOException
Save the document into the file

Parameters:
file -
document -
Throws:
IOException

saveElement

public static void saveElement(String filename,
                               org.dom4j.Element element)
                        throws IOException
Save the branch from element into the file

Parameters:
filename -
element -
Throws:
IOException

saveElement

public static void saveElement(File file,
                               org.dom4j.Element element)
                        throws IOException
Save the branch from element into the file

Parameters:
file -
element -
Throws:
IOException

getRootElement

public static org.dom4j.Element getRootElement(org.dom4j.Document document)
Parameters:
document -
Returns:
the root Element from the document

addOrSetElement

public static org.dom4j.Element addOrSetElement(org.dom4j.Element ref,
                                                String path,
                                                String value)
Add or Get (if already existing) an element given by the path relative to the referent element and set the value

Parameters:
ref -
path -
value -
Returns:
the new added or already existing element with new value

addOrGetElement

public static org.dom4j.Element addOrGetElement(org.dom4j.Element ref,
                                                String path)
Add or Get (if already existing) an element given by the path relative to the referent element

Parameters:
ref -
path -
Returns:
the new added or already existing element

addAndSetElementMultiple

public static org.dom4j.Element addAndSetElementMultiple(org.dom4j.Element ref,
                                                         String path,
                                                         String value)
Add an element given by the path relative to the referent element and set the value

Parameters:
ref -
path -
value -
Returns:
the new added element with value

addAndGetElementMultiple

public static org.dom4j.Element addAndGetElementMultiple(org.dom4j.Element ref,
                                                         String path)
Add an element given by the path relative to the referent element

Parameters:
ref -
path -
Returns:
the new added element

getParentElement

public static org.dom4j.Element getParentElement(org.dom4j.Element ref,
                                                 String path)
                                          throws org.dom4j.DocumentException
Parameters:
ref -
path -
Returns:
the parent element associated with the path relatively to the referent element
Throws:
org.dom4j.DocumentException

getElement

public static org.dom4j.Element getElement(org.dom4j.Element ref,
                                           String path)
                                    throws org.dom4j.DocumentException
Parameters:
ref -
path -
Returns:
the element associated with the path relatively to the referent element
Throws:
org.dom4j.DocumentException

getElementMultiple

public static List<org.dom4j.Element> getElementMultiple(org.dom4j.Element ref,
                                                         String path)
                                                  throws org.dom4j.DocumentException
Parameters:
ref -
path -
Returns:
the element associated with the path relatively to the referent element
Throws:
org.dom4j.DocumentException

addOrSetElement

public static org.dom4j.Element addOrSetElement(org.dom4j.Document doc,
                                                String path,
                                                String value)
Add or Get (if already existing) an element given by the path relative to the document and set the value

Parameters:
doc -
path -
value -
Returns:
the new added or already existing element with new value

addOrGetElement

public static org.dom4j.Element addOrGetElement(org.dom4j.Document doc,
                                                String path)
Add or Get (if already existing) an element given by the path relative to the document

Parameters:
doc -
path -
Returns:
the new added or already existing element

addAndSetElementMultiple

public static org.dom4j.Element addAndSetElementMultiple(org.dom4j.Document doc,
                                                         String path,
                                                         String value)
Add an element given by the path relative to the document and set the value

Parameters:
doc -
path -
value -
Returns:
the new added element with value

addAndGetElementMultiple

public static org.dom4j.Element addAndGetElementMultiple(org.dom4j.Document doc,
                                                         String path)
Add an element given by the path relative to the document

Parameters:
doc -
path -
Returns:
the new added element

getParentElement

public static org.dom4j.Element getParentElement(org.dom4j.Document doc,
                                                 String path)
                                          throws org.dom4j.DocumentException
Parameters:
doc -
path -
Returns:
the Parent element associated with the path relatively to the document
Throws:
org.dom4j.DocumentException

getElement

public static org.dom4j.Element getElement(org.dom4j.Document doc,
                                           String path)
                                    throws org.dom4j.DocumentException
Parameters:
doc -
path -
Returns:
the element associated with the path relatively to the document
Throws:
org.dom4j.DocumentException

getElementMultiple

public static List<org.dom4j.Element> getElementMultiple(org.dom4j.Document doc,
                                                         String path)
                                                  throws org.dom4j.DocumentException
Parameters:
doc -
path -
Returns:
the element associated with the path relatively to the document
Throws:
org.dom4j.DocumentException

read

public static XmlValue[] read(org.dom4j.Document doc,
                              XmlDecl[] decls)
Create the XmlValues from the XmlDevls and the Document

Parameters:
doc -
decls -
Returns:
XmlValues

read

public static XmlValue[] read(org.dom4j.Element ref,
                              XmlDecl[] decls)
Create the XmlValues from the XmlDevls and the reference Element

Parameters:
ref -
decls -
Returns:
XmlValues

write

public static void write(org.dom4j.Document doc,
                         XmlValue[] values)
Add all nodes from XmlValues into Document

Parameters:
doc -
values -

write

public static void write(org.dom4j.Element ref,
                         XmlValue[] values)
Add all nodes from XmlValues from the referenced Element

Parameters:
ref -
values -

main

public static void main(String[] args)
Example (run test)

Parameters:
args -

writeXML

public static void writeXML(String filename,
                            String encoding,
                            org.dom4j.Document document)
                     throws IOException
Write the given XML document to filename using the encoding

Parameters:
filename -
encoding - if null, default encoding ISO-8859-1 will be used
document -
Throws:
IOException


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.