List of utility methods to do XML Attribute Read
String | getOptionalAttribute(Element elt, String name) get Optional Attribute String value = elt.getAttribute(name); if (value.equals("")) { return null; } else { return value; |
String | getOptionalAttributeValue(NamedNodeMap attrs, String name) get Optional Attribute Value Node namedItem = attrs.getNamedItem(name); if (namedItem == null) { return ""; } else { return namedItem.getTextContent(); |
String | readAttribute(Node element, String attributeName) read Attribute if (element == null) return null; NamedNodeMap attributes = element.getAttributes(); if (attributes == null) return null; Node value = attributes.getNamedItem(attributeName); if (value == null) return null; ... |
String | readAttribute(Node node, String attribute, String defaultValue) Reads the value of an attribute , returning the defaultValue string if not present.
NamedNodeMap attributes = node.getAttributes(); if (null == attributes) return defaultValue; Node attr = attributes.getNamedItem(attribute); if (null == attr) return defaultValue; return attr.getNodeValue(); |
String | readAttributeWithPrefix(Node node, String attributePrefix, String defaultValue) Reads the value of the first attribute which name matches with the specified attributePrefix .
final NamedNodeMap attributes = node.getAttributes(); if (null == attributes) { return defaultValue; Node attribute; for (int a = 0; a < attributes.getLength(); a++) { attribute = attributes.item(a); if (attribute.getNodeName().startsWith(attributePrefix)) { ... |
boolean | readBoolAttr(Element element, String attributeName) read Bool Attr String attributeValue = element.getAttribute(attributeName);
return Boolean.parseBoolean(attributeValue);
|
boolean | readBooleanAttribute(Element elem, String name, boolean defaultValue) read Boolean Attribute boolean back = defaultValue; String str = elem.getAttribute(name); if (str != null) { if (str.length() > 0) { int hash = str.hashCode(); if ((hash == "yes".hashCode()) || (hash == "true".hashCode())) { back = true; } else { ... |
boolean | readBooleanAttributeElement(final XMLStreamReader reader, final String attributeName) Read an element which contains only a single boolean attribute. requireSingleAttribute(reader, attributeName); final boolean value = Boolean.parseBoolean(reader.getAttributeValue(0)); requireNoContent(reader); return value; |
float | readFloat(Node node, String attributeName, float def) read Float try { return Float.parseFloat(node.getAttributes().getNamedItem(attributeName).getNodeValue()); } catch (Exception ex) { return def; |
float | readFloatAttribute(XMLStreamReader reader, String attributeName) read Float Attribute return Float.valueOf(reader.getAttributeValue(null, attributeName));
|