本文整理了Java中org.w3c.dom.Text.setNodeValue()
方法的一些代码示例,展示了Text.setNodeValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Text.setNodeValue()
方法的具体详情如下:
包路径:org.w3c.dom.Text
类名称:Text
方法名:setNodeValue
暂无
代码示例来源:origin: org.apache.commons/commons-configuration2
txtNode.setNodeValue(newValue);
代码示例来源:origin: org.jboss.jbossas/jboss-as-connector
private Element createTextNode(Document doc, String name, String value){
Text node = doc.createTextNode(name);
node.setNodeValue(String.valueOf(value));
Element child = doc.createElement(name);
child.appendChild(node);
return child;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-project-jsf
/**
* Extract nested text from an element.
* Currently does not handle coalescing text nodes, CDATA sections, etc.
* @param parent a parent element
* @return the nested text, or null if none was found
*/
private static void replaceText(Element parent, String name) {
NodeList l = parent.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
if (l.item(i).getNodeType() == Node.TEXT_NODE) {
Text text = (Text)l.item(i);
text.setNodeValue(name);
return;
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-websvc-metro-samples
/**
* Extract nested text from an element.
* Currently does not handle coalescing text nodes, CDATA sections, etc.
* @param parent a parent element
* @return the nested text, or null if none was found
*/
private static void replaceText(Element parent, String name) {
NodeList l = parent.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
if (l.item(i).getNodeType() == Node.TEXT_NODE) {
Text text = (Text)l.item(i);
text.setNodeValue(name);
return;
}
}
}
代码示例来源:origin: stackoverflow.com
...
for (int i =0; i<list.getLength();i++) {
Node node = list.item(i);
//get the salary element, and update the value
if("from".equals(node.getNodeName())){
Text text = (Text) ((Element) node).getChildNodes().item(0);
text.setNodeValue("prasad");
}
}
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("/mnt/sdcard/one.xml"));
transformer.transform(source, result);
...
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-makeproject
private static void replaceText(Element parent, String name, String regex) {
NodeList l = parent.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
if (l.item(i).getNodeType() == Node.TEXT_NODE) {
Text text = (Text) l.item(i);
if (regex != null) {
String s = text.getNodeValue();
text.setNodeValue(s.replaceAll(regex, name));
} else {
text.setNodeValue(name);
}
return;
}
}
}
代码示例来源:origin: com.ibm.sbt/com.ibm.commons.xml
public static void setTextValue(Node node, String value, boolean cdata) {
if(node!=null) {
if(node.getNodeType()==Node.ELEMENT_NODE) {
for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE && !cdata) {
((Text)child).setNodeValue(value);
return;
}
if (child.getNodeType() == Node.CDATA_SECTION_NODE && cdata) {
((Text)child).setNodeValue(value);
return;
}
}
if(node.hasChildNodes()) {
removeChildren(node);
}
Node textNode = cdata ? node.getOwnerDocument().createCDATASection(value) : node.getOwnerDocument().createTextNode(value);
node.appendChild(textNode);
} else {
node.setNodeValue(value);
}
}
}
代码示例来源:origin: stackoverflow.com
@Test
public void testXSLTTransforms () throws Exception {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element el = doc.createElement("Container");
doc.appendChild(el);
Text e = doc.createTextNode("Character");
el.appendChild(e);
//e.setNodeValue("\'");
//e.setNodeValue("\"");
e.setNodeValue("&");
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(System.out);
//This prints the original document to the command line.
transformer.transform(source, result);
InputStream xsltStream = getClass().getResourceAsStream("/characterswap.xslt");
Source xslt = new StreamSource(xsltStream);
transformer = transformerFactory.newTransformer(xslt);
//This one is the one you'd pipe to a file
transformer.transform(source, result);
}
代码示例来源:origin: com.ibm.sbt/com.ibm.commons.xml
for(Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE) {
((Text)child).setNodeValue(value);
return;
((Text)child).setNodeValue(value);
return;
代码示例来源:origin: org.objectweb.jonas/jonas-generators-wsgen
/**
* Update the security-constraint element having url-pattern equal with
* oldPattern by replacing this old pattern with the newUrlPattern
* @param oldUrlPatter url-pattern to be replaced
* @param newUrlPatterValue url-pattern to replace with
*/
public void updateSecurityConstraint(String oldUrlPatter, String newUrlPatterValue) {
NodeList nl = getElement().getElementsByTagNameNS(J2EE_NS, SECURITY_CONSTRAINT);
// loop over security constraints
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element) nl.item(i);
// look at nested url-pattern Element(s)
NodeList urlPatternCollection = e.getElementsByTagNameNS(J2EE_NS, URL_PATTERN);
for (int j = 0; j < urlPatternCollection.getLength(); j++) {
Element urlPatternElement = (Element) urlPatternCollection.item(j);
Text urlPatternText = (Text) urlPatternElement.getFirstChild();
// if found urlPattern Element, replace its value
if (urlPatternText.getNodeValue().equals(oldUrlPatter)) {
urlPatternText.setNodeValue(newUrlPatterValue);
}
}
}
}
代码示例来源:origin: org.eclipse.emf/org.eclipse.emf.codegen
/**
* Sets the template container location in the settings file
*/
protected void setContainerValue(IContainer container, Element element, String localName)
{
Element childElement = getChildWithLocalName(element, localName);
Text text = null;
for (Node node = childElement.getFirstChild(); node != null; node = node.getNextSibling())
{
if (node.getNodeType() == Node.TEXT_NODE)
{
text = (Text)node;
break;
}
}
if (text == null)
{
text = element.getOwnerDocument().createTextNode(container.getProjectRelativePath().toString());
childElement.appendChild(text);
}
else
{
text.setNodeValue(container.getProjectRelativePath().toString());
}
}
代码示例来源:origin: org.eclipse/org.eclipse.emf.codegen
/**
* Sets the template container locations in the settings file
*/
protected void setContainerValues(List<Object> containers, List<Object> sourceContainers, Element element, String localName)
{
Element childElement = getChildWithLocalName(element, localName);
Text text = null;
for (Node node = childElement.getFirstChild(); node != null; node = node.getNextSibling())
{
if (node.getNodeType() == Node.TEXT_NODE)
{
text = (Text)node;
break;
}
}
if (text == null)
{
text = element.getOwnerDocument().createTextNode(getContainers(jetProject, containers, sourceContainers));
childElement.appendChild(text);
}
else
{
text.setNodeValue(getContainers(jetProject, containers, sourceContainers));
}
}
代码示例来源:origin: org.eclipse/org.eclipse.emf.codegen
/**
* Sets the template container location in the settings file
*/
protected void setContainerValue(IContainer container, Element element, String localName)
{
Element childElement = getChildWithLocalName(element, localName);
Text text = null;
for (Node node = childElement.getFirstChild(); node != null; node = node.getNextSibling())
{
if (node.getNodeType() == Node.TEXT_NODE)
{
text = (Text)node;
break;
}
}
if (text == null)
{
text = element.getOwnerDocument().createTextNode(container.getProjectRelativePath().toString());
childElement.appendChild(text);
}
else
{
text.setNodeValue(container.getProjectRelativePath().toString());
}
}
代码示例来源:origin: org.eclipse.emf/org.eclipse.emf.codegen
/**
* Sets the template container locations in the settings file
*/
protected void setContainerValues(List<Object> containers, List<Object> sourceContainers, Element element, String localName)
{
Element childElement = getChildWithLocalName(element, localName);
Text text = null;
for (Node node = childElement.getFirstChild(); node != null; node = node.getNextSibling())
{
if (node.getNodeType() == Node.TEXT_NODE)
{
text = (Text)node;
break;
}
}
if (text == null)
{
text = element.getOwnerDocument().createTextNode(getContainers(jetProject, containers, sourceContainers));
childElement.appendChild(text);
}
else
{
text.setNodeValue(getContainers(jetProject, containers, sourceContainers));
}
}
代码示例来源:origin: org.eclipse/org.eclipse.jst.pagedesigner
/**
* Performs simple EL resolution for the child Text Node of the specified
* source Element instance.
*
* @param srcElement Source Element for which child Text Node EL resolution
* is to be performed.
*/
protected void resolveChildText(Element srcElement) {
if (srcElement != null) {
NodeList childNodes = srcElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node childNode = childNodes.item(i);
if (childNode.getNodeType() == Node.TEXT_NODE) {
Text textNode = (Text)childNode;
String textNodeValue = textNode.getNodeValue();
try {
String newTextNodeValue = (String)PageExpressionContext.getCurrent().evaluateExpression(textNodeValue, String.class, null);
if (!textNodeValue.equals(newTextNodeValue)) {
textNode.setNodeValue(newTextNodeValue);
}
} catch(Exception ex) {
//ignore - could not resolve, do not change existing value
}
}
}
}
}
代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite
retval = titleAttr.appendChild(textNode);
clonedTitle = (Attr) titleAttr.cloneNode(false);
textNode.setNodeValue("text_node_not_cloned");
value = clonedTitle.getValue();
assertEquals("attrValue", "Yesterday", value);
代码示例来源:origin: org.jboss.ws.native/jbossws-native-core
/**
* If this is a Text node then this method will set its value, otherwise it sets the value of the immediate (Text) child of this node.
* <p/>
* The value of the immediate child of this node can be set only if, there is one child node and
* that node is a Text node, or if there are no children in which case a child Text node will be created.
*
* @param value A value string
* @throws IllegalStateException if the node is not a Text node and either has more than one child node or has a child node that is not a Text node.
*/
public void setValue(String value)
{
// The Text node should overwrite setValue
if (this instanceof javax.xml.soap.Text)
throw new WSException(BundleUtils.getMessage(bundle, "IS_NOT_TEXT"));
org.w3c.dom.Node child = (org.w3c.dom.Node)getFirstChild();
if (child instanceof org.w3c.dom.Text)
((org.w3c.dom.Text)child).setNodeValue(value);
if (child == null)
{
child = domNode.getOwnerDocument().createTextNode(value);
appendChild(new TextImpl(child));
}
}
代码示例来源:origin: io.prestosql.hadoop/hadoop-apache
txtNode.setNodeValue(PropertyConverter.escapeDelimiters(
value.toString(), getListDelimiter()));
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-configuration
txtNode.setNodeValue(newValue);
代码示例来源:origin: org.apache.commons/org.motechproject.org.apache.commons.configuration
txtNode.setNodeValue(newValue);
内容来源于网络,如有侵权,请联系作者删除!