List of usage examples for org.w3c.dom Text getData
public String getData() throws DOMException;
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from w w w . ja va 2 s. c om*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getDocumentElement(); Text text1 = (Text) element.getFirstChild(); String string = text1.getData(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*from w w w . j a v a 2 s .co m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getDocumentElement(); Text text1 = (Text) element.getFirstChild(); String string = text1.getData(); String word = "some"; Text text2 = text1.splitText(string.indexOf(word)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);//from ww w .java2 s .c o m factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getDocumentElement(); Text text1 = (Text) element.getFirstChild(); String string = text1.getData(); String word = "some"; Text text2 = text1.splitText(string.indexOf(word)); Element newElement = doc.createElement("b"); newElement.appendChild(text2); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);//from ww w.j a v a2 s .c om factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Element element = doc.getDocumentElement(); Text text1 = (Text) element.getFirstChild(); String string = text1.getData(); String word = "some"; Text text2 = text1.splitText(string.indexOf(word)); Element newElement = doc.createElement("b"); newElement.appendChild(text2); element.insertBefore(newElement, text2); }
From source file:Main.java
public static boolean isEmptyText(Text txt) { String s = txt.getData(); for (int i = 0; i < s.length(); ++i) { if (!Character.isWhitespace(s.charAt(i))) return false; }//from ww w . j av a2 s. c om return true; }
From source file:Main.java
public static final String getData(Node node) { Element e = (Element) node; NodeList childNodes = e.getChildNodes(); Text text = (Text) childNodes.item(0); return (text != null) ? text.getData() : ""; }
From source file:Main.java
private static String getText(Node node) { if (node == null) return null; NodeList lst = node.getChildNodes(); int size = lst.getLength(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < size; i++) { Node n = lst.item(i);/*www . j a va 2 s. c o m*/ if (n.getNodeType() == Node.TEXT_NODE) { Text t = (Text) n; sb.append(t.getData()); } } return sb.toString(); }
From source file:Main.java
public static void cleanWhiteSpaceNodes(Element node, boolean deep) { NodeList list = node.getChildNodes(); ArrayList temp = new ArrayList(); for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i);// w w w .j a va 2 s .co m short type = n.getNodeType(); if (type == 1) { Element e = (Element) n; cleanWhiteSpaceNodes(e, deep); } else if (type == 3) { Text text = (Text) n; String val = text.getData(); if (val.trim().equals("")) temp.add(text); } } for (Iterator i = temp.iterator(); i.hasNext(); node.removeChild((Node) i.next())) ; }
From source file:Main.java
License:asdf
public static void newEmail(Document doc, String newname, String newemail) { Element root = doc.getDocumentElement(); NodeList rootlist = root.getChildNodes(); for (int i = 0; i < rootlist.getLength(); i++) { Element person = (Element) rootlist.item(i); NodeList personlist = person.getChildNodes(); Element name = (Element) personlist.item(0); NodeList namelist = name.getChildNodes(); Text nametext = (Text) namelist.item(0); String oldname = nametext.getData(); if (oldname.equals(newname)) { Element email = (Element) personlist.item(1); NodeList emaillist = email.getChildNodes(); Text emailtext = (Text) emaillist.item(0); emailtext.setData(newemail); }/*from w w w . ja va2 s .c om*/ } }
From source file:Main.java
/** * Get the trimmed text of a text (simple content) element. * /*from ww w . j a v a 2 s .c o m*/ * @param e The element. * @return The text of the specified element, null if it has no text nodes. */ public static String getText(Element e) { if (e == null) return null; NodeList lst = e.getChildNodes(); int size = lst.getLength(); for (int i = 0; i < size; i++) { Node n = lst.item(i); if (n.getNodeType() == Node.TEXT_NODE) { Text t = (Text) n; String s = t.getData(); return s == null ? null : s.trim(); } } return null; }