Author: jleroux
Date: Fri Jul 23 16:06:41 2010
New Revision: 967151
URL:
http://svn.apache.org/viewvc?rev=967151&view=revLog:
A patch from Sascha Rodekamp "Method to get a child element attribute from a specific XML file" (
https://issues.apache.org/jira/browse/OFBIZ-3874) - OFBIZ-3874
Just a good method to return a named attribute of a named child node or a default if null.
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java?rev=967151&r1=967150&r2=967151&view=diff==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilXml.java Fri Jul 23 16:06:41 2010
@@ -855,6 +855,20 @@ public class UtilXml {
return elementValue;
}
+ /** Return a named attribute of a named child node or a default if null. */
+ public static String childElementAttribute(Element element, String childElementName, String attributeName, String defaultValue) {
+ if (element == null) return defaultValue;
+ // get the value of the first element with the given name
+ Element childElement = firstChildElement(element, childElementName);
+ String elementAttribute = elementAttribute(childElement, attributeName, defaultValue);
+
+ if (UtilValidate.isEmpty(elementAttribute))
+ return defaultValue;
+ else
+ return elementAttribute;
+ }
+
+
/** Return the text (node value) of the first node under this, works best if normalized. */
public static String elementValue(Element element) {
if (element == null) return null;