⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 get_elements.xtp

📁 resinweb服务器源文件
💻 XTP
字号:
<title section="Resin : XML Tutorial : ">Scanning Elements</title><p/>This Example extracts and print the "b" node in the following XML.<example title="Input XML">&lt;top>  &lt;a/>  &lt;b>    &lt;b1/>    &lt;b2/>  &lt;/b>  &lt;c/>&lt;/top></example><p/>In XML, the document contains a single top element.  We'll just extractthat and store it.<p/>Each DOM node has a <var/name/> and a <var/value/> retrieved using<var/getNodeName()/> and <var/getNodeValue()/>.  For an Element, the<var/name/> is the tag name and the <var/value/> is null.<p/>Traversing nodes uses a combination of:<ul><li><var/getFirstChild()/><li><var/getLastChild()/><li><var/getNextSibling()/><li><var/getPreviousSibling()/><li><var/getParentNode()/></ul>Since those return a <var/Node/>, you'll often need to cast the results tothe correct type.  Remember, that the child nodes also includes <var/Text/>nodes, including whitespace-only text nodes.  You can't assume that anychild is an Element, So you'll always need to test the node name orthe node type.<p/>The following pattern is a common method for findinga node as the child.<example title="Finding Elements with the DOM">import java.io.*;import javax.xml.parsers.*;import org.w3c.dom.*;import com.caucho.xml.*;...// Create a new parser using the JAXP API (javax.xml.parsers)DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();DocumentBuilder builder = factory.newDocumentBuilder();// Create a new documentDocument doc = builder.parse("test.xml");// Get the top elementElement top = doc.getDocumentElement();// Find the B elementNode ptr;for (ptr = top.getFirstChild();     ptr != null && ! ptr.getNodeName().equals("b");     ptr = ptr.getNextSibling()) {}</example>

⌨️ 快捷键说明

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