List of utility methods to do XML Element Get Value
String | getValueFromElement(Element element, String tagName) Gets the string value of the tag element name passed NodeList elementNodeList = element.getElementsByTagName(tagName); if (elementNodeList == null) { return ""; } else { Element tagElement = (Element) elementNodeList.item(0); if (tagElement == null) { return ""; NodeList tagNodeList = tagElement.getChildNodes(); if (tagNodeList == null || tagNodeList.getLength() == 0) { return ""; return tagNodeList.item(0).getNodeValue(); |
String | getValueFromElement(Element element, String tagName) Gets the string value of the tag element name passed try { NodeList elementNodeList = element.getElementsByTagName(tagName); Element tagElement = (Element) elementNodeList.item(0); NodeList tagNodeList = tagElement.getChildNodes(); return ((Node) tagNodeList.item(0)).getNodeValue(); } catch (NullPointerException error) { return ""; |
String | getWholeText(Element element) get Whole Text StringBuilder builder = new StringBuilder(); NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Text) builder.append(((Text) node).getWholeText()); else if (node instanceof Element) builder.append(getWholeText((Element) node)); ... |
Boolean | getXmlBoolean(Element element, String name) get Xml Boolean String val = getXmlString(element, name); return Boolean.parseBoolean(val); |
String | getXMLContent(XMLEventReader reader, StartElement element, boolean decodeCharacters) get XML Content String rootElementName = getLocalName(element); StringWriter buffer = new StringWriter(1024); StartElement pendingElement = null; String pendingElementName = null; while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); if (pendingElement != null) { boolean skip = false; ... |
XmlElement | getXmlElementAnnotation(Field field) Returns the XmlElement annotation for the given field, if the annotation exists. for (Annotation annotation : field.getDeclaredAnnotations()) { if (annotation instanceof XmlElement) { return (XmlElement) annotation; return null; |
XmlElementDecl | getXmlElementDecl(Method method) Returns annotation XmlElementDecl of the given factory method XmlElementDecl ret = null; if (null == method) { throw new Exception("method is null"); XmlElementDecl xmlElementDecl = (XmlElementDecl) method.getAnnotation(XmlElementDecl.class); if (null != xmlElementDecl) { ret = xmlElementDecl; return ret; |
String | getXMLElementTextValue(Element element, String tagName) Parse the text value of the tag with the specified name. NodeList nl = element.getElementsByTagName(tagName); if (nl != null && nl.getLength() > 0) { Element el = (Element) nl.item(0); return el.getFirstChild().getNodeValue(); return null; |
String | getXMLIdentifier(Element element) Generates a unique string from the supplied element's name space URI and tag name. if (element == null) throw new NullPointerException("element"); return getQualifiedIdentifier(element.getLocalName(), element.getNamespaceURI()); |
String | getXMLText(Element element) Gets the text from an XML element String text = ""; NodeList nodeList = element.getChildNodes(); for (int index = 0; index < nodeList.getLength(); index++) { Node node = nodeList.item(index); if (node.getNodeType() == Node.TEXT_NODE) text += node.getNodeValue(); else text += getXMLText((Element) node); ... |