@SuppressWarnings("unchecked")
public static void addToNamedList(Node nd, NamedList nlst, List arr) {
// Nodes often include whitespace, etc... so just return if this
// is not an Element.
if (nd.getNodeType() != Node.ELEMENT_NODE) return;
String type = nd.getNodeName();
String name = null;
if (nd.hasAttributes()) {
NamedNodeMap attrs = nd.getAttributes();
Node nameNd = attrs.getNamedItem("name");
if (nameNd != null) name=nameNd.getNodeValue();
}
Object val=null;
if ("str".equals(type)) {
val = getText(nd);
} else if ("int".equals(type)) {
val = Integer.valueOf(getText(nd));
} else if ("long".equals(type)) {
val = Long.valueOf(getText(nd));
} else if ("float".equals(type)) {
val = Float.valueOf(getText(nd));
} else if ("double".equals(type)) {
val = Double.valueOf(getText(nd));
} else if ("bool".equals(type)) {
val = StrUtils.parseBool(getText(nd));
} else if ("lst".equals(type)) {
val = childNodesToNamedList(nd);
} else if ("arr".equals(type)) {
val = childNodesToList(nd);
}
if (nlst != null) nlst.add(name,val);
if (arr != null) arr.add(val);
}