Class XmlMapper
- java.lang.Object
-
- org.sakaiproject.tool.assessment.qti.util.XmlMapper
-
public class XmlMapper extends Object
Utility class. Maps XML elements and attribute under a given node to a Map, or populates bean. Note this now supports deep copy.- Version:
- $Id$
- Author:
- , Ed Smiley
-
-
Field Summary
Fields Modifier and Type Field Description static StringATTRIBUTE_PREFIX
-
Constructor Summary
Constructors Constructor Description XmlMapper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Mapmap(Document doc)Maps each element node and attribute under a given node to a Map.static voidpopulateBeanFromDoc(Serializable bean, Document doc)Maps each element node to a bean property.
-
-
-
Field Detail
-
ATTRIBUTE_PREFIX
public static final String ATTRIBUTE_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
map
public static Map map(Document doc)
Maps each element node and attribute under a given node to a Map. It associates each element's text value with its name, and each attribute value with a key of "attribute_" + the attribute name. If node is a document it processes it as if it were the root node. If there are multiple nodes with the same element name they will be stored in a List. NOTE: This was DESIGNED to ignore elements at more depth than root +1. It has now been modified to deep copy under the nodes, but it WILL NOT recurse and assign key value pairs below, this is by design. The elements below (e.g. XML snippets, XHTML text) are all put into the value.- Parameters:
node- Nodeindent- String- Returns:
- HashMap
-
populateBeanFromDoc
public static void populateBeanFromDoc(Serializable bean, Document doc)
Maps each element node to a bean property. Supports only simple types such as String, int and long, plus Lists. If node is a document it processes it as if it were the root node. If there are multiple nodes with the same element name they will be stored in a List. NOTE: This is DESIGNED to ignore elements at more depth so that simple String key value pairs are used. This WILL NOT recurse to more depth, by design. If it did so, you would have to use maps of maps.- Parameters:
bean- Serializable object which has the appropriate setters/gettersdoc- the document
-
-