List of usage examples for org.w3c.dom Element getFirstChild
public Node getFirstChild();
From source file:Main.java
public static String cdataValue(Element element) { if (element == null) return null; // get the first element with the given name Node node = element.getFirstChild(); if (node != null) { do {/* w w w. ja v a 2s . c o m*/ if (node.getNodeType() == Node.CDATA_SECTION_NODE) { return node.getNodeValue(); } } while ((node = node.getNextSibling()) != null); } return null; }
From source file:Main.java
public static String getElementCDATAByTagName(Element current, String name, String namespace) { Element e = getElementByTagName(current, name, namespace); if (e == null) return null; Node child = e.getFirstChild(); if (child == null) return null; return child.getNodeValue(); }
From source file:Main.java
public static List<Element> getNamedChildElements(final Element parent, final String name) { List<Element> elements = new ArrayList<Element>(); if (parent != null) { Node child = parent.getFirstChild(); while (child != null) { if ((child.getNodeType() == Node.ELEMENT_NODE) && (child.getNodeName().equals(name))) { elements.add((Element) child); }//from w ww. j a va 2s . c o m child = child.getNextSibling(); } } return elements; }
From source file:DOMEdit.java
public static void addCDATA(Document doc) { Element root = doc.getDocumentElement(); Element place = (Element) root.getFirstChild(); Element directions = (Element) place.getLastChild(); String dirtext = "cdData."; CDATASection dirdata = doc.createCDATASection(dirtext); directions.replaceChild(dirdata, directions.getFirstChild()); }//from www . j av a 2 s .c om
From source file:Main.java
public static List<Element> elements(Element root) { List<Element> L = new ArrayList<Element>(); if (root == null) return L; for (Node n1 = root.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) { if (n1.getNodeType() != Node.ELEMENT_NODE) continue; Element e2 = Element.class.cast(n1); L.add(e2);/*from w w w.j a v a 2 s .co m*/ } return L; }
From source file:Main.java
public static Element findChildElementWithAttribute(Element parent, String name, String attribute, String value) {// w ww . j a v a2 s .c om if (parent == null) { return null; } org.w3c.dom.Node ret = parent.getFirstChild(); while (ret != null && (!(ret instanceof Element) || !ret.getNodeName().equals(name) || ((Element) ret).getAttribute(attribute) == null || !((Element) ret).getAttribute(attribute).equals(value))) { ret = ret.getNextSibling(); } return (Element) ret; }
From source file:DOMEdit.java
public static void addAttribute(Document doc) { Element root = doc.getDocumentElement(); Element person = (Element) root.getFirstChild(); person.setAttribute("company", "yourCom"); }/*from w w w . ja v a 2 s . c om*/
From source file:Main.java
static public void fillHashtable(NodeList list, Hashtable<String, String> fillIn) { for (int curElemNum = 0; curElemNum < list.getLength(); curElemNum++) { if (list.item(curElemNum).getNodeType() != Node.ELEMENT_NODE) continue; Element curValue = (Element) list.item(curElemNum); String valueName = curValue.getNodeName(); String value = curValue.getFirstChild().getNodeValue(); fillIn.put(valueName, value);/*from w w w .ja v a2 s . co m*/ } }
From source file:DOMEdit.java
public static void delAttribute(Document doc) { Element root = doc.getDocumentElement(); Element person = (Element) root.getFirstChild(); person.removeAttribute("number"); person.removeAttribute("dept"); }//from w w w.jav a 2s. co m
From source file:DOMEdit.java
public static void deleteFirstElement(Document doc) { Element root = doc.getDocumentElement(); Element child = (Element) root.getFirstChild(); root.removeChild(child);/*from www. j ava2s . c o m*/ }