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

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

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

Node.setNodeValue介绍

[英]The value of this node, depending on its type; see the table above. When it is defined to be null, setting it has no effect, including if the node is read-only.
[中]此节点的值,取决于其类型;见上表。当定义为null时,将其设置为无效,包括节点是否为只读。

代码示例

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

  1. @Override
  2. public void setNodeValue(String nodeValue) throws DOMException {
  3. node.setNodeValue(nodeValue);
  4. }

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

  1. private static void setProperty (Document doc, Node parent, String name, String value) {
  2. Node properties = getFirstChildNodeByName(parent, "properties");
  3. Node property = getFirstChildByNameAttrValue(properties, "property", "name", name);
  4. NamedNodeMap attributes = property.getAttributes();
  5. Node valueNode = attributes.getNamedItem("value");
  6. if (valueNode == null) {
  7. valueNode = doc.createAttribute("value");
  8. valueNode.setNodeValue(value);
  9. attributes.setNamedItem(valueNode);
  10. } else {
  11. valueNode.setNodeValue(value);
  12. }
  13. }

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

  1. private static void setProperty (Document doc, Node parent, String name, String value) {
  2. Node properties = getFirstChildNodeByName(parent, "properties");
  3. Node property = getFirstChildByNameAttrValue(properties, "property", "name", name);
  4. NamedNodeMap attributes = property.getAttributes();
  5. Node valueNode = attributes.getNamedItem("value");
  6. if (valueNode == null) {
  7. valueNode = doc.createAttribute("value");
  8. valueNode.setNodeValue(value);
  9. attributes.setNamedItem(valueNode);
  10. } else {
  11. valueNode.setNodeValue(value);
  12. }
  13. }

代码示例来源:origin: groovy/groovy-core

  1. public static void setValue(Element self, String value) {
  2. Node firstChild = self.getFirstChild();
  3. if (firstChild == null) {
  4. firstChild = self.getOwnerDocument().createTextNode(value);
  5. self.appendChild(firstChild);
  6. }
  7. firstChild.setNodeValue(value);
  8. }

代码示例来源:origin: iBotPeaches/Apktool

  1. /**
  2. * Checks if the replacement was properly made to a node.
  3. *
  4. * @param file File we are searching for value
  5. * @param saved boolean on whether we need to save
  6. * @param provider Node we are attempting to replace
  7. * @return boolean
  8. * @throws AndrolibException setting node value failed
  9. */
  10. private static boolean isSaved(File file, boolean saved, Node provider) throws AndrolibException {
  11. String reference = provider.getNodeValue();
  12. String replacement = pullValueFromStrings(file.getParentFile(), reference);
  13. if (replacement != null) {
  14. provider.setNodeValue(replacement);
  15. saved = true;
  16. }
  17. return saved;
  18. }

代码示例来源:origin: iBotPeaches/Apktool

  1. /**
  2. * Replaces package value with passed packageOriginal string
  3. *
  4. * @param file File for AndroidManifest.xml
  5. * @param packageOriginal Package name to replace
  6. * @throws AndrolibException
  7. */
  8. public static void renameManifestPackage(File file, String packageOriginal) throws AndrolibException {
  9. try {
  10. Document doc = loadDocument(file);
  11. // Get the manifest line
  12. Node manifest = doc.getFirstChild();
  13. // update package attribute
  14. NamedNodeMap attr = manifest.getAttributes();
  15. Node nodeAttr = attr.getNamedItem("package");
  16. nodeAttr.setNodeValue(packageOriginal);
  17. saveDocument(file, doc);
  18. } catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
  19. }
  20. }

代码示例来源:origin: sannies/mp4parser

  1. private static void pushDown(Node p) {
  2. long time = 0;
  3. Node current = p;
  4. while ((current = current.getParentNode()) != null) {
  5. if (current.getAttributes() != null && current.getAttributes().getNamedItem("begin") != null) {
  6. time += toTime(current.getAttributes().getNamedItem("begin").getNodeValue());
  7. }
  8. }
  9. if (p.getAttributes() != null && p.getAttributes().getNamedItem("begin") != null) {
  10. p.getAttributes().getNamedItem("begin").setNodeValue(toTimeExpression(time + toTime(p.getAttributes().getNamedItem("begin").getNodeValue())));
  11. }
  12. if (p.getAttributes() != null && p.getAttributes().getNamedItem("end") != null) {
  13. p.getAttributes().getNamedItem("end").setNodeValue(toTimeExpression(time + toTime(p.getAttributes().getNamedItem("end").getNodeValue())));
  14. }
  15. }

代码示例来源:origin: sannies/mp4parser

  1. public static void changeTime(Node p, String attribute, long amount) {
  2. if (p.getAttributes() != null && p.getAttributes().getNamedItem(attribute) != null) {
  3. String oldValue = p.getAttributes().getNamedItem(attribute).getNodeValue();
  4. long nuTime = toTime(oldValue) + amount;
  5. int frames = 0;
  6. if (oldValue.contains(".")) {
  7. frames = -1;
  8. } else {
  9. // todo more precision! 44 ~= 23 frames per second.
  10. // that should be ok for non high framerate content
  11. // actually I'd have to get the ttp:frameRateMultiplier
  12. // and the ttp:frameRate attribute to calculate at which frame to show the sub
  13. frames = (int) (nuTime - (nuTime / 1000) * 1000) / 44;
  14. }
  15. p.getAttributes().getNamedItem(attribute).setNodeValue(toTimeExpression(nuTime, frames));
  16. }
  17. }

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

  1. protected void setTextcontent(Node root, String text) {
  2. Node textNode = findTextNode(root);
  3. if (textNode != null) {
  4. //Apache FOP may remove any leading/trailing spaces if
  5. //a page-number-citation is at the end of a paragraph
  6. //for this reson change the first/last one to a non breaking space.
  7. if (text.charAt(text.length() - 1) == ' ') {
  8. text = text.substring(0, text.length() - 1) + (char)160;
  9. }
  10. if (text.charAt(0) == ' ') {
  11. if (text.length() > 1) {
  12. text = (char)160 + (text.substring(1));
  13. }
  14. else {
  15. text = Character.toString((char)160);
  16. }
  17. }
  18. textNode.setNodeValue(text);
  19. }
  20. }

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

  1. @Override
  2. public Node[] merge(List<Node> nodeList1, List<Node> nodeList2, List<Node> exhaustedNodes) {
  3. if (CollectionUtils.isEmpty(nodeList1) || CollectionUtils.isEmpty(nodeList2)) {
  4. return null;
  5. }
  6. Node node1 = nodeList1.get(0);
  7. Node node2 = nodeList2.get(0);
  8. Set<String> finalItems = getMergedNodeValues(node1, node2);
  9. StringBuilder sb = new StringBuilder();
  10. Iterator<String> itr = finalItems.iterator();
  11. while (itr.hasNext()) {
  12. sb.append(itr.next());
  13. if (itr.hasNext()) {
  14. sb.append(getDelimiter());
  15. }
  16. }
  17. node1.setNodeValue(sb.toString());
  18. node2.setNodeValue(sb.toString());
  19. Node[] response = new Node[nodeList2.size()];
  20. for (int j=0;j<response.length;j++){
  21. response[j] = nodeList2.get(j);
  22. }
  23. return response;
  24. }

代码示例来源:origin: sannies/mp4parser

  1. protected static List<byte[]> extractImages(Document ttml) throws XPathExpressionException, URISyntaxException, IOException {
  2. XPathFactory xPathfactory = XPathFactory.newInstance();
  3. XPath xpath = xPathfactory.newXPath();
  4. XPathExpression expr = xpath.compile("//*/@backgroundImage");
  5. NodeList nl = (NodeList) expr.evaluate(ttml, XPathConstants.NODESET);
  6. LinkedHashMap<String, String> internalNames2Original = new LinkedHashMap<String, String>();
  7. int p = 1;
  8. for (int i = 0; i < nl.getLength(); i++) {
  9. Node bgImageNode = nl.item(i);
  10. String uri = bgImageNode.getNodeValue();
  11. String ext = uri.substring(uri.lastIndexOf("."));
  12. String internalName = internalNames2Original.get(uri);
  13. if (internalName == null) {
  14. internalName = "urn:mp4parser:" + p++ + ext;
  15. internalNames2Original.put(internalName, uri);
  16. }
  17. bgImageNode.setNodeValue(internalName);
  18. }
  19. List<byte[]> images = new ArrayList<byte[]>();
  20. if (!internalNames2Original.isEmpty()) {
  21. for (Map.Entry<String, String> internalName2Original : internalNames2Original.entrySet()) {
  22. URI pic = new URI(ttml.getDocumentURI()).resolve(internalName2Original.getValue());
  23. images.add(streamToByteArray(pic.toURL().openStream()));
  24. }
  25. }
  26. return images;
  27. }

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

  1. private static void substituteSystemProperties(Node node) {
  2. Stack<NodeList> nodeLists = new Stack<>();
  3. nodeLists.push(node.getChildNodes());
  4. while (!nodeLists.isEmpty()) {
  5. NodeList nodeList = nodeLists.pop();
  6. for (int i = 0; i < nodeList.getLength(); ++i) {
  7. Node currentNode = nodeList.item(i);
  8. if (currentNode.hasChildNodes()) {
  9. nodeLists.push(currentNode.getChildNodes());
  10. }
  11. final NamedNodeMap attributes = currentNode.getAttributes();
  12. if (attributes != null) {
  13. for (int j = 0; j < attributes.getLength(); ++j) {
  14. final Node attributeNode = attributes.item(j);
  15. final String newValue = replaceProperties(attributeNode.getNodeValue());
  16. if (newValue != null) {
  17. attributeNode.setNodeValue(newValue);
  18. }
  19. }
  20. }
  21. if (currentNode.getNodeType() == Node.TEXT_NODE) {
  22. final String newValue = replaceProperties(currentNode.getNodeValue());
  23. if (newValue != null) {
  24. currentNode.setNodeValue(newValue);
  25. }
  26. }
  27. }
  28. }
  29. }

代码示例来源:origin: groovy/groovy-core

  1. private static NodeList getChildElements(Element self, String elementName) {
  2. List<Node> result = new ArrayList<Node>();
  3. NodeList nodeList = self.getChildNodes();
  4. for (int i = 0; i < nodeList.getLength(); i++) {
  5. Node node = nodeList.item(i);
  6. if (node.getNodeType() == Node.ELEMENT_NODE) {
  7. Element child = (Element) node;
  8. if ("*".equals(elementName) || child.getTagName().equals(elementName)) {
  9. result.add(child);
  10. }
  11. } else if (node.getNodeType() == Node.TEXT_NODE) {
  12. String value = node.getNodeValue();
  13. if ((!isGlobalKeepIgnorableWhitespace() && value.trim().length() == 0) || isGlobalTrimWhitespace()) {
  14. value = value.trim();
  15. }
  16. if ("*".equals(elementName) && value.length() > 0) {
  17. node.setNodeValue(value);
  18. result.add(node);
  19. }
  20. }
  21. }
  22. return new NodesHolder(result);
  23. }

代码示例来源:origin: loklak/loklak_server

  1. gceNode.appendChild(delayNode);
  2. delayNode.setNodeValue(Integer.valueOf(delayMillis / 10).toString());
  3. if (transparencyColorIndex >= 0) {
  4. Node transparencyFlagNode = gceNode.getAttributes().getNamedItem(transparencyFlagNodeName);
  5. gceNode.appendChild(transparencyFlagNode);
  6. transparencyFlagNode.setNodeValue("TRUE");
  7. Node transparencyIndexNode = gceNode.getAttributes().getNamedItem(transparencyIndexNodeName);
  8. if (transparencyIndexNode == null) {
  9. gceNode.appendChild(transparencyIndexNode);
  10. transparencyIndexNode.setNodeValue(Integer.valueOf(transparencyColorIndex).toString());

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

  1. /**
  2. * Parse the DOM tree recursively searching for text containing reference to the old sheet name and replacing it.
  3. *
  4. * @param dom the XML node in which to perform the replacement.
  5. *
  6. * Code extracted from: <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=54470">Bug 54470</a>
  7. */
  8. private void updateDomSheetReference(Node dom, final String oldName, final String newName) {
  9. String value = dom.getNodeValue();
  10. if (value != null) {
  11. // make sure the value contains the old sheet and not a similar sheet
  12. // (ex: Valid: 'Sheet1'! or Sheet1! ; NotValid: 'Sheet1Test'! or Sheet1Test!)
  13. if (value.contains(oldName+"!") || value.contains(oldName+"'!")) {
  14. XSSFName temporary = _wb.createName();
  15. temporary.setRefersToFormula(value);
  16. updateName(temporary, oldName, newName);
  17. dom.setNodeValue(temporary.getRefersToFormula());
  18. _wb.removeName(temporary);
  19. }
  20. }
  21. NodeList nl = dom.getChildNodes();
  22. for (int i = 0; i < nl.getLength(); i++) {
  23. updateDomSheetReference(nl.item(i), oldName, newName);
  24. }
  25. }

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

  1. node.setNodeValue(newNodeValue);

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

  1. @Test
  2. public void testAddedAttributes() {
  3. Node node1 = new DummyNode();
  4. node1.setNodeValue("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd");
  5. Node node2 = new DummyNode();
  6. node2.setNodeValue("http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd");
  7. Set<String> mergedVals = merge.getMergedNodeValues(node1, node2);
  8. assertArrayEquals(new String[] {"http://www.springframework.org/schema/beans",
  9. "http://www.springframework.org/schema/beans/spring-beans.xsd",
  10. "http://www.springframework.org/schema/tx",
  11. "http://www.springframework.org/schema/tx/spring-tx.xsd"}, mergedVals.toArray());
  12. }

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

  1. @Test
  2. public void testNodeAttributes() {
  3. Node node1 = new DummyNode();
  4. node1.setNodeValue("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
  5. + "\nhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-8.4.xsd"
  6. + "\nhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-9.4.xsd"
  7. + "\nhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd");
  8. Node node2 = new DummyNode();
  9. node2.setNodeValue("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd");
  10. Set<String> mergedVals = merge.getMergedNodeValues(node1, node2);
  11. assertArrayEquals(new String[] {"http://www.springframework.org/schema/beans",
  12. "http://www.springframework.org/schema/beans/spring-beans.xsd",
  13. "http://www.springframework.org/schema/tx",
  14. "http://www.springframework.org/schema/tx/spring-tx.xsd"}, mergedVals.toArray());
  15. }

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

  1. @RunTestSetup
  2. @Test
  3. public void testGeoServerReload() throws Exception {
  4. Catalog cat = getCatalog();
  5. FeatureTypeInfo lakes =
  6. cat.getFeatureTypeByName(
  7. MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
  8. assertFalse("foo".equals(lakes.getTitle()));
  9. GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader());
  10. File info = dd.findResourceFile(lakes);
  11. // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml");
  12. FileReader in = new FileReader(info);
  13. Element dom = ReaderUtils.parse(in);
  14. Element title = ReaderUtils.getChildElement(dom, "title");
  15. title.getFirstChild().setNodeValue("foo");
  16. OutputStream output = new FileOutputStream(info);
  17. try {
  18. TransformerFactory.newInstance()
  19. .newTransformer()
  20. .transform(new DOMSource(dom), new StreamResult(output));
  21. } finally {
  22. output.close();
  23. }
  24. getGeoServer().reload();
  25. lakes =
  26. cat.getFeatureTypeByName(
  27. MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
  28. assertEquals("foo", lakes.getTitle());
  29. }

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

  1. currentElement.setTextContent(value);
  2. } else {
  3. node.setNodeValue(value);

相关文章