Package io.goobi.viewer.controller
Class XmlTools
java.lang.Object
io.goobi.viewer.controller.XmlTools
XML utilities.
-
Method Summary
Modifier and TypeMethodDescriptioncheckXMLWellformed
(String xml) static String
determineFileFormat
(String xml, String encoding) determineFileFormat.static String
determineFileFormat
(org.jdom2.Document doc) Determines the format of the given XML file by checking for namespaces.evaluate
(String expr, Object parent, org.jdom2.filter.Filter filter, List<org.jdom2.Namespace> namespaces) XPath evaluation with a given return type filter.evaluateAttributeString
(String expr, Object parent, List<org.jdom2.Namespace> namespaces) evaluateString
(String expr, Object parent, List<org.jdom2.Namespace> namespaces) static List<org.jdom2.Element>
evaluateToElements
(String expr, org.jdom2.Element element, List<org.jdom2.Namespace> namespaces) Evaluates the given XPath expression to a list of elements.evaluateToFirstAttributeString
(String expr, Object parent, List<org.jdom2.Namespace> namespaces) static Optional<org.jdom2.Element>
evaluateToFirstElement
(String expr, org.jdom2.Element element, List<org.jdom2.Namespace> namespaces) evaluateToFirstString
(String expr, Object parent, List<org.jdom2.Namespace> namespaces) static org.jdom2.Document
getDocumentFromString
(String string, String encoding) Create a JDOM document from an XML string.static org.jdom2.input.SAXBuilder
static String
getStringFromElement
(Object element, String encoding) getStringFromElement.static org.jdom2.output.XMLOutputter
Create an XMLOutputter with default encoding and system linebreaksstatic org.jdom2.Document
readXmlFile
(String filePath) readXmlFile.static org.jdom2.Document
readXmlFile
(URL url) Reads an XML document from the given URL and returns a JDOM2 document.static org.jdom2.Document
readXmlFile
(Path path) readXmlFile.static File
writeXmlFile
(org.jdom2.Document doc, String filePath) writeXmlFile.
-
Method Details
-
getSAXBuilder
public static org.jdom2.input.SAXBuilder getSAXBuilder() -
readXmlFile
public static org.jdom2.Document readXmlFile(String filePath) throws IOException, org.jdom2.JDOMException readXmlFile.
- Parameters:
filePath
- aString
object.- Returns:
- a
Document
object. - Throws:
FileNotFoundException
- if any.IOException
- if any.org.jdom2.JDOMException
- if any.
-
readXmlFile
Reads an XML document from the given URL and returns a JDOM2 document. Works with XML files within JARs.- Parameters:
url
- aURL
object.- Returns:
- a
Document
object. - Throws:
FileNotFoundException
- if any.IOException
- if any.org.jdom2.JDOMException
- if any.
-
readXmlFile
readXmlFile.
- Parameters:
path
- aPath
object.- Returns:
- a
Document
object. - Throws:
FileNotFoundException
- if any.IOException
- if any.org.jdom2.JDOMException
- if any.
-
writeXmlFile
writeXmlFile.
- Parameters:
doc
- aDocument
object.filePath
- aString
object.- Returns:
- a
File
object. - Throws:
FileNotFoundException
- if any.IOException
- if any.
-
getDocumentFromString
public static org.jdom2.Document getDocumentFromString(String string, String encoding) throws org.jdom2.JDOMException, IOException Create a JDOM document from an XML string.- Parameters:
string
- aString
object.encoding
- aString
object.- Returns:
- a
Document
object. - Throws:
org.jdom2.JDOMException
- if any.IOException
- if any.
-
getStringFromElement
getStringFromElement.
-
evaluateToElements
public static List<org.jdom2.Element> evaluateToElements(String expr, org.jdom2.Element element, List<org.jdom2.Namespace> namespaces) Evaluates the given XPath expression to a list of elements. -
evaluateToFirstElement
-
evaluate
public static List<Object> evaluate(String expr, Object parent, org.jdom2.filter.Filter filter, List<org.jdom2.Namespace> namespaces) XPath evaluation with a given return type filter. -
evaluateAttributeString
-
evaluateString
-
evaluateToFirstAttributeString
-
evaluateToFirstString
-
determineFileFormat
public static String determineFileFormat(String xml, String encoding) throws org.jdom2.JDOMException, IOException determineFileFormat.
- Parameters:
xml
- aString
object.encoding
- aString
object.- Returns:
- a
String
object. - Throws:
org.jdom2.JDOMException
- if any.IOException
- if any.
-
determineFileFormat
Determines the format of the given XML file by checking for namespaces.- Parameters:
doc
- aDocument
object.- Returns:
- a
String
object.
-
checkXMLWellformed
public static List<XMLError> checkXMLWellformed(String xml) throws ParserConfigurationException, SAXException, IOException - Parameters:
xml
-- Returns:
- List
- Throws:
ParserConfigurationException
SAXException
IOException
-
getXMLOutputter
public static org.jdom2.output.XMLOutputter getXMLOutputter()Create an XMLOutputter with default encoding and system linebreaks- Returns:
- a new XMLOutputter instance with standard format settings
-