Java Utililty Methods XML Attribute Set

List of utility methods to do XML Attribute Set

  1. HOME
  2. Java
  3. X
  4. XML Attribute Set

Description

The list of methods to do XML Attribute Set are organized into topic(s).

Method

String attr(Element element, String name)
Get an attribute value if it exists, or null
return attr(element, name, true);
String attr(Element element, String name)
Get an attribute value if it exists, or null
if (element.hasAttribute(name)) {
 return element.getAttribute(name);
return null;
Map attrbiuteToMap(NamedNodeMap attributes)
attrbiute To Map
if (attributes == null)
 return new LinkedHashMap<String, String>();
Map<String, String> result = new LinkedHashMap<String, String>();
for (int i = 0; i < attributes.getLength(); i++) {
 result.put(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue());
return result;
String attribute(Element element, String attrName)
attribute
Attr attr = element.getAttributeNode(attrName);
return attr != null ? attr.getValue() : null;
String attribute(Node node, String... attributes)
attribute
String value = attributeOrNull(node, attributes);
return value == null ? "" : value;
boolean attributeBooleanGet(Element e, String name, boolean defaultValue)
attribute Boolean Get
if (!e.hasAttribute(name)) {
 return defaultValue;
} else {
 return Boolean.parseBoolean(e.getAttribute(name));
void attributeBooleanSet(Element base, String name, boolean value, boolean defaultValue)
Sets an attribute on the specified element with the specified name if the specified value is different from the specified default value.
if (value != defaultValue) {
 base.setAttribute(name, Boolean.toString(value));
boolean attributeBoolValue(Element e, String attr)
attribute Bool Value
if (!e.hasAttribute(attr))
 return false;
String val = e.getAttribute(attr);
return val.equals("yes") || val.equals("true") || val.equals("1");
float attributeFloat(Node node, String attributeName)
attribute Float
return Float.parseFloat(attributeString(node, attributeName));
int attributeIntValue(Element e, String attr)
attribute Int Value
return attributeIntValue(e, attr, null);


AltStyle によって変換されたページ (->オリジナル) /