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 StringdetermineFileFormat(String xml, String encoding) determineFileFormat.static StringdetermineFileFormat(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.DocumentgetDocumentFromString(String string, String encoding) Create a JDOM document from an XML string.static org.jdom2.input.SAXBuilderstatic StringgetStringFromElement(Object element, String encoding) getStringFromElement.static org.jdom2.output.XMLOutputterCreate an XMLOutputter with default encoding and system linebreaksstatic org.jdom2.DocumentreadXmlFile(String filePath) readXmlFile.static org.jdom2.DocumentreadXmlFile(URL url) Reads an XML document from the given URL and returns a JDOM2 document.static org.jdom2.DocumentreadXmlFile(Path path) readXmlFile.static FilewriteXmlFile(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- aStringobject.- Returns:
- a
Documentobject. - 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- aURLobject.- Returns:
- a
Documentobject. - Throws:
FileNotFoundException- if any.IOException- if any.org.jdom2.JDOMException- if any.
-
readXmlFile
readXmlFile.
- Parameters:
path- aPathobject.- Returns:
- a
Documentobject. - Throws:
FileNotFoundException- if any.IOException- if any.org.jdom2.JDOMException- if any.
-
writeXmlFile
writeXmlFile.
- Parameters:
doc- aDocumentobject.filePath- aStringobject.- Returns:
- a
Fileobject. - 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- aStringobject.encoding- aStringobject.- Returns:
- a
Documentobject. - 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- aStringobject.encoding- aStringobject.- Returns:
- a
Stringobject. - Throws:
org.jdom2.JDOMException- if any.IOException- if any.
-
determineFileFormat
Determines the format of the given XML file by checking for namespaces.- Parameters:
doc- aDocumentobject.- Returns:
- a
Stringobject.
-
checkXMLWellformed
public static List<XMLError> checkXMLWellformed(String xml) throws ParserConfigurationException, SAXException, IOException - Parameters:
xml-- Returns:
- List
- Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
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
-