Package dk.netarkivet.common.utils
Class XmlUtils
- java.lang.Object
-
- dk.netarkivet.common.utils.XmlUtils
-
public class XmlUtils extends Object
Utilities for handling XML-files.
-
-
Constructor Summary
Constructors Constructor Description XmlUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.dom4j.Document
documentFromString(String xml)
Parses a given string to produce aDocument
instance.static org.dom4j.Document
getXmlDoc(File f)
Read and parse an XML-file, and return a Document object representing this object.static org.dom4j.Document
getXmlDoc(InputStream resourceAsStream)
Read and parse an XML stream, and return a Document object representing this object.static void
setNode(org.dom4j.Document doc, String xpath, String value)
Set a XmlNode defined by the given XPath to the given value.static void
setNodes(org.dom4j.Document doc, String xpath, String value)
Set a List of XmlNodes defined by the given XPath to the given value.static void
validateWithXSD(File xsdFile)
Validate that the settings xml files conforms to the XSD.static void
writeXmlToFile(org.dom4j.Document doc, File f)
Write document tree to file.
-
-
-
Method Detail
-
getXmlDoc
public static org.dom4j.Document getXmlDoc(File f) throws IOFailure
Read and parse an XML-file, and return a Document object representing this object.- Parameters:
f
- a given xml file- Returns:
- a Document representing the xml file
- Throws:
IOFailure
- if unable to read the xml file or unable to parse the file as XML
-
getXmlDoc
public static org.dom4j.Document getXmlDoc(InputStream resourceAsStream)
Read and parse an XML stream, and return a Document object representing this object.- Parameters:
resourceAsStream
- a given xml document- Returns:
- a Document representing the xml document
- Throws:
IOFailure
- if unable to read the xml document or unable to parse the document as XML
-
setNode
public static void setNode(org.dom4j.Document doc, String xpath, String value)
Set a XmlNode defined by the given XPath to the given value.- Parameters:
doc
- the Document, which is being modifiedxpath
- the given XPathvalue
- the given value- Throws:
IOFailure
- If the given XPath was not found in the document
-
setNodes
public static void setNodes(org.dom4j.Document doc, String xpath, String value)
Set a List of XmlNodes defined by the given XPath to the given value.- Parameters:
doc
- the Document, which is being modifiedxpath
- the given XPathvalue
- the given value- Throws:
IOFailure
- If the given XPath was not found in the document
-
validateWithXSD
public static void validateWithXSD(File xsdFile)
Validate that the settings xml files conforms to the XSD.- Parameters:
xsdFile
- Schema to check settings against.- Throws:
ArgumentNotValid
- if unable to validate the settings filesIOFailure
- If unable to read the settings files and/or the xsd file.
-
writeXmlToFile
public static void writeXmlToFile(org.dom4j.Document doc, File f) throws IOFailure
Write document tree to file.- Parameters:
doc
- the document tree to save.f
- the file to write the document to.- Throws:
IOFailure
- On trouble writing XML file to disk.
-
documentFromString
public static org.dom4j.Document documentFromString(String xml) throws org.dom4j.DocumentException
Parses a given string to produce aDocument
instance.- Parameters:
xml
- Some XML text.- Returns:
- a
Document
parsed from the given xml. - Throws:
org.dom4j.DocumentException
- If unable to parse the given text as XML.
-
-