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

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

本文整理了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

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

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

private static void setProperty (Document doc, Node parent, String name, String value) {
  Node properties = getFirstChildNodeByName(parent, "properties");
  Node property = getFirstChildByNameAttrValue(properties, "property", "name", name);
  NamedNodeMap attributes = property.getAttributes();
  Node valueNode = attributes.getNamedItem("value");
  if (valueNode == null) {
    valueNode = doc.createAttribute("value");
    valueNode.setNodeValue(value);
    attributes.setNamedItem(valueNode);
  } else {
    valueNode.setNodeValue(value);
  }
}

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

private static void setProperty (Document doc, Node parent, String name, String value) {
  Node properties = getFirstChildNodeByName(parent, "properties");
  Node property = getFirstChildByNameAttrValue(properties, "property", "name", name);
  NamedNodeMap attributes = property.getAttributes();
  Node valueNode = attributes.getNamedItem("value");
  if (valueNode == null) {
    valueNode = doc.createAttribute("value");
    valueNode.setNodeValue(value);
    attributes.setNamedItem(valueNode);
  } else {
    valueNode.setNodeValue(value);
  }
}

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

public static void setValue(Element self, String value) {
  Node firstChild = self.getFirstChild();
  if (firstChild == null) {
    firstChild = self.getOwnerDocument().createTextNode(value);
    self.appendChild(firstChild);
  }
  firstChild.setNodeValue(value);
}

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

/**
 * Checks if the replacement was properly made to a node.
 *
 * @param file File we are searching for value
 * @param saved boolean on whether we need to save
 * @param provider Node we are attempting to replace
 * @return boolean
 * @throws AndrolibException setting node value failed
 */
private static boolean isSaved(File file, boolean saved, Node provider) throws AndrolibException {
  String reference = provider.getNodeValue();
  String replacement = pullValueFromStrings(file.getParentFile(), reference);
  if (replacement != null) {
    provider.setNodeValue(replacement);
    saved = true;
  }
  return saved;
}

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

/**
 * Replaces package value with passed packageOriginal string
 *
 * @param file File for AndroidManifest.xml
 * @param packageOriginal Package name to replace
 * @throws AndrolibException
 */
public static void renameManifestPackage(File file, String packageOriginal) throws AndrolibException {
  try {
    Document doc = loadDocument(file);
    // Get the manifest line
    Node manifest = doc.getFirstChild();
    // update package attribute
    NamedNodeMap attr = manifest.getAttributes();
    Node nodeAttr = attr.getNamedItem("package");
    nodeAttr.setNodeValue(packageOriginal);
    saveDocument(file, doc);
  } catch (SAXException | ParserConfigurationException | IOException | TransformerException ignored) {
  }
}

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

private static void pushDown(Node p) {
  long time = 0;
  Node current = p;
  while ((current = current.getParentNode()) != null) {
    if (current.getAttributes() != null && current.getAttributes().getNamedItem("begin") != null) {
      time += toTime(current.getAttributes().getNamedItem("begin").getNodeValue());
    }
  }
  if (p.getAttributes() != null && p.getAttributes().getNamedItem("begin") != null) {
    p.getAttributes().getNamedItem("begin").setNodeValue(toTimeExpression(time + toTime(p.getAttributes().getNamedItem("begin").getNodeValue())));
  }
  if (p.getAttributes() != null && p.getAttributes().getNamedItem("end") != null) {
    p.getAttributes().getNamedItem("end").setNodeValue(toTimeExpression(time + toTime(p.getAttributes().getNamedItem("end").getNodeValue())));
  }
}

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

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

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

protected void setTextcontent(Node root, String text) {
Node textNode = findTextNode(root);
  if (textNode != null) {
    //Apache FOP may remove any leading/trailing spaces if 
    //a page-number-citation is at the end of a paragraph
    //for this reson change the first/last one to a non breaking space.
    if (text.charAt(text.length() - 1) == ' ') {
      text = text.substring(0, text.length() - 1) + (char)160;
    }
    if (text.charAt(0) == ' ') {
      if (text.length() > 1) {
        text = (char)160 + (text.substring(1));
      }
      else {
        text = Character.toString((char)160);
      }
    }
    textNode.setNodeValue(text);
  }
}

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

@Override
public Node[] merge(List<Node> nodeList1, List<Node> nodeList2, List<Node> exhaustedNodes) {
  if (CollectionUtils.isEmpty(nodeList1) || CollectionUtils.isEmpty(nodeList2)) {
    return null;
  }
  Node node1 = nodeList1.get(0);
  Node node2 = nodeList2.get(0);
  Set<String> finalItems = getMergedNodeValues(node1, node2);
  StringBuilder sb = new StringBuilder();
  Iterator<String> itr = finalItems.iterator();
  while (itr.hasNext()) {
    sb.append(itr.next());
    if (itr.hasNext()) {
      sb.append(getDelimiter());
    }
  }
  node1.setNodeValue(sb.toString());
  node2.setNodeValue(sb.toString());
  Node[] response = new Node[nodeList2.size()];
  for (int j=0;j<response.length;j++){
    response[j] = nodeList2.get(j);
  }
  return response;
}

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

protected static List<byte[]> extractImages(Document ttml) throws XPathExpressionException, URISyntaxException, IOException {
  XPathFactory xPathfactory = XPathFactory.newInstance();
  XPath xpath = xPathfactory.newXPath();
  XPathExpression expr = xpath.compile("//*/@backgroundImage");
  NodeList nl = (NodeList) expr.evaluate(ttml, XPathConstants.NODESET);
  LinkedHashMap<String, String> internalNames2Original = new LinkedHashMap<String, String>();
  int p = 1;
  for (int i = 0; i < nl.getLength(); i++) {
    Node bgImageNode = nl.item(i);
    String uri = bgImageNode.getNodeValue();
    String ext = uri.substring(uri.lastIndexOf("."));
    String internalName = internalNames2Original.get(uri);
    if (internalName == null) {
      internalName = "urn:mp4parser:" + p++ + ext;
      internalNames2Original.put(internalName, uri);
    }
    bgImageNode.setNodeValue(internalName);
  }
  List<byte[]> images = new ArrayList<byte[]>();
  if (!internalNames2Original.isEmpty()) {
    for (Map.Entry<String, String> internalName2Original : internalNames2Original.entrySet()) {
      URI pic = new URI(ttml.getDocumentURI()).resolve(internalName2Original.getValue());
      images.add(streamToByteArray(pic.toURL().openStream()));
    }
  }
  return images;
}

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

private static void substituteSystemProperties(Node node) {
 Stack<NodeList> nodeLists = new Stack<>();
 nodeLists.push(node.getChildNodes());
 while (!nodeLists.isEmpty()) {
  NodeList nodeList = nodeLists.pop();
  for (int i = 0; i < nodeList.getLength(); ++i) {
   Node currentNode = nodeList.item(i);
   if (currentNode.hasChildNodes()) {
    nodeLists.push(currentNode.getChildNodes());
   }
   final NamedNodeMap attributes = currentNode.getAttributes();
   if (attributes != null) {
    for (int j = 0; j < attributes.getLength(); ++j) {
     final Node attributeNode = attributes.item(j);
     final String newValue = replaceProperties(attributeNode.getNodeValue());
     if (newValue != null) {
      attributeNode.setNodeValue(newValue);
     }
    }
   }
   if (currentNode.getNodeType() == Node.TEXT_NODE) {
    final String newValue = replaceProperties(currentNode.getNodeValue());
    if (newValue != null) {
     currentNode.setNodeValue(newValue);
    }
   }
  }
 }
}

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

private static NodeList getChildElements(Element self, String elementName) {
  List<Node> result = new ArrayList<Node>();
  NodeList nodeList = self.getChildNodes();
  for (int i = 0; i < nodeList.getLength(); i++) {
    Node node = nodeList.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
      Element child = (Element) node;
      if ("*".equals(elementName) || child.getTagName().equals(elementName)) {
        result.add(child);
      }
    } else if (node.getNodeType() == Node.TEXT_NODE) {
      String value = node.getNodeValue();
      if ((!isGlobalKeepIgnorableWhitespace() && value.trim().length() == 0) || isGlobalTrimWhitespace()) {
        value = value.trim();
      }
      if ("*".equals(elementName) && value.length() > 0) {
        node.setNodeValue(value);
        result.add(node);
      }
    }
  }
  return new NodesHolder(result);
}

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

gceNode.appendChild(delayNode);
delayNode.setNodeValue(Integer.valueOf(delayMillis / 10).toString());
if (transparencyColorIndex >= 0) {
  Node transparencyFlagNode = gceNode.getAttributes().getNamedItem(transparencyFlagNodeName);
    gceNode.appendChild(transparencyFlagNode);
  transparencyFlagNode.setNodeValue("TRUE");
  Node transparencyIndexNode = gceNode.getAttributes().getNamedItem(transparencyIndexNodeName);
  if (transparencyIndexNode == null) {
    gceNode.appendChild(transparencyIndexNode);
  transparencyIndexNode.setNodeValue(Integer.valueOf(transparencyColorIndex).toString());

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

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

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

node.setNodeValue(newNodeValue);

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

@Test
public void testAddedAttributes() {
  Node node1 = new DummyNode();
  node1.setNodeValue("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd");
  Node node2 = new DummyNode();
  node2.setNodeValue("http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd");
  
  Set<String> mergedVals = merge.getMergedNodeValues(node1, node2);
  
  assertArrayEquals(new String[] {"http://www.springframework.org/schema/beans",
      "http://www.springframework.org/schema/beans/spring-beans.xsd",
      "http://www.springframework.org/schema/tx",
      "http://www.springframework.org/schema/tx/spring-tx.xsd"}, mergedVals.toArray());
}

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

@Test
public void testNodeAttributes() {
  Node node1 = new DummyNode();
  node1.setNodeValue("http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
      + "\nhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-8.4.xsd"
      + "\nhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-9.4.xsd"
      + "\nhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd");
  Node node2 = new DummyNode();
  node2.setNodeValue("http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans.xsd");
  
  Set<String> mergedVals = merge.getMergedNodeValues(node1, node2);
  
  assertArrayEquals(new String[] {"http://www.springframework.org/schema/beans",
      "http://www.springframework.org/schema/beans/spring-beans.xsd",
      "http://www.springframework.org/schema/tx",
      "http://www.springframework.org/schema/tx/spring-tx.xsd"}, mergedVals.toArray());
}

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

@RunTestSetup
@Test
public void testGeoServerReload() throws Exception {
  Catalog cat = getCatalog();
  FeatureTypeInfo lakes =
      cat.getFeatureTypeByName(
          MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
  assertFalse("foo".equals(lakes.getTitle()));
  GeoServerDataDirectory dd = new GeoServerDataDirectory(getResourceLoader());
  File info = dd.findResourceFile(lakes);
  // File info = getResourceLoader().find("featureTypes", "cite_Lakes", "info.xml");
  FileReader in = new FileReader(info);
  Element dom = ReaderUtils.parse(in);
  Element title = ReaderUtils.getChildElement(dom, "title");
  title.getFirstChild().setNodeValue("foo");
  OutputStream output = new FileOutputStream(info);
  try {
    TransformerFactory.newInstance()
        .newTransformer()
        .transform(new DOMSource(dom), new StreamResult(output));
  } finally {
    output.close();
  }
  getGeoServer().reload();
  lakes =
      cat.getFeatureTypeByName(
          MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
  assertEquals("foo", lakes.getTitle());
}

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

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

相关文章