public XMLHelper createSubNode(String subnode) { int pos = subnode.lastIndexOf(DELIM); if (pos >= 0) { XMLHelper helper = getSubNode(subnode.substring(0, pos)); return helper.createSubNode(subnode.substring(pos + 1)); } else { return new XMLHelper( (Element) element.appendChild(element.getOwnerDocument().createElement(subnode)), true); } }
private Node getTextNode() { NodeList list = element.getChildNodes(); int length = list.getLength(); for (int i = 0; i < length; i++) { Node node = list.item(i); if (node.getNodeType() == Node.TEXT_NODE) { return node; } } return element.appendChild(element.getOwnerDocument().createTextNode("")); }
public XMLHelper getSubNode(String subnode) { String nodes[] = subnode.split(REGEX); Element sub = element; boolean isnew = false; for (int i = 0; i < nodes.length; i++) { NodeList list = getImediateElementsByTagName(sub, nodes[i]); if (list.getLength() > 0) { sub = (Element) list.item(0); } else { sub = (Element) sub.appendChild(element.getOwnerDocument().createElement(nodes[i])); isnew = true; } } return new XMLHelper(sub, isnew); }
public void save(String filename) { try { Document document = element.getOwnerDocument(); document.getDocumentElement().normalize(); TransformerFactory tFactory = TransformerFactory.newInstance(); tFactory.setAttribute("indent-number", new Integer(4)); Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(document); File file = new File(filename); StreamResult result = new StreamResult(file); transformer.transform(source, result); } catch (Exception e) { severe("Could not save XML file: " + e.getMessage()); } }