elements.xtp

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

XTP
51
字号
<s1 title="Adding Elements"><p>Elements in XML are the same as tags.  This example will create adocument and add some elements to it.</p><example title="Resulting XML">&lt;top>  &lt;a/>  &lt;b/>  &lt;c/>&lt;/top></example><p>All the DOM nodes are created using the Document object.  Each nodecreated by a Document belongs to that document.  You can't directly addnodes from one document to another document.  (Although you can <var/import/>the node.)</p><p>Documents are intrinsically implementation-dependent.To bootstrap this process, you need to create the Document.Sun's JAXP DocumentBuilder gives an implementation-independent methodfor creating a document.</p><example title="Creating Elements with the DOM">import java.io.*;import javax.xml.parser.*;import org.w3c.dom.*;import com.caucho.xml.*;...// Create a new parser using the JAXP API (javax.xml.parser)DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();DocumentBuilder builder = factory.newDocumentBuilder();// Create a new documentDocument doc = builder.newDocument();// Create the top elementElement top = doc.createElement("top");// Add it to the documentdoc.appendChild(top);// Add elements to the toptop.appendChild(doc.createElement("a"));top.appendChild(doc.createElement("b"));top.appendChild(doc.createElement("c"));</example></s1>

⌨️ 快捷键说明

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