List of usage examples for org.w3c.dom Element getTextContent
public String getTextContent() throws DOMException;
From source file:Main.java
public static String firstChildTextContent(Element element, String name) { Element child = firstChild(element, name); if (child != null) { return child.getTextContent(); }//from w w w. j av a2 s . c om return null; }
From source file:Main.java
/** * Gets the value of the immediately child element by tag name under the given parent * element. If there is more than one child element, return the value of the * first one.//from ww w. ja va 2 s. com * * @param parent the parent element * @param tagName the tag name of the child element * @return value of the first child element, NULL if tag not exists */ public static String getChildElementValue(Element parent, String tagName) { Element element = getChildElement(parent, tagName); if (element != null) { return element.getTextContent(); } else { return null; } }
From source file:Main.java
/** * Loads an optional datetime element value from a XML element *///w ww . java 2s . c om public static DateTime getDateTimeNode(Element element, String name) { Element child = getSingleElement(element, name); if (child == null) return null; String value = child.getTextContent(); if (value == null) return null; if (value.length() == 0) return null; value = value.replace('T', ' ').replace("Z", ""); DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); return dtf.parseDateTime(value); }
From source file:Main.java
public static int getElementContentsAsInteger(Element element, String elementName) throws IOException { int results = 0; Element first = getFirstElement(element, elementName); if (first != null) { try {//from w w w . j a v a2s . c om results = Integer.parseInt(first.getTextContent()); } catch (NumberFormatException ex) { } } return results; }
From source file:Main.java
/** * Loads an optional Boolean element value from a XML element *///from w w w . ja va 2s.c o m public static boolean getBooleanNode(Element element, String name, boolean _default) { Element child = getSingleElement(element, name); if (child == null) return _default; String value = child.getTextContent(); if (value == null) return _default; if (value.compareTo("S") == 0) return true; if (value.compareTo("N") == 0) return false; return _default; }
From source file:Main.java
/** * Returns the text content for the child element with the specified name for the specified * element.// www . j ava2s. c om * * @param element the parent element * @param name the name of the child element to return * * @return the text content for the child element or <code>null</code> if a child element with * the specified name could not be found */ public static String getChildElementText(Element element, String name) { NodeList nodeList = element.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { Element childElement = (Element) node; if (childElement.getNodeName().equals(name)) { return childElement.getTextContent(); } } } return null; }
From source file:Main.java
public static String selectStringElement(Element parent, String elementName, String defaultVal) { Element element = selectSingleElement(parent, elementName); if (element == null) { return defaultVal; } else {//from w w w .j av a2 s .c om return element.getTextContent(); } }
From source file:uk.ac.bbsrc.tgac.miso.core.util.TaxonomyUtils.java
public static String checkScientificNameAtNCBI(String scientificName) { try {/*from w w w . java2 s . co m*/ String query = ncbiEntrezUtilsURL + "db=taxonomy&term=" + URLEncoder.encode(scientificName, "UTF-8"); final HttpClient httpclient = HttpClientBuilder.create().build(); HttpGet httpget = new HttpGet(query); try { HttpResponse response = httpclient.execute(httpget); String out = parseEntity(response.getEntity()); log.info(out); try { DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document d = docBuilder.newDocument(); TransformerFactory.newInstance().newTransformer() .transform(new StreamSource(new UnicodeReader(out)), new DOMResult(d)); NodeList nl = d.getElementsByTagName("Id"); for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); return e.getTextContent(); } } catch (ParserConfigurationException e) { log.error("check scientific name at NCBI", e); } catch (TransformerException e) { log.error("check scientific name at NCBI", e); } } catch (ClientProtocolException e) { log.error("check scientific name at NCBI", e); } catch (IOException e) { log.error("check scientific name at NCBI", e); } } catch (UnsupportedEncodingException e) { log.error("check scientific name at NCBI", e); } return null; }
From source file:org.datacleaner.util.http.HttpXmlUtils.java
public static String getText(Node node) { Element element = (Element) node; return element.getTextContent(); }
From source file:org.kitodo.sruimport.ResponseHandler.java
private static String getRecordID(Element record) { Element recordIdentifier = getXmlElement(record, RECORD_ID_TAG); return recordIdentifier.getTextContent().trim(); }