public class Dom4JUtil extends Object
Constructor and Description |
---|
Dom4JUtil()
default constructor will assign no namespaces and use a default file handler.
|
Dom4JUtil(FileHandler fileHandler)
constructor will assign no namespaces.
|
Modifier and Type | Method and Description |
---|---|
FileHandler |
getFileHandler() |
Map |
getNamespaces() |
org.dom4j.Document |
loadXmlFromFile(String sourceFile)
read the specified file into a Document.
|
org.dom4j.Element |
parseIntoElement(String elementToParse)
parse the passed string into an
Element object. |
void |
saveXml(org.dom4j.Document document,
String filename)
write the xml document to disk, rethrowing checked exceptions as runtime.
|
org.dom4j.Element |
selectElementMatchingXPath(String xpath,
org.dom4j.Element toSearch)
The following will search the given element for the specified xpath and return any node that
matches.
|
List |
selectElementsMatchingXPath(String xpath,
org.dom4j.Element toSearch)
The following will search the given element for the specified xpath and return a list of
nodes that match.
|
void |
setFileHandler(FileHandler fileHandler) |
void |
setNamespaces(Map namespaces) |
public Dom4JUtil()
public Dom4JUtil(FileHandler fileHandler)
fileHandler
- used to read and write xml files.public List selectElementsMatchingXPath(String xpath, org.dom4j.Element toSearch)
xpath
- - selection criteriatoSearch
- - element to start the search atpublic org.dom4j.Element selectElementMatchingXPath(String xpath, org.dom4j.Element toSearch)
xpath
- - selection criteriatoSearch
- - element to start the search atpublic org.dom4j.Document loadXmlFromFile(String sourceFile)
sourceFile
- file to readpublic void saveXml(org.dom4j.Document document, String filename)
document
- document to write to diskfilename
- where to write the documentpublic FileHandler getFileHandler()
public void setFileHandler(FileHandler fileHandler)
fileHandler
- the Cargo file utility class to use. This method is useful for unit
testing with Mock objects as it can be passed a test file handler that doesn't
perform any real file action.public void setNamespaces(Map namespaces)
namespaces
- the namespaces to setpublic Map getNamespaces()
public org.dom4j.Element parseIntoElement(String elementToParse)
Element
object.elementToParse
- string to parseCopyright © 2004-2013 Codehaus. All Rights Reserved.