org.w3c.dom.Node.appendChild()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(546)

本文整理了Java中org.w3c.dom.Node.appendChild()方法的一些代码示例,展示了Node.appendChild()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.appendChild()方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:appendChild

Node.appendChild介绍

[英]Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.
[中]将节点newChild添加到此节点的子节点列表的末尾。如果newChild已在树中,则首先将其删除。

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public void startElement(String uri, String localName, String qName, Attributes attributes) {
  3. Node parent = getParent();
  4. Element element = this.document.createElementNS(uri, qName);
  5. for (int i = 0; i < attributes.getLength(); i++) {
  6. String attrUri = attributes.getURI(i);
  7. String attrQname = attributes.getQName(i);
  8. String value = attributes.getValue(i);
  9. if (!attrQname.startsWith("xmlns")) {
  10. element.setAttributeNS(attrUri, attrQname, value);
  11. }
  12. }
  13. element = (Element) parent.appendChild(element);
  14. this.elements.add(element);
  15. }

代码示例来源:origin: libgdx/libgdx

  1. /** If the child node doesn't exist, it is created. */
  2. private static Node getFirstChildNodeByName (Node parent, String child) {
  3. NodeList childNodes = parent.getChildNodes();
  4. for (int i = 0; i < childNodes.getLength(); i++) {
  5. if (childNodes.item(i).getNodeName().equals(child)) {
  6. return childNodes.item(i);
  7. }
  8. }
  9. Node newNode = parent.getOwnerDocument().createElement(child);
  10. if (childNodes.item(0) != null)
  11. return parent.insertBefore(newNode, childNodes.item(0));
  12. else
  13. return parent.appendChild(newNode);
  14. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public void characters(char[] ch, int start, int length) {
  3. String data = new String(ch, start, length);
  4. Node parent = getParent();
  5. Node lastChild = parent.getLastChild();
  6. if (lastChild != null && lastChild.getNodeType() == Node.TEXT_NODE) {
  7. ((Text) lastChild).appendData(data);
  8. }
  9. else {
  10. Text text = this.document.createTextNode(data);
  11. parent.appendChild(text);
  12. }
  13. }

代码示例来源:origin: stackoverflow.com

  1. public static void main(String[] args) throws Exception {
  2. DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
  3. DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
  4. Document document = documentBuilder.parse("server.xml");
  5. Element root = document.getDocumentElement();
  6. Element newServer = document.createElement("server");
  7. Element name = document.createElement("name");
  8. name.appendChild(document.createTextNode(server.getName()));
  9. newServer.appendChild(name);
  10. Element port = document.createElement("port");
  11. port.appendChild(document.createTextNode(Integer.toString(server.getPort())));
  12. newServer.appendChild(port);
  13. root.appendChild(newServer);

代码示例来源:origin: stackoverflow.com

  1. File... files) throws Exception {
  2. DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
  3. .newInstance();
  4. docBuilderFactory
  5. .setIgnoringElementContentWhitespace(true);
  6. DocumentBuilder docBuilder = docBuilderFactory
  7. .newDocumentBuilder();
  8. Document base = docBuilder.parse(files[0]);
  9. nextResults.removeChild(kid);
  10. kid = base.importNode(kid, true);
  11. results.appendChild(kid);

代码示例来源:origin: kiegroup/jbpm

  1. nl = (NodeList) exprFrom.evaluate(source, XPathConstants.NODESET);
  2. } else if (source instanceof String) {
  3. DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  4. Document doc = builder.newDocument();
  5. Element temp = doc.createElementNS(null, "temp");
  6. temp.appendChild(doc.createTextNode((String) source));
  7. nl = temp.getChildNodes();
  8. } else if (source == null) {
  9. targetElem = ((Text) nl.item(i)).getWholeText();
  10. } else {
  11. DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  12. Document doc = builder.newDocument();
  13. targetElem = doc.importNode(nl.item(i), true);
  14. ((Element) targetElem).setAttributeNode((Attr) n);
  15. } else {
  16. ((org.w3c.dom.Node) targetElem).appendChild(n);

代码示例来源:origin: robovm/robovm

  1. Element node = factory.createElement("foundJar");
  2. node.setAttribute("name", keyStr.substring(0, keyStr.indexOf("-")));
  3. node.setAttribute("desc", keyStr.substring(keyStr.indexOf("-") + 1));
  4. node.appendChild(factory.createTextNode((String)subhash.get(keyStr)));
  5. container.appendChild(node);
  6. Element node = factory.createElement("foundJar");
  7. node.appendChild(factory.createTextNode(ERROR + " Reading " + key + " threw: " + e.toString()));
  8. container.appendChild(node);

代码示例来源:origin: stackoverflow.com

  1. .newInstance();
  2. DocumentBuilder db = dbf.newDocumentBuilder();
  3. DOMImplementation domImpl = db.getDOMImplementation();
  4. Document document = buildExampleDocumentWithNamespaces(domImpl);
  5. Document document = domImpl.createDocument("urn:example.namespace",
  6. "my:example", null);
  7. Element element = document.createElementNS("http://another.namespace",
  8. "element");
  9. document.getDocumentElement().appendChild(element);
  10. return document;

代码示例来源:origin: stackoverflow.com

  1. Element root = xmlDoc.createElement("booking");
  2. item = xmlDoc.createElement("bookingID");
  3. item.appendChild(xmlDoc.createTextNode("115"));
  4. root.appendChild(item);
  5. xmlDoc.appendChild(root);

代码示例来源:origin: pmd/pmd

  1. protected void appendElement(org.w3c.dom.Node parentNode) {
  2. DocumentNavigator docNav = new DocumentNavigator();
  3. Document ownerDocument = parentNode.getOwnerDocument();
  4. if (ownerDocument == null) {
  5. // If the parentNode is a Document itself, it's ownerDocument is
  6. // null
  7. ownerDocument = (Document) parentNode;
  8. }
  9. String elementName = docNav.getElementName(this);
  10. Element element = ownerDocument.createElement(elementName);
  11. parentNode.appendChild(element);
  12. for (Iterator<Attribute> iter = docNav.getAttributeAxisIterator(this); iter.hasNext();) {
  13. Attribute attr = iter.next();
  14. element.setAttribute(attr.getName(), attr.getStringValue());
  15. }
  16. for (Iterator<Node> iter = docNav.getChildAxisIterator(this); iter.hasNext();) {
  17. AbstractNode child = (AbstractNode) iter.next();
  18. child.appendElement(element);
  19. }
  20. }

代码示例来源:origin: plutext/docx4j

  1. static class LoggingErrorListener implements ErrorListener {
  2. // See http://www.cafeconleche.org/slides/sd2003west/xmlandjava/346.html
  3. boolean strict;
  4. public LoggingErrorListener(boolean strict) {
  5. }
  6. public void warning(TransformerException exception) {
  7. log.warn(exception.getMessage(), exception);
  8. // Don't throw an exception and stop the processor
  9. // just for a warning; but do log the problem
  10. }
  11. public void error(TransformerException exception)
  12. throws TransformerException {
  13. log.error(exception.getMessage(), exception);
  14. // XSLT is not as draconian as XML. There are numerous errors
  15. // which the processor may but does not have to recover from;
  16. // e.g. multiple templates that match a node with the same
  17. // priority. If I do not want to allow that, I'd throw this
  18. // exception here.
  19. if (strict) {
  20. throw exception;
  21. }

代码示例来源:origin: apache/cloudstack

  1. private static Element configVServiceNodeDetails(Document doc, String vlanId, String ipAddr) {
  2. Element configure = doc.createElementNS(s_ciscons, "nxos:configure");
  3. Element modeConfigure = doc.createElement("nxos:" + s_configuremode);
  4. configure.appendChild(modeConfigure);
  5. Element vservice = doc.createElement("vservice");
  6. vservice.appendChild(doc.createElement("node"))
  7. .appendChild(doc.createElement("ASA_" + vlanId))
  8. .appendChild(doc.createElement("type"))
  9. .appendChild(doc.createElement("asa"));
  10. modeConfigure.appendChild(vservice);
  11. Element address = doc.createElement(s_paramvalue);
  12. address.setAttribute("isKey", "true");
  13. address.setTextContent(ipAddr);
  14. modeConfigure.appendChild(doc.createElement("ip")).appendChild(doc.createElement("address")).appendChild(doc.createElement("value")).appendChild(address);
  15. modeConfigure.appendChild(doc.createElement("adjacency"))
  16. .appendChild(doc.createElement("l2"))
  17. .appendChild(doc.createElement("vlan"))
  18. .appendChild(doc.createElement("value"))
  19. .appendChild(vlan);
  20. modeConfigure.appendChild(doc.createElement("fail-mode")).appendChild(doc.createElement("close"));

代码示例来源:origin: pentaho/pentaho-kettle

  1. DocumentBuilder builder = XMLParserFactoryProducer.createSecureDocBuilderFactory().newDocumentBuilder();
  2. data.targetDOM = builder.parse( inputSource );
  3. if ( !meta.isComplexJoin() ) {
  4. DocumentBuilder builder = XMLParserFactoryProducer.createSecureDocBuilderFactory().newDocumentBuilder();
  5. Document joinDocument = builder.parse( new InputSource( new StringReader( strJoinXML ) ) );
  6. data.targetNode.appendChild( node );
  7. } catch ( Exception e ) {
  8. throw new KettleException( e );

代码示例来源:origin: xalan/xalan

  1. public void startElement(String namespace, String localName, String qName,
  2. Attributes attrs)
  3. final Element tmp = (Element)_document.createElementNS(namespace, qName);
  4. for (int i = 0; i < nattrs; i++) {
  5. if (attrs.getLocalName(i) == null) {
  6. tmp.setAttribute(attrs.getQName(i), attrs.getValue(i));
  7. last.insertBefore(tmp, _nextSibling);
  8. else
  9. last.appendChild(tmp);

代码示例来源:origin: commons-digester/commons-digester

  1. Node previousTop = top;
  2. if ((localName == null) || (localName.length() == 0)) {
  3. top = doc.createElement(qName);
  4. } else {
  5. top = doc.createElementNS(namespaceURI, localName);
  6. previousTop.appendChild(top);
  7. depth++;
  8. } catch (DOMException e) {

代码示例来源:origin: org.apache.poi/poi-ooxml

  1. private Node createElement(Document doc, Node currentNode, String axisName) {
  2. Node selectedNode;
  3. if (isNamespaceDeclared()) {
  4. selectedNode =doc.createElementNS(getNamespace(),axisName);
  5. } else {
  6. selectedNode = doc.createElementNS("", axisName);
  7. }
  8. currentNode.appendChild(selectedNode);
  9. return selectedNode;
  10. }

代码示例来源:origin: org.apache.servicemix/servicemix-eip

  1. protected Element createChildElement(QName name, Node parent) {
  2. Document doc = parent instanceof Document ? (Document) parent : parent.getOwnerDocument();
  3. Element elem;
  4. if ("".equals(name.getNamespaceURI())) {
  5. elem = doc.createElement(name.getLocalPart());
  6. } else {
  7. elem = doc.createElementNS(name.getNamespaceURI(),
  8. name.getPrefix() + ":" + name.getLocalPart());
  9. }
  10. parent.appendChild(elem);
  11. return elem;
  12. }

代码示例来源:origin: org.semver/api

  1. /**
  2. * Add a contained class.
  3. *
  4. * @param info information about a class
  5. * @throws DiffException when there is an underlying exception, e.g.
  6. * writing to a file caused an IOException
  7. */
  8. public void contains(ClassInfo info) throws DiffException {
  9. Element tmp = doc.createElementNS(XML_URI, "class");
  10. tmp.setAttribute("name", info.getName());
  11. currentNode.appendChild(tmp);
  12. }

代码示例来源:origin: org.apache.servicemix/servicemix-core

  1. private static Element createChild(Node parent, String name, String text) {
  2. Document doc = parent instanceof Document ? (Document) parent : parent.getOwnerDocument();
  3. Element child = doc.createElementNS("http://java.sun.com/xml/ns/jbi/management-message", name);
  4. if (text != null) {
  5. child.appendChild(doc.createTextNode(text));
  6. }
  7. parent.appendChild(child);
  8. return child;
  9. }

代码示例来源:origin: geotools/geotools

  1. Element e = doc.createElementNS(uri, qName);
  2. node.appendChild(e);
  3. node = e;

相关文章