本文整理匯總了Java中org.w3c.dom.Node.setTextContent方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.setTextContent方法的具體用法?Java Node.setTextContent怎麽用?Java Node.setTextContent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.setTextContent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setPropsForCompile
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Description: Editing the xml file for compiling projects.
* @param init path to the xml file
* @param build path to the build directory
* @param src path to the source directory
*/
public static void setPropsForCompile(String init ,String build, String src) {
try {
String filepath = init;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);
// get project
//Node project = doc.getFirstChild();
Node prop1 = doc.getElementsByTagName("property").item(0);
Node prop2 = doc.getElementsByTagName("property").item(1);
NamedNodeMap srcAttr = prop1.getAttributes();
Node srcName = srcAttr.getNamedItem("location");
srcName.setTextContent(src);
NamedNodeMap buildAttr = prop2.getAttributes();
Node buildName = buildAttr.getNamedItem("location");
buildName.setTextContent(build);
updateBuildFile( filepath, doc);
} catch (Exception exc) {}
}
示例2: encode
import org.w3c.dom.Node; //導入方法依賴的package包/類
public String encode(ResultSet rs) throws Exception {
ResultSetMetaData rsmd;
rsmd = rs.getMetaData();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element ele = doc.createElement("result");
Integer count = 0;
while(rs.next()){
count++;
Node rowNode = doc.createElement("row");
for (int i=1; i<= rsmd.getColumnCount(); i++){
Node colNode = doc.createElement(rsmd.getColumnName(i)) ;
colNode.setTextContent(rs.getObject(colNode.getNodeName()).toString());
rowNode.appendChild(colNode);
}
ele.appendChild(rowNode);
}
ele.setAttribute("size", count.toString());
doc.appendChild(ele);
return toXmlString(doc);
}
示例3: trimWhiteSpace
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void trimWhiteSpace(Node node) {
NodeList children = node.getChildNodes();
int count = children.getLength();
for (int i = 0; i < count; ++i) {
Node child = children.item(i);
if (child.getNodeType() == Node.TEXT_NODE) {
child.setTextContent(child.getTextContent().trim());
}
trimWhiteSpace(child);
}
}
示例4: updateParamValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Remove the tool's applicationContext entry from the param-value node of the context-param entry.
* Should find and remove all the matching entries (should it somehow have have got in there m
*
* @param doc
* @param children
* @param childNode
*/
@Override
protected void updateParamValue(Document doc, Node contextParamElement) {
NodeList valueChildren = contextParamElement.getChildNodes();
for (int i = 0; i < valueChildren.getLength(); i++) {
Node valueChild = valueChildren.item(i);
if (valueChild instanceof Text) {
String value = valueChild.getNodeValue();
String newValue = StringUtils.replace(value, getApplicationContextPathWithClasspath(), "");
if (newValue.length() < value.length()) {
valueChild.setTextContent(newValue);
System.out.println(
"Removed context entry " + getApplicationContextPathWithClasspath() + " from document.");
}
}
}
}
示例5: setServiceDescriptionName
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Sets the service description name.
*
* @param serviceDescriptionFile the service description file
* @param serviceName the service name
*/
private void setServiceDescriptionName(File serviceDescriptionFile) {
String newServiceName = this.getSymbolicBundleName() + "." + CLASS_LOAD_SERVICE_NAME;
try {
// --- Open the XML document ------------------
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(serviceDescriptionFile);
// --- Get the XML root/component element -----
Node component = doc.getFirstChild();
NamedNodeMap componentAttr = component.getAttributes();
Node nameAttr = componentAttr.getNamedItem("name");
nameAttr.setTextContent(newServiceName);
// --- Save document in XML file --------------
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(serviceDescriptionFile);
transformer.transform(source, result);
} catch (ParserConfigurationException pcEx) {
pcEx.printStackTrace();
} catch (SAXException saxEx) {
saxEx.printStackTrace();
} catch (IOException ioEx) {
ioEx.printStackTrace();
} catch (TransformerConfigurationException tcEx) {
tcEx.printStackTrace();
} catch (TransformerException tEx) {
tEx.printStackTrace();
}
}
示例6: setPropsForCompileFile
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Description: Editing the xml file for compiling files.
* @param init path to the xml file
* @param sourceFile path to the source to be compiled
*/
public static void setPropsForCompileFile(String init, String sourceFile) {
try {
File file = new File(sourceFile);
String filepath = init;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);
// get project
//Node project = doc.getFirstChild();
Node prop1 = doc.getElementsByTagName("property").item(0);
Node prop2 = doc.getElementsByTagName("property").item(1);
Node prop3 = doc.getElementsByTagName("property").item(2);
NamedNodeMap srcAttr = prop1.getAttributes();
Node srcName = srcAttr.getNamedItem("location");
srcName.setTextContent( file.getParent());
NamedNodeMap buildAttr = prop2.getAttributes();
Node buildName = buildAttr.getNamedItem("location");
buildName.setTextContent( file.getParent());
NamedNodeMap fileAttr = prop3.getAttributes();
Node fileName = fileAttr.getNamedItem("value");
fileName.setTextContent( file.getName());
updateBuildFile( filepath, doc);
} catch (Exception ex) {}
}
示例7: removeLastCharacter
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void removeLastCharacter(Node node) {
String value = node.getTextContent();
if (value.length() > 0) {
String textContent = value.substring(0, (value.length() - 1));
node.setTextContent(textContent);
}
}
示例8: convertException
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void convertException(SOAPMessageContext context,
String newExceptionName) throws SOAPException {
String saaSApplicationExceptionName = getSaaSApplicationExceptionName();
NodeList nodeList = context.getMessage().getSOAPBody()
.getElementsByTagName(PREFIX + newExceptionName);
if (null == nodeList) {
return;
}
Node node = nodeList.item(0);
Element newNode = node.getOwnerDocument().createElementNS(
node.getNamespaceURI(), PREFIX + saaSApplicationExceptionName);
NodeList list = node.getChildNodes();
if (null != list) {
int childrenSize = list.getLength();
for (int i = 0; i < childrenSize; i++) {
Node child = list.item(0);
if (child.getNodeName().equals(PREFIX + MESSAGEKEYTAG)) {
String content = child.getTextContent().replaceAll(
newExceptionName, saaSApplicationExceptionName);
child.setTextContent(content);
}
newNode.appendChild(child);
}
node.getParentNode().replaceChild(newNode, node);
}
}
示例9: appendLog
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void appendLog(Node parent, String log) {
if (!log.isEmpty()) {
Node pre = node("div", "preformatted");
pre.setTextContent(log);
parent.appendChild(pre);
}
}
示例10: setByPath
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void setByPath(Node doc, String path, String value) {
Node node = getNodeByPath(doc, path, true);
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
node.setNodeValue(value);
} else if (node.hasChildNodes() && node.getFirstChild().getNodeType() == Node.TEXT_NODE) {
node.getFirstChild().setTextContent(value);
} else if (node.getNodeType() == Node.ELEMENT_NODE) {
node.setTextContent(value);
}
}
示例11: setNodeValue
import org.w3c.dom.Node; //導入方法依賴的package包/類
public synchronized void setNodeValue(String xpath, Node nodeContext, String value)
{
Node node = singleNodeFromList(nodeList(xpath, nodeContext));
if( node != null )
{
node.setTextContent(value);
}
}
示例12: preProcess
import org.w3c.dom.Node; //導入方法依賴的package包/類
@Override
protected void preProcess(Document doc, Node src, Node dest) throws DocTemplateException {
NodeList childElements = src.getChildNodes();
for (int i = 0; i < childElements.getLength(); i++) {
Node childElement = childElements.item(i);
Node result = null;
boolean field = false;
// OO Field Eigenschaft kann mit "variable-get" oder "variable-set" Knotename behandlen werden.
if (childElement.getNodeName().endsWith(ODT_BOOKMARK_TAG_SUFFIX)
|| (field = childElement.getNodeName().endsWith(OO_FIELD_GET_TAG_POSTFIX) || childElement.getNodeName().endsWith(OO_FIELD_SET_TAG_POSTFIX))) {
String key = "";
// In Fall des Fields key gleich mit dem "text:name" Eigenschaft
if (field) {
key = childElement.getAttributes().getNamedItem(TEXT_NAME).getTextContent();
} else {
key = childElement.getAttributes().item(0).getTextContent();
}
// mehrere gleiche Textmarken mit ALT-Suffix intern ohne ALT-Suffix anwenden
int altPos = key.indexOf(ALTERNATE_SUFFIX);
if (altPos > 0) {
key = key.substring(0, altPos);
}
if (key != null && (key.startsWith(getFieldPrefix()) || key.startsWith(SORTFIELD_PREFIX) || key.startsWith(CONDITION_BEGIN) || key.startsWith(CONDITION_END)
|| key.startsWith(ITERATION_BEGIN) || key.startsWith(ITERATION_END)) || field) {
result = doc.createElement(INTERNAL_BOOKMARK_TAG);
// In Fall des Fields wird ein Feld mit Prefix "FIELD_" generiert. Das bedautet, wir behandlen den
// OO Field ebenso, als "FIELD_" Bookmark
result.setTextContent(field ? (getFieldPrefix() + key) : key);
}
}
if (result == null) {
result = doc.adoptNode(childElement.cloneNode(false));
}
dest.appendChild(result);
preProcess(doc, childElement, result);
}
}
示例13: toXMLNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
public Node toXMLNode(Document doc, String name) {
Node node = doc.createElement(name);
node.setTextContent(start + " | " + end);
return node;
}
示例14: appendTo
import org.w3c.dom.Node; //導入方法依賴的package包/類
private void appendTo(Document doc, Node target, String name, String text) {
Node n = doc.createElement(name);
n.setTextContent(text);
target.appendChild(n);
}
示例15: preProcess
import org.w3c.dom.Node; //導入方法依賴的package包/類
protected void preProcess(Document doc, Node src, Node dest) throws DocTemplateException {
NodeList childElements = src.getChildNodes();
for (int i = 0; i < childElements.getLength(); i++) {
Node childElement = childElements.item(i);
Node result = null;
String nodeName = childElement.getNodeName();
boolean field = nodeName.toUpperCase().endsWith(XML_FIELD);
if (NAMESPACE_URI.equals(childElement.getNamespaceURI())) {
String key = null;
// In Fall des Fields key gleich mit dem "text:name" Eigenschaft
if (field) {
key = getValueOfAttribute(XML_FIELD_PATH, childElement);
String formatter = getValueOfAttribute(XML_FIELD_FORMATTER, childElement);
if (!StringUtils.isEmpty(formatter)) {
String postFix = LdtConstants.FORMAT_SUFFIX + formatter;
key = key + postFix;
keyTranslationTable.put(postFix, postFix);
}
} else {
for (String blockElement : BLOCK_MARKERS) {
if (nodeName.toUpperCase().endsWith(blockElement)) {
key = blockElement + "_" + childElement.getAttributes().item(0).getTextContent();
break;
}
}
}
if (key != null) {
result = doc.createElement(INTERNAL_BOOKMARK_TAG);
result.setTextContent(field ? (getFieldPrefix() + key) : key);
String sort = null;
if ((sort = getValueOfAttribute(SORT, childElement)) != null) {
if (!sort.equalsIgnoreCase(ASC) && !sort.equalsIgnoreCase(DESC)) {
log.warn("Die Sortierung ist falsch: asc oder desc!");
} else {
dest.appendChild(result);
result = doc.createElement(INTERNAL_BOOKMARK_TAG);
String body = SORT.toUpperCase().concat("_").concat(getPfadOnly(key));
if (sort.equalsIgnoreCase(DESC)) {
body = body.concat("_").concat(sort.toUpperCase());
}
result.setTextContent(body);
}
}
Node attr = childElement.getAttributes().getNamedItem("attribute");
if (attr != null) {
String s = attr.getNodeValue();
Node srcAttr = src.getAttributes().getNamedItem(s);
if (srcAttr != null) {
srcAttr.setNodeValue(INTERNAL_BOOKMARK_XML_ATTR_START + result.getTextContent() + INTERNAL_BOOKMARK_XML_ATTR_END);
dest.getAttributes().setNamedItem(doc.adoptNode(srcAttr.cloneNode(false)));
continue;
}
}
if (!field) {
dest.appendChild(result);
preProcess(doc, childElement, dest);
result = doc.createElement(INTERNAL_BOOKMARK_TAG);
result.setTextContent("END".concat(key));
dest.appendChild(result);
continue;
}
}
}
if (result == null) {
result = doc.adoptNode(childElement.cloneNode(false));
}
dest.appendChild(result);
preProcess(doc, childElement, result);
}
}