本文整理了Java中org.w3c.dom.Element.appendChild()
方法的一些代码示例,展示了Element.appendChild()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.appendChild()
方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:appendChild
暂无
代码示例来源:origin: apache/hive
private Element appendElement(Element parent, String name, String text) {
Document document = parent.getOwnerDocument();
Element child = document.createElement(name);
parent.appendChild(child);
if (text != null) {
Text textNode = document.createTextNode(text);
child.appendChild(textNode);
}
return child;
}
代码示例来源:origin: pmd/pmd
private Element createTextElement(String name, String value) {
Element element = document.createElementNS(RULESET_2_0_0_NS_URI, name);
Text text = document.createTextNode(value);
element.appendChild(text);
return element;
}
代码示例来源:origin: plantuml/plantuml
private void addFilter(Element filter, String name, String... data) {
final Element elt = (Element) document.createElement(name);
for (int i = 0; i < data.length; i += 2) {
elt.setAttribute(data[i], data[i + 1]);
}
filter.appendChild(elt);
}
代码示例来源:origin: apache/flink
Element conf = doc.createElement("configuration");
doc.appendChild(conf);
conf.appendChild(doc.createTextNode("\n"));
continue;
Element propNode = doc.createElement("property");
conf.appendChild(propNode);
Element nameNode = doc.createElement("name");
nameNode.appendChild(doc.createTextNode(name));
propNode.appendChild(nameNode);
Element valueNode = doc.createElement("value");
valueNode.appendChild(doc.createTextNode(value));
propNode.appendChild(valueNode);
for(String s : sources) {
Element sourceNode = doc.createElement("source");
sourceNode.appendChild(doc.createTextNode(s));
propNode.appendChild(sourceNode);
conf.appendChild(doc.createTextNode("\n"));
代码示例来源:origin: spring-projects/spring-framework
@Test
public void unmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.newDocument();
Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights");
document.appendChild(flightsElement);
Element flightElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = document.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = document.createTextNode("42");
numberElement.appendChild(text);
DOMSource source = new DOMSource(document);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
代码示例来源:origin: kiegroup/jbpm
@Test
public void testExclusiveSplitXPathAdvanced2() throws Exception {
KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced-vars-not-signaled.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.getWorkItemManager().registerWorkItemHandler("Email",
new SystemOutWorkItemHandler());
Map<String, Object> params = new HashMap<String, Object>();
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element hi = doc.createElement("hi");
Element ho = doc.createElement("ho");
hi.appendChild(ho);
Attr attr = doc.createAttribute("value");
ho.setAttributeNode(attr);
attr.setValue("a");
params.put("x", hi);
params.put("y", "Second");
ProcessInstance processInstance = ksession.startProcess(
"com.sample.test", params);
assertProcessInstanceCompleted(processInstance);
}
代码示例来源:origin: marytts/marytts
public Document createComponentXML() throws ParserConfigurationException {
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
fact.setNamespaceAware(true);
Document doc = fact.newDocumentBuilder().newDocument();
Element root = (Element) doc.appendChild(doc.createElementNS(installerNamespaceURI, "marytts-install"));
Element desc = (Element) root.appendChild(doc.createElementNS(installerNamespaceURI, getComponentTypeString()));
desc.setAttribute("locale", MaryUtils.locale2xmllang(locale));
desc.setAttribute("name", name);
desc.setAttribute("version", version);
Element descriptionElt = (Element) desc.appendChild(doc.createElementNS(installerNamespaceURI, "description"));
descriptionElt.setTextContent(description);
Element licenseElt = (Element) desc.appendChild(doc.createElementNS(installerNamespaceURI, "license"));
if (license != null) {
licenseElt.setAttribute("href", license.toString());
Element packageElt = (Element) desc.appendChild(doc.createElementNS(installerNamespaceURI, "package"));
packageElt.setAttribute("size", Integer.toString(packageSize));
packageElt.setAttribute("md5sum", packageMD5);
isFolder = true;
Element lElt = (Element) packageElt.appendChild(doc.createElementNS(installerNamespaceURI, "location"));
lElt.setAttribute("href", urlString);
lElt.setAttribute("folder", String.valueOf(isFolder));
Element filesElement = (Element) desc.appendChild(doc.createElementNS(installerNamespaceURI, "files"));
filesElement.setTextContent(installedFilesNames);
代码示例来源:origin: org.apache.poi/poi-ooxml
/**
* Use to append default types XML elements, use by the save() method.
*
* @param root
* XML parent element use to append this default type element.
* @param entry
* The values to append.
* @see #save(java.io.OutputStream)
*/
private void appendDefaultType(Element root, Entry<String, String> entry) {
Element defaultType = root.getOwnerDocument().createElementNS(TYPES_NAMESPACE_URI, DEFAULT_TAG_NAME);
defaultType.setAttribute(EXTENSION_ATTRIBUTE_NAME, entry.getKey());
defaultType.setAttribute(CONTENT_TYPE_ATTRIBUTE_NAME, entry.getValue());
root.appendChild(defaultType);
}
代码示例来源:origin: stackoverflow.com
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setIgnoringComments(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse(new File("XmlTest.xml"));
NodeList nodes = doc.getElementsByTagName("CustomerId");
Text a = doc.createTextNode("value");
Element p = doc.createElement("newNode");
p.appendChild(a);
nodes.item(0).getParentNode().insertBefore(p, nodes.item(0));
代码示例来源:origin: apache/nifi
private static void addVariable(final Element parentElement, final String variableName, final String variableValue) {
final Element variableElement = parentElement.getOwnerDocument().createElement("variable");
variableElement.setAttribute("name", variableName);
variableElement.setAttribute("value", variableValue);
parentElement.appendChild(variableElement);
}
代码示例来源:origin: apache/nifi
private void addStringElement(final Element parentElement, final String elementName, final String value) {
final Element childElement = parentElement.getOwnerDocument().createElement(elementName);
childElement.setTextContent(value);
parentElement.appendChild(childElement);
}
代码示例来源:origin: ehcache/ehcache3
private Element createServerElement(Document doc, ClusteringServiceConfiguration clusteringServiceConfiguration) {
if (!(clusteringServiceConfiguration.getConnectionSource() instanceof ConnectionSource.ServerList)) {
throw new IllegalArgumentException("When connection URL is null, source of connection MUST be of type ConnectionSource.ServerList.class");
}
ConnectionSource.ServerList servers = (ConnectionSource.ServerList)clusteringServiceConfiguration.getConnectionSource();
Element rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + CLUSTER_ELEMENT_NAME);
Element connElement = createConnectionElementWrapper(doc, clusteringServiceConfiguration);
servers.getServers().forEach(server -> {
Element serverElement = doc.createElement(TC_CLUSTERED_NAMESPACE_PREFIX + SERVER_ELEMENT_NAME);
serverElement.setAttribute(HOST_ATTRIBUTE_NAME, server.getHostName());
/*
If port is greater than 0, set the attribute. Otherwise, do not set. Default value will be taken.
*/
if (server.getPort() > 0) {
serverElement.setAttribute(PORT_ATTRIBUTE_NAME, Integer.toString(server.getPort()));
}
connElement.appendChild(serverElement);
});
rootElement.appendChild(connElement);
return rootElement;
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
/**
* appends a new Element with the given name to currentElement, sets
* currentElement to be new Element, and returns the new Element as well
*/
private Element appendElement(String name) {
Element ret = doc.createElement(name);
if (currentElement == null) {
ret.setAttribute("format_version", Integer.toString(FormatVersion.VERSION));
doc.appendChild(ret);
} else {
currentElement.appendChild(ret);
}
currentElement = ret;
return ret;
}
代码示例来源:origin: marytts/marytts
@Override
public Document createComponentXML() throws ParserConfigurationException {
Document doc = super.createComponentXML();
NodeList nodes = doc.getElementsByTagName(getComponentTypeString());
assert nodes.getLength() == 1;
Element voiceElt = (Element) nodes.item(0);
voiceElt.setAttribute("type", type);
voiceElt.setAttribute("gender", gender);
Element dependsElt = (Element) voiceElt.appendChild(doc.createElementNS(ComponentDescription.installerNamespaceURI,
"depends"));
dependsElt.setAttribute("language", dependsLanguage);
dependsElt.setAttribute("version", dependsVersion);
return doc;
}
}
代码示例来源:origin: scouter-project/scouter
private Document appendObjectType(ObjectType objType, Document doc) {
try {
Element rootElement = (Element) doc.getElementsByTagName(CounterEngine.TAG_COUNTERS).item(0);
Element typesElements = (Element) doc.getElementsByTagName(CounterEngine.TAG_TYPES).item(0);
if (rootElement == null) {
rootElement = doc.createElement(CounterEngine.TAG_COUNTERS);
doc.appendChild(rootElement);
}
if (typesElements == null) {
typesElements = doc.createElement(CounterEngine.TAG_TYPES);
rootElement.appendChild(typesElements);
}
Element objElement = doc.createElement(CounterEngine.TAG_OBJECT_TYPE);
setObjectTypeAttribute(doc, objElement, objType);
typesElements.appendChild(objElement);
} catch (Exception e) {
Logger.printStackTrace(e);
return null;
}
return doc;
}
代码示例来源:origin: apache/flink
String value = properties.getProperty(propertyName);
if (value != null) {
Element propNode = doc.createElement("property");
conf.appendChild(propNode);
Element nameNode = doc.createElement("name");
nameNode.appendChild(doc.createTextNode(propertyName));
propNode.appendChild(nameNode);
Element valueNode = doc.createElement("value");
valueNode.appendChild(doc.createTextNode(
properties.getProperty(propertyName)));
propNode.appendChild(valueNode);
Element finalNode = doc.createElement("final");
finalNode.appendChild(doc.createTextNode(
String.valueOf(finalParameters.contains(propertyName))));
propNode.appendChild(finalNode);
for(String s : sources) {
Element sourceNode = doc.createElement("source");
sourceNode.appendChild(doc.createTextNode(s));
propNode.appendChild(sourceNode);
代码示例来源:origin: osmandapp/Osmand
protected static void copyAndReplaceElement(Element oldElement, Element newElement) {
while(oldElement.getChildNodes().getLength() > 0) {
newElement.appendChild(oldElement.getChildNodes().item(0));
}
NamedNodeMap attrs = oldElement.getAttributes();
for(int i = 0; i < attrs.getLength(); i++) {
Node ns = attrs.item(i);
newElement.setAttribute(ns.getNodeName(), ns.getNodeValue());
}
((Element)oldElement.getParentNode()).replaceChild(newElement, oldElement);
}
}
代码示例来源:origin: pmd/pmd
private Element createCDATASectionElement(String name, String value) {
Element element = document.createElementNS(RULESET_2_0_0_NS_URI, name);
CDATASection cdataSection = document.createCDATASection(value);
element.appendChild(cdataSection);
return element;
}
}
代码示例来源:origin: marytts/marytts
protected MaryData createMaryDataFromText(String text, Locale locale) {
Document doc = MaryXML.newDocument();
doc.getDocumentElement().setAttribute("xml:lang", MaryUtils.locale2xmllang(locale));
doc.getDocumentElement().appendChild(doc.createTextNode(text));
MaryData md = new MaryData(MaryDataType.RAWMARYXML, locale);
md.setDocument(doc);
return md;
}
代码示例来源:origin: org.apache.poi/poi-ooxml
Element root = xmlOutDoc.createElementNS(PackageNamespaces.RELATIONSHIPS, PackageRelationship.RELATIONSHIPS_TAG_NAME);
xmlOutDoc.appendChild(root);
Element relElem = xmlOutDoc.createElementNS(PackageNamespaces.RELATIONSHIPS, PackageRelationship.RELATIONSHIP_TAG_NAME);
root.appendChild(relElem);
relElem.setAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel.getId());
relElem.setAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel.getRelationshipType());
relElem.setAttribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME, "External");
} else {
URI targetURI = rel.getTargetURI();
内容来源于网络,如有侵权,请联系作者删除!