List of utility methods to do XML Attribute from Element
boolean | getElementBooleanValue(Element element, String attribute) get Element Boolean Value return getElementBooleanValue(element, attribute, false);
|
boolean | getElementBooleanValue(Element element, String attribute, boolean defaultValue) get Element Boolean Value if (!element.hasAttribute(attribute)) return defaultValue; return Boolean.valueOf(getElementStringValue(element, attribute)); |
Element | getElementByAttr(NodeList elements, String attrName) get Element By Attr Element element = null; for (int i = 0; i < elements.getLength(); i++) { element = (Element) elements.item(i); if (element.hasAttribute(attrName)) break; return element; |
String[] | getElements(Element root, String tagName, String attrName) get Elements NodeList list = root.getElementsByTagName(tagName); String[] result = new String[list.getLength()]; for (int i = 0; i < list.getLength(); i++) { Element el = (Element) list.item(i); result[i] = (attrName == null) ? el.getNodeName() : el.getAttribute(attrName); return (result); |
List | getElementsByTagAndAttr(Element parent, String elemName, String attrName, String attrVal) get Elements By Tag And Attr List<Element> result = new ArrayList<Element>(); NodeList nl = parent.getElementsByTagName(elemName); for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) { Element elem = (Element) nl.item(i); String val = elem.getAttribute(attrName); if (val != null && val.equals(attrVal)) result.add(elem); ... |
String | getElementStringValue(Element element, String attribute) get Element String Value return element.getAttribute(attribute);
|
String | getElementStringValue(Element element, String attribute) get Element String Value return element.getAttribute(attribute);
|
String | getElementTextByAttr(Element modsroot, String nodename, String attrname, String attrvalue) Retrieves text of element by attribute value (e.g. String str = ""; NodeList list = modsroot.getElementsByTagName(nodename); for (int i = 0; i < list.getLength(); i++) { Node node = (Node) list.item(i); NamedNodeMap attrs = node.getAttributes(); Attr attr = (Attr) attrs.getNamedItem(attrname); if (attr != null) { if (attr.getValue().equals(attrvalue)) { ... |
Collection | getElementValues(final String elementName, final String attributeValue, final InputStream is) get Element Values final Collection<String> elementValues = new ArrayList<>(); final XMLEventReader xmlEventReader = XMLInputFactory.newInstance() .createXMLEventReader(new InputStreamReader(is, Charset.defaultCharset().name())); final StringBuffer characters = new StringBuffer(); boolean read = false; while (xmlEventReader.peek() != null) { final XMLEvent event = (XMLEvent) xmlEventReader.next(); switch (event.getEventType()) { ... |
String | getFirstAttribute(Element elem, String name, String attrName) Get the attribute value of a given attribute name for the first XML org.w3c.dom.Element of given name. NodeList nodeList = elem.getElementsByTagName(name); if (nodeList.getLength() == 0) { return null; return (((Element) nodeList.item(0)).getAttribute(attrName)); |