List of usage examples for org.w3c.dom Node getNodeValue
public String getNodeValue() throws DOMException;
From source file:Main.java
static String getAttributeValue(final Node node, final String attributeName) { if (node == null || attributeName == null) { return null; }/* ww w.ja v a2s . c o m*/ final NamedNodeMap attrMap = node.getAttributes(); final Node attrNode = attrMap.getNamedItem(attributeName); if (attrNode != null) { return attrNode.getNodeValue(); } return null; }
From source file:Main.java
public static void deepCopyDocument(Document ttml, File target) throws IOException { try {/* ww w .j a v a2 s . co m*/ XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile("//*/@backgroundImage"); NodeList nl = (NodeList) expr.evaluate(ttml, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) { Node backgroundImage = nl.item(i); URI backgroundImageUri = URI.create(backgroundImage.getNodeValue()); if (!backgroundImageUri.isAbsolute()) { copyLarge(new URI(ttml.getDocumentURI()).resolve(backgroundImageUri).toURL().openStream(), new File(target.toURI().resolve(backgroundImageUri).toURL().getFile())); } } copyLarge(new URI(ttml.getDocumentURI()).toURL().openStream(), target); } catch (XPathExpressionException e) { throw new IOException(e); } catch (URISyntaxException e) { throw new IOException(e); } }
From source file:Main.java
public static String getElementValue(Element inElement) { if (null == inElement) return null; Node wkFirstChild = inElement.getFirstChild(); if (null == wkFirstChild) return ""; else/* ww w . ja v a2 s.c o m*/ return wkFirstChild.getNodeValue(); }
From source file:Main.java
/** Gets the text information associated with the given DOM element. */ public static String getText(final Element el) { final NodeList nodes = el.getChildNodes(); final int len = nodes.getLength(); for (int i = 0; i < len; i++) { final Node node = nodes.item(i); if ("#text".equals(node.getNodeName())) return node.getNodeValue(); }/*w w w . j av a2 s .co m*/ return null; }
From source file:Main.java
public static String getNodeValue(Node node) { String value = null;//from w w w.j a va2 s . com if (node != null) { value = node.getNodeValue(); if (value == null) { value = node.getTextContent(); } } return value; }
From source file:Main.java
public static String getTagValue(String sTag, Element eElement) { if (eElement == null) { return null; }/*w w w .java 2 s .co m*/ NodeList aNodeList = eElement.getElementsByTagName(sTag); if (aNodeList == null) { return null; } Node aNode = aNodeList.item(0); if (aNode == null) { return null; } NodeList nlList = aNode.getChildNodes(); Node nValue = (Node) nlList.item(0); if (nValue == null) { return null; } return nValue.getNodeValue(); }
From source file:Main.java
public static String getNodeValue(Node node) { if (node == null) { return null; }/*from w w w . ja v a 2 s. co m*/ NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); } } return null; }
From source file:Main.java
public static String getAttribute(Node node, String name) { if (node == null) { return null; }/*from www .java 2 s . co m*/ Node val = node.getAttributes().getNamedItem(name); if (val == null) { return null; } return val.getNodeValue(); }
From source file:Main.java
public static String getTextTag(Node node, String tagName) { Element elem = (Element) node; NodeList list = elem.getElementsByTagName(tagName); if (list.getLength() == 0) return null; Node child = list.item(0).getFirstChild(); if (child.getNodeType() == Node.TEXT_NODE) return child.getNodeValue(); return null;/* w w w . ja v a2s.co m*/ }
From source file:Main.java
public static Map<String, String> findAttributesValues(Node node) { Map<String, String> retval = new HashMap<String, String>(); NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { Node attr = attrs.item(i); String name = attr.getNodeName(); String value = attr.getNodeValue(); retval.put(name, value);//from w w w . ja va2 s . c o m } } return retval; }