本文整理汇总了Java中org.w3c.dom.Document.createTextNode方法的典型用法代码示例。如果您正苦于以下问题:Java Document.createTextNode方法的具体用法?Java Document.createTextNode怎么用?Java Document.createTextNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Document
的用法示例。
在下文中一共展示了Document.createTextNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServiceResult
import org.w3c.dom.Document; //导入方法依赖的package包/类
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
Element rootElement = document.getDocumentElement();
Element objectElement;
Text objectText;
objectElement = document.createElement("threads");
rootElement.appendChild(objectElement);
objectText = document.createTextNode("" + com.twinsoft.convertigo.beans.core.RequestableObject.nbCurrentWorkerThreads);
objectElement.appendChild(objectText);
objectElement = document.createElement("contexts");
rootElement.appendChild(objectElement);
try {
objectText = document.createTextNode(Engine.isStarted ? "" + Engine.theApp.contextManager.getNumberOfContexts() : "0");
} catch (Exception e) {
objectText = document.createTextNode("0");
}
objectElement.appendChild(objectText);
objectElement = document.createElement("requests");
rootElement.appendChild(objectElement);
long i = EngineStatistics.getAverage(EngineStatistics.REQUEST);
if (i == -1) i = 0;
objectText = document.createTextNode("" + i);
objectElement.appendChild(objectText);
}
示例2: engineAddContextToElement
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Method engineAddContextToElement
*
* @param element
*/
public void engineAddContextToElement(Element element) {
if (element == null) {
throw new IllegalArgumentException("null element");
}
if (this.HMACOutputLengthSet) {
Document doc = element.getOwnerDocument();
Element HMElem =
XMLUtils.createElementInSignatureSpace(doc, Constants._TAG_HMACOUTPUTLENGTH);
Text HMText =
doc.createTextNode(Integer.valueOf(this.HMACOutputLength).toString());
HMElem.appendChild(HMText);
XMLUtils.addReturnToElement(element);
element.appendChild(HMElem);
XMLUtils.addReturnToElement(element);
}
}
示例3: testTextNode
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testTextNode() {
try {
Document xmlDocument = createNewDocument();
String whitespace = "\r\n ";
Text textNode = xmlDocument.createTextNode(whitespace);
System.out.println("original text is:\r\n\"" + whitespace + "\"");
String outerXML = getOuterXML(textNode);
System.out.println("OuterXML Text Node is:\r\n\"" + outerXML + "\"");
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
}
示例4: testSplitText
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testSplitText() throws Exception {
Document document = createDOMWithNS("Text01.xml");
NodeList nodeList = document.getElementsByTagName("p");
Node node = nodeList.item(0);
Text textNode = document.createTextNode("This is a text node");
node.appendChild(textNode);
int rawChildNum = node.getChildNodes().getLength();
textNode.splitText(0);
int increased = node.getChildNodes().getLength() - rawChildNum;
assertEquals(increased, 1);
}
示例5: format
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Appends the formatted text of the value as a text node to it's parent;
*/
public Node format(Object value, Node parent) {
String txt = this.componentAdapter.formatObject(value);
if (txt != null && !txt.isEmpty()) {
Document document = parent.getOwnerDocument();
Text text = document.createTextNode(txt);
parent.appendChild(text);
return text;
} else
return null;
}
示例6: getTextNode
import org.w3c.dom.Document; //导入方法依赖的package包/类
public org.w3c.dom.Text getTextNode(Document ownerDoc) {
// XXX Current XMLUtil.write anyway does not preserve CDATA sections, it seems.
String nocdata = getProject().getProperty("makenbm.nocdata");
if (nocdata != null && Project.toBoolean(nocdata)) {
return ownerDoc.createTextNode(text.toString());
} else {
return ownerDoc.createCDATASection(text.toString());
}
}
示例7: copyXMLTree
import org.w3c.dom.Document; //导入方法依赖的package包/类
private static void copyXMLTree(Document doc, Element from, Element to, String newNamespace) {
NodeList nl = from.getChildNodes();
int length = nl.getLength();
for (int i = 0; i < length; i++) {
org.w3c.dom.Node node = nl.item(i);
org.w3c.dom.Node newNode;
switch (node.getNodeType()) {
case org.w3c.dom.Node.ELEMENT_NODE:
Element oldElement = (Element) node;
newNode = doc.createElementNS(newNamespace, oldElement.getTagName());
NamedNodeMap attrs = oldElement.getAttributes();
int alength = attrs.getLength();
for (int j = 0; j < alength; j++) {
org.w3c.dom.Attr oldAttr = (org.w3c.dom.Attr) attrs.item(j);
((Element)newNode).setAttributeNS(oldAttr.getNamespaceURI(), oldAttr.getName(), oldAttr.getValue());
}
copyXMLTree(doc, oldElement, (Element) newNode, newNamespace);
break;
case org.w3c.dom.Node.TEXT_NODE:
newNode = doc.createTextNode(((Text) node).getData());
break;
case org.w3c.dom.Node.COMMENT_NODE:
newNode = doc.createComment(((Comment) node).getData());
break;
default:
// Other types (e.g. CDATA) not yet handled.
throw new AssertionError(node);
}
to.appendChild(newNode);
}
}
示例8: copyNode
import org.w3c.dom.Document; //导入方法依赖的package包/类
private void copyNode(Node sourceNode, Node destinationNode) {
Document destinationDoc = destinationNode.getOwnerDocument();
switch (sourceNode.getNodeType()) {
case Node.TEXT_NODE:
Text text = destinationDoc.createTextNode(sourceNode.getNodeValue());
destinationNode.appendChild(text);
break;
case Node.ELEMENT_NODE:
Element element = destinationDoc.createElement(sourceNode.getNodeName());
destinationNode.appendChild(element);
element.setTextContent(sourceNode.getNodeValue());
// Copy attributes
NamedNodeMap attributes = sourceNode.getAttributes();
int nbAttributes = attributes.getLength();
for (int i = 0; i < nbAttributes; i++) {
Node attribute = attributes.item(i);
element.setAttribute(attribute.getNodeName(), attribute.getNodeValue());
}
// Copy children nodes
NodeList children = sourceNode.getChildNodes();
int nbChildren = children.getLength();
for (int i = 0; i < nbChildren; i++) {
Node child = children.item(i);
copyNode(child, element);
}
}
}
示例9: parseSubTree2
import org.w3c.dom.Document; //导入方法依赖的package包/类
private Element parseSubTree2(HierarchicalStreamReader reader, Document doc)
{
String qname = reader.getNodeName();
Element parent = doc.createElement(qname);
// Iterator i = reader.getAttributeNames();
int count = reader.getAttributeCount();
for( int i = 0; i < count; i++ )
{
String aname = reader.getAttributeName(i);
String value = reader.getAttribute(i);
parent.setAttribute(aname, value);
}
String text = reader.getValue();
if( text.trim().length() != 0 )
{
Text textEl = doc.createTextNode(text);
parent.appendChild(textEl);
}
for( ; reader.hasMoreChildren(); reader.moveUp() )
{
reader.moveDown();
Element child = parseSubTree2(reader, doc);
parent.appendChild(child);
}
return parent;
}
示例10: createStepNodeValue
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
String nodeValue = getSequence().context.getAuthenticatedUser();
if (nodeValue != null && nodeValue.length() > 0) {
Node text = doc.createTextNode(nodeValue);
stepNode.appendChild(text);
}
}
示例11: createStepNodeValue
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
getSequence().context.setAuthenticatedUser(userid.getSingleString(this));
String nodeValue = getSequence().context.getAuthenticatedUser();
if (nodeValue != null && nodeValue.length() > 0) {
Node text = doc.createTextNode(nodeValue);
stepNode.appendChild(text);
}
}
示例12: createStepNodeValue
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
if (isEnabled()) {
try {
Engine.logBeans.info("Hashing file \"" + sourceFilePath + "\"");
File sourceFile = new File(sourceFilePath);
if (!sourceFile.exists()) {
throw new EngineException("Source file does not exist: " + sourceFilePath);
}
if (!sourceFile.isFile()) {
throw new EngineException("Source file is not a file: " + sourceFilePath);
}
byte[] path = null;
path = FileUtils.readFileToByteArray(sourceFile);
String hash = null;
if (hashAlgorithm == HashAlgorithm.MD5) {
hash = org.apache.commons.codec.digest.DigestUtils.md5Hex(path);
} else if (hashAlgorithm == HashAlgorithm.SHA1) {
hash = org.apache.commons.codec.digest.DigestUtils.sha1Hex(path);
}
Engine.logBeans.info("File \"" + sourceFilePath + "\" has been hashed.");
// Node hashNode = doc.createElement("hash");
// hashNode.appendChild(doc.createTextNode(hash));
// stepNode.appendChild(hashNode);
Node text = doc.createTextNode(hash);
stepNode.appendChild(text);
} catch (Exception e) {
setErrorStatus(true);
throw new EngineException("Unable to compute hash code", e);
}
}
}
示例13: fillElementWithBigInteger
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* This method takes an (empty) Element and a BigInteger and adds the
* base64 encoded BigInteger to the Element.
*
* @param element
* @param biginteger
*/
public static final void fillElementWithBigInteger(Element element, BigInteger biginteger) {
String encodedInt = encode(biginteger);
if (!XMLUtils.ignoreLineBreaks() && encodedInt.length() > BASE64DEFAULTLENGTH) {
encodedInt = "\n" + encodedInt + "\n";
}
Document doc = element.getOwnerDocument();
Text text = doc.createTextNode(encodedInt);
element.appendChild(text);
}
示例14: duplicateNode
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Helper method used by {@link #findAlternateToolsXml(InputStream)} to duplicate a node
* and attach it to the given root in the new document.
*/
private Element duplicateNode(Element newRootNode, Element oldNode,
String namespaceUri, String prefix) {
// The implementation here is more or less equivalent to
//
// newRoot.appendChild(newDoc.importNode(oldNode, deep=true))
//
// except we can't just use importNode() since we need to deal with the fact
// that the old document is not namespace-aware yet the new one is.
Document newDoc = newRootNode.getOwnerDocument();
Element newNode = null;
String nodeName = oldNode.getNodeName();
int pos = nodeName.indexOf(':');
if (pos > 0 && pos < nodeName.length() - 1) {
nodeName = nodeName.substring(pos + 1);
newNode = newDoc.createElementNS(namespaceUri, nodeName);
newNode.setPrefix(prefix);
} else {
newNode = newDoc.createElement(nodeName);
}
newRootNode.appendChild(newNode);
// Merge in all the attributes
NamedNodeMap attrs = oldNode.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Attr attr = (Attr) attrs.item(i);
Attr newAttr = null;
String attrName = attr.getNodeName();
pos = attrName.indexOf(':');
if (pos > 0 && pos < attrName.length() - 1) {
attrName = attrName.substring(pos + 1);
newAttr = newDoc.createAttributeNS(namespaceUri, attrName);
newAttr.setPrefix(prefix);
} else {
newAttr = newDoc.createAttribute(attrName);
}
newAttr.setNodeValue(attr.getNodeValue());
if (pos > 0) {
newNode.getAttributes().setNamedItemNS(newAttr);
} else {
newNode.getAttributes().setNamedItem(newAttr);
}
}
// Merge all child elements and texts
for (Node child = oldNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
duplicateNode(newNode, (Element) child, namespaceUri, prefix);
} else if (child.getNodeType() == Node.TEXT_NODE) {
Text newText = newDoc.createTextNode(child.getNodeValue());
newNode.appendChild(newText);
}
}
return newNode;
}
示例15: nodeset
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* This method is an extension that implements as a Xalan extension
* the node-set function also found in xt and saxon.
* If the argument is a Result Tree Fragment, then <code>nodeset</code>
* returns a node-set consisting of a single root node as described in
* section 11.1 of the XSLT 1.0 Recommendation. If the argument is a
* node-set, <code>nodeset</code> returns a node-set. If the argument
* is a string, number, or boolean, then <code>nodeset</code> returns
* a node-set consisting of a single root node with a single text node
* child that is the result of calling the XPath string() function on the
* passed parameter. If the argument is anything else, then a node-set
* is returned consisting of a single root node with a single text node
* child that is the result of calling the java <code>toString()</code>
* method on the passed argument.
* Most of the
* actual work here is done in <code>MethodResolver</code> and
* <code>XRTreeFrag</code>.
* @param myProcessor Context passed by the extension processor
* @param rtf Argument in the stylesheet to the nodeset extension function
*
* NEEDSDOC ($objectName$) @return
*/
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
{
String textNodeValue;
if (rtf instanceof NodeIterator)
{
return new NodeSet((NodeIterator) rtf);
}
else
{
if (rtf instanceof String)
{
textNodeValue = (String) rtf;
}
else if (rtf instanceof Boolean)
{
textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
}
else if (rtf instanceof Double)
{
textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
}
else
{
textNodeValue = rtf.toString();
}
// This no longer will work right since the DTM.
// Document myDoc = myProcessor.getContextNode().getOwnerDocument();
Document myDoc = getDocument();
Text textNode = myDoc.createTextNode(textNodeValue);
DocumentFragment docFrag = myDoc.createDocumentFragment();
docFrag.appendChild(textNode);
return new NodeSet(docFrag);
}
}