List of usage examples for org.w3c.dom Element appendChild
public Node appendChild(Node newChild) throws DOMException;
newChild
to the end of the list of children of this node. From source file:com.viettel.ws.client.JDBCUtil.java
/** * Create document using DOM api//from ww w .jav a 2 s .co m * * @param rs a result set * @param doc a input document for append content * @param rsName name of the appended element * @return a document after append content * @throws ParserConfigurationException If error when parse XML string * @throws SQLException If error when read data from database */ public static Document add2Document(List<Object> rs, Document doc, String rsName) throws ParserConfigurationException, SQLException { if (rs == null) { return doc; } //Get root element Element root = doc.getDocumentElement(); Element rsElement = doc.createElement(rsName); root.appendChild(rsElement); for (Object object : rs) { Element row = createRowElement(object, doc); rsElement.appendChild(row); } return doc; }
From source file:com.nridge.core.base.std.XMLUtl.java
public static void makeElemDoubleValue(Document aDocument, Element anElement, String aName, double aValue) { Element subElement; Double doubleObject;/*www . j a v a 2 s . c o m*/ if (StringUtils.isNotEmpty(aName)) { doubleObject = aValue; subElement = aDocument.createElement(aName); subElement.appendChild(aDocument.createTextNode(doubleObject.toString())); anElement.appendChild(subElement); } }
From source file:Main.java
private static Node convertFromNamespaceForm(final Node node) { if (node instanceof Element) { final Document document = node.getOwnerDocument(); final Element newElement = document.createElementNS(null, node.getLocalName()); final NodeList children = node.getChildNodes(); for (int i = 0, n = children.getLength(); i < n; i++) { final Node oldChildNode = children.item(i); final Node newChildNode = convertFromNamespaceForm(oldChildNode); newElement.appendChild(newChildNode); }//ww w .j a va 2 s.c om final NamedNodeMap attributes = node.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { final Attr attr = (Attr) attributes.item(i); final String attrQualifiedName = attr.getNodeName(); final String attrLocalName = attr.getLocalName(); if (!attrQualifiedName.equals(XMLNS) && !attrQualifiedName.startsWith(XMLNS_COLON) && !attrLocalName.equals(XSI_SCHEMA_LOCATION_ATTR)) { newElement.setAttributeNS(null, attrLocalName, attr.getValue()); } } return newElement; } else { return node.cloneNode(true); } }
From source file:DOMEdit.java
public static void addFragment(Document doc) { Element person;/*from w w w .j av a 2 s .com*/ Element root = doc.getDocumentElement(); DocumentFragment fragment = doc.createDocumentFragment(); person = makePersonNode(doc, "Name 1", "555-4444"); fragment.appendChild(person); person = makePersonNode(doc, "Name 2", "555-9999"); fragment.appendChild(person); root.appendChild(fragment); }
From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XmlBuilder.java
private static Element buildAttributeCollection(Document doc, String localName, Collection<?> values) { Element attribute = doc.createElement(ENTRY_ATTRIBUTE_NODE); attribute.setAttribute(ENTRY_QUALIFIEDNAME, localName); for (Object value : values) { Element valueElement = doc.createElement(ENTRY_ATTRIBUTE_VALUE); valueElement.setTextContent(value.toString()); attribute.appendChild(valueElement); }// ww w.j a v a2 s . co m return attribute; }
From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XmlBuilder.java
public static Document buildEntry(QName type, String objectId, Map<QName, Serializable> properties, List<AssociationBean> list) { // Document entry = new Document(); DocumentBuilder documentBuilder = null; try {/*from w ww . j ava 2s .c om*/ documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); throw new RuntimeException("Couldn't create a document builder."); } Document doc = documentBuilder.newDocument(); Element root = doc.createElement(ENTRY_ROOTNODE); root.setAttribute(ENTRY_QUALIFIEDNAME, type.getLocalName()); root.setAttribute(ENTRY_ID, objectId); Element attributesE = buildAttributes(doc, properties); Element associationsE = buildAssociations(doc, list); root.appendChild(attributesE); root.appendChild(associationsE); doc.appendChild(root); return doc; }
From source file:com.google.visualization.datasource.render.HtmlRenderer.java
/** * Appends a simple text line to the body of the document. * * @param document The containing document. * @param bodyElement The body of the document. * @param text The text to append./*from w w w . ja v a2 s . c om*/ */ private static void appendSimpleText(Document document, Element bodyElement, String text) { Element statusElement = document.createElement("div"); statusElement.setTextContent(text); bodyElement.appendChild(statusElement); }
From source file:Main.java
/** * Given a certain parent {@link Element} and {@link Document}, append a * child {@link Element} with Tag Name (which cannot be null), Node * Attribute Name, Node Attribute Value (which both are null at the same * time or none is null at all), Node Value (which can be null). * /* w w w. j a v a 2 s . c om*/ * @param nodeTagName * Node Tag Name. * @param nodeAttributeName * Node Attribute Name. * @param nodeAttributeValue * Node Attribute Value. * @param nodeValue * Node Value. * @param elementToBeApppendedTo * Parent {@link Element} which the new created {@link Element} * will be appended to. * @param document * {@link Document} which everything belongs to. * * @return Returns the created {@link Element}. */ private static Element appendNewElementToNode(String nodeTagName, String nodeAttributeName, String nodeAttributeValue, String nodeValue, Element elementToBeApppendedTo, Document document) { // create element and append it Element element = document.createElement(nodeTagName); if ((nodeAttributeName != null) && (nodeAttributeValue != null)) { element.setAttribute(nodeAttributeName, nodeAttributeValue); } if (nodeValue != null) { element.setTextContent(nodeValue); } elementToBeApppendedTo.appendChild(element); return element; }
From source file:com.sonar.maven.it.ItUtils.java
private static Element createRepositories(Document doc) { Element repositories = doc.createElement("repositories"); Element repository = doc.createElement("repository"); Element id = doc.createElement("id"); Element url = doc.createElement("url"); id.setTextContent("sonarsource"); url.setTextContent("https://repox.sonarsource.com/sonarsource"); repositories.appendChild(repository); repository.appendChild(id);//from w w w . ja v a 2s .com repository.appendChild(url); return repositories; }
From source file:Main.java
public static Element appendNewElement(Document document, Element parent, String element, Object content, String namespace) {/*from w w w . ja v a2s . com*/ Element childElement; if (namespace != null) { childElement = document.createElementNS(namespace, element); } else { childElement = document.createElement(element); } if (content != null) { // TODO: We'll have that on Android 2.2: // childElement.setTextContent(content.toString()); // Meanwhile: childElement.appendChild(document.createTextNode(content.toString())); } parent.appendChild(childElement); return childElement; }