Package org.codehaus.cargo.util
Class XmlUtils
- java.lang.Object
- 
- org.codehaus.cargo.util.XmlUtils
 
- 
 public class XmlUtils extends Object This class offers utility methods for handling XML files.
- 
- 
Constructor SummaryConstructors Constructor Description XmlUtils()default constructor will assign no namespaces and use a default file handler.XmlUtils(boolean namespaceAware)default constructor will assign no namespaces and use a default file handler.XmlUtils(FileHandler fileHandler)constructor will assign no namespaces.XmlUtils(FileHandler fileHandler, boolean namespaceAware)constructor will assign no namespaces.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description DocumentcreateDocument()Creates a new, blank XML document.FileHandlergetFileHandler()Map<String,String>getNamespaces()DocumentloadXmlFromFile(String sourceFile)read the specified file into a Document.ElementparseIntoElement(String elementToParse)parse the passed string into anElementobject.voidsaveXml(Document document, String filename)write the xml document to disk, rethrowing checked exceptions as runtime.ElementselectElementMatchingXPath(String xpath, Element toSearch)The following will search the given element for the specified XPath and return any node that matches.List<Element>selectElementsMatchingXPath(String xpath, Element toSearch)The following will search the given element for the specified XPath and return a list of nodes that match.voidsetFileHandler(FileHandler fileHandler)voidsetNamespaces(Map<String,String> namespaces)StringtoString(Element node)Output an XML node as string, without the XML header.
 
- 
- 
- 
Constructor Detail- 
XmlUtilspublic XmlUtils() default constructor will assign no namespaces and use a default file handler.
 - 
XmlUtilspublic XmlUtils(boolean namespaceAware) default constructor will assign no namespaces and use a default file handler.- Parameters:
- namespaceAware- true if XmlUtils should be namespace aware.
 
 - 
XmlUtilspublic XmlUtils(FileHandler fileHandler) constructor will assign no namespaces.- Parameters:
- fileHandler- used to read and write xml files.
 
 - 
XmlUtilspublic XmlUtils(FileHandler fileHandler, boolean namespaceAware) constructor will assign no namespaces.- Parameters:
- fileHandler- used to read and write xml files.
- namespaceAware- true if XmlUtils should be namespace aware.
 
 
- 
 - 
Method Detail- 
selectElementsMatchingXPathpublic List<Element> selectElementsMatchingXPath(String xpath, Element toSearch) The following will search the given element for the specified XPath and return a list of nodes that match.- Parameters:
- xpath- - selection criteria
- toSearch- - element to start the search at
- Returns:
- List of matching elements
 
 - 
selectElementMatchingXPathpublic Element selectElementMatchingXPath(String xpath, Element toSearch) The following will search the given element for the specified XPath and return any node that matches.- Parameters:
- xpath- - selection criteria
- toSearch- - element to start the search at
- Returns:
- a matching element
 
 - 
loadXmlFromFilepublic Document loadXmlFromFile(String sourceFile) read the specified file into a Document.- Parameters:
- sourceFile- file to read
- Returns:
- Document corresponding with sourceFile
 
 - 
saveXmlpublic void saveXml(Document document, String filename) write the xml document to disk, rethrowing checked exceptions as runtime.- Parameters:
- document- document to write to disk
- filename- where to write the document
 
 - 
getFileHandlerpublic FileHandler getFileHandler() - Returns:
- the Cargo file utility class
 
 - 
setFileHandlerpublic void setFileHandler(FileHandler fileHandler) - Parameters:
- 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.
 
 - 
setNamespacespublic void setNamespaces(Map<String,String> namespaces) - Parameters:
- namespaces- the namespaces to set
 
 - 
parseIntoElementpublic Element parseIntoElement(String elementToParse) parse the passed string into anElementobject.- Parameters:
- elementToParse- string to parse
- Returns:
- result of parsing
 
 - 
createDocumentpublic Document createDocument() Creates a new, blank XML document.- Returns:
- New, blank XML document.
 
 
- 
 
-