List of usage examples for org.w3c.dom Document createElement
public Element createElement(String tagName) throws DOMException;
From source file:Main.java
/** * Adds a new element containing a CDATA section to the parent element * @param parent the parent element to add the new element to * @param namespaceURI the namespace of the added element's tag name, or null if there isn't any.. * @param tag the tag name of the new element * @param text the text of the CDATA section (if text is null or empty no CDATA section will be added). *///from w w w. j a v a 2s . c o m public static void addTextElementNS(Element parent, String namespaceURI, String tag, String text) { // Add an element with the given tag name. Document document = parent.getOwnerDocument(); Element textElement = namespaceURI != null ? document.createElementNS(namespaceURI, tag) : document.createElement(tag); parent.appendChild(textElement); if (text != null && text.length() > 0) { CDATASection cdata = createCDATASection(document, text); textElement.appendChild(cdata); } }
From source file:Main.java
public static void addHook(String hookName, String interfaceName, String identity, boolean superOverride, String superOverrideClass) { try {/*from ww w . j ava 2 s . c om*/ 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:Main.java
public static Element createElement(Document document, String nsURI, String name, Element child) { Element element = (Element) document.createElement(name); element.appendChild(child);/*from w w w . j av a 2 s. co m*/ return element; }
From source file:com.sonar.maven.it.ItUtils.java
/** * Creates a settings xml with a sonar profile, containing all the given properties * Also adds repox to continue to use QAed artifacts *///from w w w . ja v a 2s. c o m public static String createSettingsXml(Map<String, String> props) throws Exception { DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element settings = doc.createElement("settings"); Element profiles = doc.createElement("profiles"); Element profile = doc.createElement("profile"); Element id = doc.createElement("id"); id.setTextContent("sonar"); Element properties = doc.createElement("properties"); for (Map.Entry<String, String> e : props.entrySet()) { Element el = doc.createElement(e.getKey()); el.setTextContent(e.getValue()); properties.appendChild(el); } profile.appendChild(id); profile.appendChild(properties); profile.appendChild(createRepositories(doc)); profile.appendChild(createPluginRepositories(doc)); profiles.appendChild(profile); settings.appendChild(profiles); doc.appendChild(settings); Writer writer = new StringWriter(); Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.transform(new DOMSource(doc), new StreamResult(writer)); return writer.toString(); }
From source file:com.marklogic.client.test.DeleteSearchTest.java
public static void writeDoc() throws Exception { Document domDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = domDocument.createElement("root"); root.setAttribute("xml:lang", "en"); root.setAttribute("foo", "bar"); root.appendChild(domDocument.createElement("child")); root.appendChild(domDocument.createTextNode("mixed")); domDocument.appendChild(root);//from ww w.jav a2 s . c o m @SuppressWarnings("unused") String domString = ((DOMImplementationLS) DocumentBuilderFactory.newInstance().newDocumentBuilder() .getDOMImplementation()).createLSSerializer().writeToString(domDocument); XMLDocumentManager docMgr = Common.client.newXMLDocumentManager(); docMgr.write(docId, new DOMHandle().with(domDocument)); }
From source file:io.selendroid.server.model.internal.JsonXmlUtil.java
private static void buildXmlNode(JSONObject from, Element parent, Document document) { if (from == null) { return;//from www .j a v a 2s .c o m } Element node = document.createElement(extractTagName(from.optString("type"))); parent.appendChild(node); node.setAttribute("name", from.optString("name")); node.setAttribute("label", from.optString("label")); node.setAttribute("value", from.optString("value")); node.setAttribute("ref", from.optString("ref")); node.setAttribute("id", from.optString("id")); node.setAttribute("shown", from.optString("shown")); JSONObject rect = from.optJSONObject("rect"); if (rect != null) { Element rectNode = document.createElement("rect"); JSONObject size = rect.optJSONObject("size"); JSONObject origin = rect.optJSONObject("origin"); rectNode.setAttribute("x", origin.optString("x")); rectNode.setAttribute("y", origin.optString("y")); rectNode.setAttribute("height", size.optString("height")); rectNode.setAttribute("width", size.optString("width")); node.appendChild(rectNode); } JSONArray array = from.optJSONArray("children"); if (array != null) { for (int i = 0; i < array.length(); i++) { JSONObject n = array.optJSONObject(i); buildXmlNode(n, node, document); } } }
From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XmlBuilder.java
private static Element buildAssociations(Document doc, List<AssociationBean> list) { Element associationsE = doc.createElement(ENTRY_ASSOCIATIONS_NODE); for (AssociationBean associationBean : list) { Element asso = buildAssociation(doc, associationBean); associationsE.appendChild(asso); }// w w w .j a v a2 s . com return associationsE; }
From source file:Main.java
/** * createXMLDoc(String) Given a name for the root element will create and * return a org.w3c.dom.Document with the root node specified. The Document * will be based on the Document implementation as specified in the system * properties file XML_DOCUMENT_CLASS//from w w w. ja v a 2 s .co m * * @param String * rootName * @return Document * @author Peter Manta (after blatant copying of Jeff) */ public static org.w3c.dom.Document createXMLDoc(String rootName) { Class docClass = null; Document doc = null; Element root = null; try { docClass = Class.forName(XML_DOCUMENT_IMPL); doc = (Document) docClass.newInstance(); root = doc.createElement(rootName); doc.appendChild(root); } catch (Exception e) { e.printStackTrace(); } finally { } return doc; }
From source file:Main.java
public static void createOptionalChildText(Document paramDocument, Element paramElement, String paramString1, String paramString2) {//from www.j a va 2s . c o m if ((paramString2 == null) || (paramString2.length() == 0)) return; Element localElement = paramDocument.createElement(paramString1); localElement.appendChild(paramDocument.createTextNode(paramString2)); paramElement.appendChild(localElement); }
From source file:Main.java
/** * add profiles section under pomRoot//ww w . j a v a 2 s . co m * @param pomRoot * @return the profiles node */ private static Element addProfilesSection(Document document, Element root) { Node profiles = document.createElement(PROFILES_NODE_NAME); root.appendChild(profiles); return (Element) profiles; }