public class CollectionConverter extends Object
From DOM to Collection:
Element
is transformed into Map
.
String
values.
Map
values,
and processed recursively.
List
, which in turn contains either strings or maps.
null
.
From Collection to DOM:
Map
is converted to an element with children, where each
key in the map becomes an Element
.
String
values are turned into text nodes under the key
element.
Map
values are turned into elements recursively.
List
and Set
values are turned into repeated
elements with the same key (and may be in turn either strings or maps).
Each of the conversion functions allows the caller to specify a list of keys as a filter. If these keys are present, only the specified keys will be processed from the input.
Constructor and Description |
---|
CollectionConverter() |
Modifier and Type | Method and Description |
---|---|
static Map<String,?> |
convertToMap(Element elem,
Set<String> keyFilter)
Common conversion code for a single element, with digested filter.
|
static Map<String,?> |
convertToMap(Element elem,
String... keyFilter)
Converts a single XML element into a map.
|
static List<Map<String,?>> |
convertToMap(List<Element> elems,
String... keyFilter)
Converts a list of XML elements into a list of maps.
|
static Document |
convertToXml(Map<String,?> map,
QName rootName,
String... keyFilter)
Creates a new DOM document from the passed map, in which all elements
are members of the specified namespace and will inherit the root's
prefix (if any).
|
static Document |
convertToXml(Map<String,?> map,
String rootName,
String... keyFilter)
Creates a new DOM document from the passed map, without any namespace.
|
public static Document convertToXml(Map<String,?> map, String rootName, String... keyFilter)
map
- The source object. Its elements will be the children
of the document root.rootName
- The local name given to the root element of the
generated document.keyFilter
- If present, the mappings will be limited to child
elements with the specified names.public static Document convertToXml(Map<String,?> map, QName rootName, String... keyFilter)
map
- The source object. Its elements will be the children
of the document root.rootName
- The qualified name given to the root element of the
generated document (this is a QName
to
avoid ambiguous argument lists).keyFilter
- If present, the mappings will be limited to child
elements with the specified names.public static Map<String,?> convertToMap(Element elem, String... keyFilter)
elem
- The element.keyFilter
- If present, the mappings will be limited to child
elements with the specified names.public static List<Map<String,?>> convertToMap(List<Element> elems, String... keyFilter)
elems
- The elements.keyFilter
- If present, the mappings will be limited to child
elements with the specified names.