text.xtp

来自「resinweb服务器源文件」· XTP 代码 · 共 58 行

XTP
58
字号
<title section="Resin : XML Tutorial : ">Text</title><p/><var/Text/> nodes, like elements, are children of nodes.  The textvalue is retrieved using <var/getNodeValue()/>.<section title="Adding Text Nodes"><p/>Text nodes are added using the <var/appendChild()/> call, like Elements.<example title="Resulting XML">&lt;top>Hello, world&lt;/top></example><example title="Adding Attributes with the DOM">// Create a new documentDocument doc = builder.newDocument();// Create the top elementElement top = doc.createElement("top");// Create Text NodeText text = doc.createTextNode("Hello, world");// Add it to the toptop.appendChild(text);</example></section><section title="Getting Text Values"><p/>As mentioned above, the value of a text node is retrieved using<var/getNodeValue()/>.  The <var/name/> of a text node isalways <var/#text/>.  Normally, you'll either use <var/instanceof/> or<var/getNodeType()/> to tell if the node is a text node, but testingthe <var/name/> against <var/#text/> will work.<p/>The following function recursively prints all the text childrenof an element.  It tests against <var/CharacterData/> so <var/CDATA/>sections will also be printed.<example>void printText(Node node){  for (; node != null; node = node.getNextSibling()) {    if (node instanceof CharacterData)      System.out.print(ptr.getNodeValue());    printText(node.getFirstChild());  }}</example></section>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?