Package de.uni_kiel.rz.fdr.repl.mycore
Class XMLHelpers
java.lang.Object
de.uni_kiel.rz.fdr.repl.mycore.XMLHelpers
Some helper functions related to JDOM XML.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.jdom2.Parent
addStringOrElement
(org.jdom2.Parent parent, Object content, boolean nsInherit) Adds content to a JDOM node, automatically coverting XML-like strings to JDOM elements.static org.jdom2.Parent
addStringOrElement
(org.jdom2.Parent parent, Collection<?> content, boolean nsInherit) Adds content to a JDOM node, automatically coverting XML-like strings to JDOM elements.static <T> Collection<T>
inheritNamespace
(org.jdom2.NamespaceAware reference, Collection<T> children) For each child in children: sets the namespace of a child node and all of its descendants to the namespace of reference, but only if none of the children or their descendants have a defined namespace.static <T> T
inheritNamespace
(org.jdom2.NamespaceAware reference, T child) Sets the namespace of a child node and all of its descendants to the namespace of reference, but only if none of the child or its descendants has a defined namespace.static List<org.jdom2.NamespaceAware>
recurse
(org.jdom2.NamespaceAware root) Returns all elements and attributes below the root, including the root itself.static org.jdom2.Parent
setStringOrElement
(org.jdom2.Parent parent, Object content, boolean nsInherit) Sets the content of a JDOM node, automatically coverting XML-like strings to JDOM elements.static org.jdom2.Parent
setStringOrElement
(org.jdom2.Parent parent, Collection<?> content, boolean nsInherit) Sets the content of a JDOM node, automatically coverting XML-like strings to JDOM elements.
-
Method Details
-
inheritNamespace
public static <T> T inheritNamespace(org.jdom2.NamespaceAware reference, T child) Sets the namespace of a child node and all of its descendants to the namespace of reference, but only if none of the child or its descendants has a defined namespace.- Type Parameters:
T
- Class of the child.- Parameters:
reference
- The reference node for the namespace.child
- The child that will recursively inherit the namspace.- Returns:
- The child, whether modified or not.
-
inheritNamespace
public static <T> Collection<T> inheritNamespace(org.jdom2.NamespaceAware reference, Collection<T> children) For each child in children: sets the namespace of a child node and all of its descendants to the namespace of reference, but only if none of the children or their descendants have a defined namespace.- Type Parameters:
T
- Class of the children.- Parameters:
reference
- The reference node for the namespace.children
- The child that will recursively inherit the namspace.- Returns:
- The childrem, whether modified or not.
-
recurse
Returns all elements and attributes below the root, including the root itself.- Parameters:
root
- The root node to recurse from.- Returns:
- The list of the sub-elements and attributes, including the root itself.
-
addStringOrElement
public static org.jdom2.Parent addStringOrElement(org.jdom2.Parent parent, Object content, boolean nsInherit) throws org.jdom2.JDOMException Adds content to a JDOM node, automatically coverting XML-like strings to JDOM elements.- Parameters:
parent
- The parent node to which the content will be added.content
- The content that will be added, either JDOMContent
orString
. The latter will be automatically converted to a JDOMElement
if it starts with "<
" and ends with ">
".nsInherit
- Controls whether the content shall inherit the parent's XML namespace according to the rules ofinheritNamespace()
.- Returns:
- The parent node, with the added content.
- Throws:
org.jdom2.JDOMException
- If your XML-like string is malformed.
-
addStringOrElement
public static org.jdom2.Parent addStringOrElement(org.jdom2.Parent parent, Collection<?> content, boolean nsInherit) throws org.jdom2.JDOMException Adds content to a JDOM node, automatically coverting XML-like strings to JDOM elements.- Parameters:
parent
- The parent node to which the content will be added.content
- The content that will be added, either JDOMContent
orString
. The latter will be automatically converted to a JDOMElement
if it starts with "<
" and ends with ">
".nsInherit
- Controls whether the content shall inherit the parent's XML namespace according to the rules ofinheritNamespace()
.- Returns:
- The parent node, with the added content.
- Throws:
org.jdom2.JDOMException
- If any of your XML-like strings are malformed.
-
setStringOrElement
public static org.jdom2.Parent setStringOrElement(org.jdom2.Parent parent, Object content, boolean nsInherit) throws org.jdom2.JDOMException Sets the content of a JDOM node, automatically coverting XML-like strings to JDOM elements.- Parameters:
parent
- The parent node whose content will be set.content
- The content that will be added, either JDOMContent
orString
. The latter will be automatically converted to a JDOMElement
if it starts with "<
" and ends with ">
".nsInherit
- Controls whether the content shall inherit the parent's XML namespace according to the rules ofinheritNamespace()
.- Returns:
- The parent node, with the altered content.
- Throws:
org.jdom2.JDOMException
- If your XML-like string is malformed.
-
setStringOrElement
public static org.jdom2.Parent setStringOrElement(org.jdom2.Parent parent, Collection<?> content, boolean nsInherit) throws org.jdom2.JDOMException Sets the content of a JDOM node, automatically coverting XML-like strings to JDOM elements.- Parameters:
parent
- The parent node whose content will be set.content
- The content that will be added, either JDOMContent
orString
. The latter will be automatically converted to a JDOMElement
if it starts with "<
" and ends with ">
".nsInherit
- Controls whether the content shall inherit the parent's XML namespace according to the rules ofinheritNamespace()
.- Returns:
- The parent node, with the altered content.
- Throws:
org.jdom2.JDOMException
- If your XML-like string is malformed.
-