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

x33g5p2x  于2022-01-18 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(325)

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

Element.setTextContent介绍

暂无

代码示例

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

  1. Element node = doc_.createElement("New_Node");
  2. node.setTextContent("This is the content"); //adds content
  3. node.setAttribute("attrib", "attrib_value"); //adds an attribute

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

  1. private Node append(final Document doc, final Node parent, final String element,
  2. final String value) {
  3. final Element child = doc.createElement(element);
  4. if (value != null)
  5. child.setTextContent(value);
  6. parent.appendChild(child);
  7. return child;
  8. }

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

  1. private void addStringElement(final Element parentElement, final String elementName, final String value) {
  2. final Element childElement = parentElement.getOwnerDocument().createElement(elementName);
  3. childElement.setTextContent(value);
  4. parentElement.appendChild(childElement);
  5. }

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

  1. private void addStyle(final Element parentElement, final Map<String, String> style) {
  2. final Element element = parentElement.getOwnerDocument().createElement("styles");
  3. for (final Map.Entry<String, String> entry : style.entrySet()) {
  4. final Element styleElement = parentElement.getOwnerDocument().createElement("style");
  5. styleElement.setAttribute("name", entry.getKey());
  6. styleElement.setTextContent(entry.getValue());
  7. element.appendChild(styleElement);
  8. }
  9. parentElement.appendChild(element);
  10. }

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

  1. private Element setElementTextContent(String localName, NamespaceImpl namespace, Optional<?> property, String propertyValue) {
  2. if (!property.isPresent())
  3. return null;
  4. Element root = xmlDoc.getDocumentElement();
  5. Element elem = (Element) root.getElementsByTagNameNS(namespace.getNamespaceURI(), localName).item(0);
  6. if (elem == null) {
  7. // missing, we add it
  8. elem = xmlDoc.createElementNS(namespace.getNamespaceURI(), getQName(localName, namespace));
  9. root.appendChild(elem);
  10. }
  11. elem.setTextContent(propertyValue);
  12. return elem;
  13. }

代码示例来源:origin: org.ojbc.bundles.connectors/ojb-web-application-connector

  1. public static Element createIdentificationElementWithStructureAttrAndParent(Document doc, String parentElementName, String identificationID, String structureAttrName, String structureAttrValue) {
  2. Element parentElement = doc.createElementNS(NIEMNamespaces.NC_20_NS, parentElementName);
  3. Element identificationIDElement = doc.createElementNS(NIEMNamespaces.NC_20_NS, "IdentificationID");
  4. identificationIDElement.setTextContent(identificationID.trim());
  5. identificationIDElement.setAttributeNS(NIEMNamespaces.STRUCT_NS, structureAttrName, structureAttrValue);
  6. parentElement.appendChild(identificationIDElement);
  7. return parentElement;
  8. }

代码示例来源:origin: ehcache/ehcache3

  1. private Element createTimeoutElement(Document doc, String timeoutName, Duration timeout) {
  2. Element retElement;
  3. if (READ_TIMEOUT_ELEMENT_NAME.equals(timeoutName)) {
  4. retElement = doc.createElement(TC_CLUSTERED_NAMESPACE_PREFIX + READ_TIMEOUT_ELEMENT_NAME);
  5. } else if (WRITE_TIMEOUT_ELEMENT_NAME.equals(timeoutName)) {
  6. retElement = doc.createElement(TC_CLUSTERED_NAMESPACE_PREFIX + WRITE_TIMEOUT_ELEMENT_NAME);
  7. } else {
  8. retElement = doc.createElement(TC_CLUSTERED_NAMESPACE_PREFIX + CONNECTION_TIMEOUT_ELEMENT_NAME);
  9. }
  10. retElement.setAttribute(UNIT_ATTRIBUTE_NAME, DEFAULT_UNIT_ATTRIBUTE_VALUE);
  11. retElement.setTextContent(Long.toString(timeout.getSeconds()));
  12. return retElement;
  13. }

代码示例来源:origin: mulesoft/mule

  1. private void setTextContentElement(Element element, DslElementModel<?> elementModel, Element parentNode) {
  2. getCustomizedValue(elementModel).ifPresent(value -> {
  3. DslElementSyntax dsl = elementModel.getDsl();
  4. if (dsl.supportsChildDeclaration() && !dsl.supportsAttributeDeclaration()) {
  5. if (elementModel.getConfiguration().map(c -> c.getProperty(IS_CDATA).isPresent()).orElse(false)) {
  6. element.appendChild(doc.createCDATASection(value));
  7. } else {
  8. element.setTextContent(value);
  9. }
  10. if (parentNode != element) {
  11. parentNode.appendChild(element);
  12. }
  13. } else {
  14. parentNode.setAttribute(dsl.getAttributeName(), value);
  15. }
  16. });
  17. }

代码示例来源:origin: ehcache/ehcache3

  1. @Override
  2. protected Element createRootElement(Document doc, ResourcePool resourcePool) {
  3. Element rootElement = null;
  4. if (ClusteredResourcePoolImpl.class == resourcePool.getClass()) {
  5. rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + CLUSTERED_ELEMENT_NAME);
  6. } else if (DedicatedClusteredResourcePoolImpl.class == resourcePool.getClass()) {
  7. DedicatedClusteredResourcePoolImpl dedicatedClusteredResourcePool = (DedicatedClusteredResourcePoolImpl) resourcePool;
  8. rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + DEDICATED_ELEMENT_NAME);
  9. if (dedicatedClusteredResourcePool.getFromResource() != null) {
  10. rootElement.setAttribute(FROM_ELEMENT_NAME, dedicatedClusteredResourcePool.getFromResource());
  11. }
  12. rootElement.setAttribute(UNIT_ELEMENT_NAME, dedicatedClusteredResourcePool.getUnit().toString());
  13. rootElement.setTextContent(String.valueOf(dedicatedClusteredResourcePool.getSize()));
  14. } else if (SharedClusteredResourcePoolImpl.class == resourcePool.getClass()) {
  15. SharedClusteredResourcePoolImpl sharedClusteredResourcePool = (SharedClusteredResourcePoolImpl) resourcePool;
  16. rootElement = doc.createElementNS(getNamespace().toString(), TC_CLUSTERED_NAMESPACE_PREFIX + SHARED_ELEMENT_NAME);
  17. rootElement.setAttribute(SHARING_ELEMENT_NAME, sharedClusteredResourcePool.getSharedResourcePool());
  18. }
  19. return rootElement;
  20. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. public static Document annotationToXmlDocument(Annotation annotation) {
  2. Element dateElem = XMLUtils.createElement("DATE");
  3. dateElem.setTextContent(annotation.get(CoreAnnotations.DocDateAnnotation.class));
  4. Element textElem = annotationToTmlTextElement(annotation);
  5. Element docElem = XMLUtils.createElement("DOC");
  6. docElem.appendChild(dateElem);
  7. docElem.appendChild(textElem);
  8. // Create document and import elements into this document....
  9. Document doc = XMLUtils.createDocument();
  10. doc.appendChild(doc.importNode(docElem, true));
  11. return doc;
  12. }

代码示例来源:origin: org.ojbc.bundles.connectors/ojb-web-application-connector

  1. public static Element createSourceSystemElement(Document doc, String sourceSystemNamespace,
  2. String sourceSystemName) {
  3. Element sourceSystemElement = doc.createElementNS(sourceSystemNamespace, "SourceSystemNameText");
  4. sourceSystemElement.setTextContent(sourceSystemName);
  5. return sourceSystemElement;
  6. }

代码示例来源:origin: jphp-group/jphp

  1. @Override
  2. public void run(Debugger context, CommandArguments args, Document document) {
  3. Element init = document.createElement("init");
  4. init.setAttribute("xmlns", "urn:debugger_protocol_v1");
  5. init.setAttribute("fileuri", this.fileUri);
  6. init.setAttribute("language", this.language);
  7. init.setAttribute("protocol_version", this.protocolVersion);
  8. init.setAttribute("appid", this.appId);
  9. init.setAttribute("idekey", this.ideKey);
  10. Element engine = document.createElement("engine");
  11. engine.setAttribute("version", Information.CORE_VERSION);
  12. engine.setTextContent("JPHP Debugger");
  13. init.appendChild(engine);
  14. Element author = document.createElement("author");
  15. author.setTextContent("JPHP Group");
  16. init.appendChild(author);
  17. Element url = document.createElement("url");
  18. url.setTextContent("http://j-php.net");
  19. init.appendChild(url);
  20. Element copyright = document.createElement("copyright");
  21. copyright.setTextContent("Copyright (c) 2015 by JPHP Group");
  22. init.appendChild(copyright);
  23. document.appendChild(init);
  24. }

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

  1. private static void addTextElement(final Element element, final String name, final Optional<String> value) {
  2. if (!value.isPresent()) {
  3. return;
  4. }
  5. final Document doc = element.getOwnerDocument();
  6. final Element toAdd = doc.createElement(name);
  7. toAdd.setTextContent(CharacterFilterUtils.filterInvalidXmlCharacters(value.get())); // value should already be filtered, but just in case ensure there are no invalid xml characters
  8. element.appendChild(toAdd);
  9. }

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

  1. org.w3c.dom.Document docContainer, DocumentFragment docfrag,
  2. String errMsg) {
  3. org.w3c.dom.Element wr = docContainer.createElementNS(Namespaces.NS_WORD12, "r");
  4. org.w3c.dom.Element wt = docContainer.createElementNS(Namespaces.NS_WORD12, "t");
  5. wt.setTextContent(errMsg);
  6. wr.appendChild(wt);
  7. } else if (sdtParent.equals("tbl")) {
  8. org.w3c.dom.Element wtr = docContainer.createElementNS(Namespaces.NS_WORD12, "tr");
  9. docfrag.appendChild(wtr);
  10. org.w3c.dom.Element wtc = docContainer.createElementNS(Namespaces.NS_WORD12, "tc");
  11. wtr.appendChild(wtc);
  12. org.w3c.dom.Element wp = docContainer.createElementNS(Namespaces.NS_WORD12, "p");
  13. wtc.appendChild(wp);
  14. wp.appendChild(wr);

代码示例来源:origin: org.talend.esb/security-common

  1. public static Element createClaimValue(String claimValue) {
  2. Element elClaims = createClaimsElement();
  3. Element elClaimValue = elClaims.getOwnerDocument().createElementNS(IDENTITY_NS_05_05, "ClaimValue");
  4. elClaimValue.setAttributeNS(null, "Uri", CLAIM_ROLE_NAME);
  5. Element elValue = elClaims.getOwnerDocument().createElementNS(IDENTITY_NS_05_05, "Value");
  6. elValue.setTextContent(claimValue);
  7. elClaimValue.appendChild(elValue);
  8. elClaims.appendChild(elClaimValue);
  9. return elClaims;
  10. }

代码示例来源:origin: ehcache/ehcache3

  1. private Element createSharedPoolElement(Document doc, String poolName, ServerSideConfiguration.Pool pool) {
  2. Element poolElement = doc.createElement(TC_CLUSTERED_NAMESPACE_PREFIX + SHARED_POOL_ELEMENT_NAME);
  3. poolElement.setAttribute(NAME_ATTRIBUTE_NAME, poolName);
  4. String from = pool.getServerResource();
  5. if (from != null) {
  6. if (from.trim().length() == 0) {
  7. throw new XmlConfigurationException("Resource pool name can not be empty.");
  8. }
  9. poolElement.setAttribute(FROM_ATTRIBUTE_NAME, from);
  10. }
  11. long memoryInBytes = MemoryUnit.B.convert(pool.getSize(), MemoryUnit.B);
  12. poolElement.setAttribute(UNIT_ATTRIBUTE_NAME, MemoryUnit.B.toString());
  13. poolElement.setTextContent(Long.toString(memoryInBytes));
  14. return poolElement;
  15. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. public static Timex fromMap(String text, Map<String, String> map) {
  2. try {
  3. Element element = XMLUtils.createElement("TIMEX3");
  4. for (Map.Entry<String, String> entry : map.entrySet()) {
  5. if (entry.getValue() != null) {
  6. element.setAttribute(entry.getKey(), entry.getValue());
  7. }
  8. }
  9. element.setTextContent(text);
  10. return new Timex(element);
  11. } catch (Exception ex) {
  12. throw new RuntimeException(ex);
  13. }
  14. }

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

  1. @Test
  2. public void writeDOMSource() throws Exception {
  3. DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
  4. documentBuilderFactory.setNamespaceAware(true);
  5. Document document = documentBuilderFactory.newDocumentBuilder().newDocument();
  6. Element rootElement = document.createElement("root");
  7. document.appendChild(rootElement);
  8. rootElement.setTextContent("Hello World");
  9. DOMSource domSource = new DOMSource(document);
  10. MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
  11. converter.write(domSource, null, outputMessage);
  12. assertThat("Invalid result", outputMessage.getBodyAsString(StandardCharsets.UTF_8),
  13. isSimilarTo("<root>Hello World</root>"));
  14. assertEquals("Invalid content-type", new MediaType("application", "xml"),
  15. outputMessage.getHeaders().getContentType());
  16. assertEquals("Invalid content-length", outputMessage.getBodyAsBytes().length,
  17. outputMessage.getHeaders().getContentLength());
  18. }

代码示例来源:origin: org.ow2.petals/jbi-adapter-impl

  1. private static final Element addElement(Document document, Node parentNode,
  2. String namespaceUri, String qualifiedName, String value, Map<String, String> attributes) {
  3. Element newElement = document.createElementNS(namespaceUri, qualifiedName);
  4. if (value != null) {
  5. newElement.setTextContent(value);
  6. }
  7. for (String attributeName : attributes.keySet()) {
  8. newElement.setAttribute(attributeName, attributes.get(attributeName));
  9. }
  10. parentNode.appendChild(newElement);
  11. return newElement;
  12. }

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

  1. Element newB = document.createElement("B");
  2. Element newC = document.createElement("c");
  3. newC.setTextContent("11");
  4. Element newD = document.createElement("d");
  5. newD.setTextContent("21");
  6. Element newE = document.createElement("e");
  7. newE.setTextContent("31");
  8. newB.appendChild(newC);
  9. newB.appendChild(newD);
  10. newB.appendChild(newE);
  11. document.getDocumentElement().appendChild(newB);

相关文章