org.sakaiproject.tool.assessment.qti.util
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: XmlMapper.java 9274 2006-05-10 22:50:48Z daisyf@stanford.edu $
- Author:
- @author Ed Smiley
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ATTRIBUTE_PREFIX
public static final String ATTRIBUTE_PREFIX
- See Also:
- Constant Field Values
XmlMapper
public XmlMapper()
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
Copyright © 2005-2013 Sakai Project. All Rights Reserved.