List of usage examples for org.w3c.dom Document createTextNode
public Text createTextNode(String data);
Text
node given the specified string. From source file:Main.java
/** * Updates the specified the child node/* w ww . j ava2s . c o m*/ * * @param parent the parent node * @param nodeName the name of child node to update * @param nodeValue the new value * @return boolean true * @throws Exception */ public static boolean updateChildNodeValueByName(Document doc, Node parent, String nodeName, String nodeValue) throws Exception { Node node = findChildNodeByName(parent, nodeName); if (node == null) return false; Node firstNode = node.getFirstChild(); if (firstNode == null) { node.appendChild(doc.createTextNode(nodeValue)); } else { firstNode.setNodeValue(nodeValue); } return true; }
From source file:Main.java
public static void addHook(String hookName, String interfaceName, String identity, boolean superOverride, String superOverrideClass) { try {//from w w w . ja v a 2 s . c o m DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBldr = dFactory.newDocumentBuilder(); Document doc = dBldr.parse(new File("hooks.xml")); Element hooks = doc.getDocumentElement(); Element hook = doc.createElement("hook"); hook.setAttribute("name", hookName); Element eIdentity = doc.createElement("identity"); eIdentity.appendChild(doc.createTextNode(identity)); hook.appendChild(eIdentity); Element eInterface = doc.createElement("interface"); eInterface.appendChild(doc.createTextNode(interfaceName)); hook.appendChild(eInterface); Element eSuper = doc.createElement("super"); if (superOverride) { eSuper.appendChild(doc.createTextNode(superOverrideClass)); } else { eSuper.appendChild(doc.createTextNode("null")); } hook.appendChild(eSuper); hooks.insertBefore(hook, hooks.getLastChild()); write(doc); } catch (SAXException | IOException | ParserConfigurationException e) { e.printStackTrace(); } }
From source file:Utils.java
public static Element findElementElseCreateAndSet(Document document, Element parent, String child, String value) {// w w w . j ava 2 s. co m Element ret = null; NodeList nl = parent.getElementsByTagName(child); if (nl.getLength() == 0) { parent.appendChild(document.createElement(child)); ret = (Element) parent.getElementsByTagName(child).item(0); ret.appendChild(document.createTextNode(value)); } return ret; }
From source file:Main.java
/** * attach (append to child) RGB to the element, in the format <red>12</red> etc * @param rgb//w ww. j a va 2s . c o m * @param elem * @param doc */ public static void attachRGB(Color rgb, Element elem, Document doc) { int r = rgb.getRed(); int g = rgb.getGreen(); int b = rgb.getBlue(); //create element Element red = doc.createElement(TAG_NAME_RED); Element green = doc.createElement(TAG_NAME_GREEN); Element blue = doc.createElement(TAG_NAME_BLUE); //fill the content red.appendChild(doc.createTextNode(Integer.toString(r))); green.appendChild(doc.createTextNode(Integer.toString(g))); blue.appendChild(doc.createTextNode(Integer.toString(b))); //structure the content elem.appendChild(red); elem.appendChild(green); elem.appendChild(blue); }
From source file:net.sf.jabref.exporter.OOCalcDatabase.java
private static void addTableCell(Document doc, Element parent, String content) { Element cell = doc.createElement("table:table-cell"); Element text = doc.createElement("text:p"); Text textNode = doc.createTextNode(content); text.appendChild(textNode);//from www. ja v a2 s . c o m //text.setTextContent(content); cell.appendChild(text); parent.appendChild(cell); }
From source file:Main.java
/** * Add an element to a parent element with its value. * @param doc DOM document object/*from w w w . ja va 2 s . c om*/ * @param parentElement parent element * @param elementName name of the element * @param value text of the element */ public static void addTagValue(final Document doc, final Element parentElement, final String elementName, final String value) { if (doc == null || parentElement == null || elementName == null || value == null) { return; } Element child = doc.createElement(elementName); parentElement.appendChild(child); child.appendChild(doc.createTextNode(value)); }
From source file:DOMEdit.java
public static void append(Document doc, String name, String phone, String email) { Element personNode = doc.createElement("person"); Element nameNode = doc.createElement("name"); personNode.appendChild(nameNode); Text nametextNode = doc.createTextNode(name); nameNode.appendChild(nametextNode); Element phoneNode = doc.createElement("phone"); personNode.appendChild(phoneNode); Text phonetextNode = doc.createTextNode(phone); phoneNode.appendChild(phonetextNode); Element emailNode = doc.createElement("email"); personNode.appendChild(emailNode); Text emailtextNode = doc.createTextNode(email); emailNode.appendChild(emailtextNode); Element root = doc.getDocumentElement(); root.appendChild(personNode);//w w w . j av a 2 s . c o m }
From source file:Main.java
public static void createElementAndAppend(String name, Date value, Document doc, Element appendeeElement, String attributeName, String attributeValue) { Element newElement = null;/*from w w w.j av a 2 s.c o m*/ if (value == null) { log.info("XMLUtil.createElementAndAppend() value == null for name = " + name); newElement = doc.createElement(name); Text text = doc.createTextNode(""); newElement.appendChild(text); } else { newElement = doc.createElement(name); Text text = doc.createTextNode(sdfObj.format(value)); newElement.appendChild(text); } if (attributeName != null && !attributeName.equals("")) { newElement.setAttribute(attributeName, attributeValue); } appendeeElement.appendChild(newElement); }
From source file:com.msopentech.odatajclient.engine.data.Serializer.java
private static void xmlLink(final ODataLink link, final Writer writer) { try {/*from w ww . j a v a2 s . com*/ final DocumentBuilder builder = ODataConstants.DOC_BUILDER_FACTORY.newDocumentBuilder(); final Document doc = builder.newDocument(); final Element uri = doc.createElementNS(ODataConstants.NS_DATASERVICES, ODataConstants.ELEM_URI); uri.appendChild(doc.createTextNode(link.getLink().toASCIIString())); dom(uri, writer); } catch (Exception e) { throw new IllegalArgumentException("While serializing XML link", e); } }
From source file:com.omertron.thetvdbapi.tools.DOMHelper.java
/** * Add a child element to a parent element * * @param doc// w ww .j a va2s. c om * @param parentElement * @param elementName * @param elementValue */ public static void appendChild(Document doc, Element parentElement, String elementName, String elementValue) { Element child = doc.createElement(elementName); Text text = doc.createTextNode(elementValue); child.appendChild(text); parentElement.appendChild(child); }