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

📄 attributes.xtp

📁 resinweb服务器源文件
💻 XTP
字号:
<title section="Resin : XML Tutorial : ">Attributes</title><p/>Attributes are special children of elements.  They attach a set of&lt;key, value> pairs to each element.<section title="Adding Attributes"><p/>Adding attributes uses the <var/setAttribute()/> method.<example title="Resulting XML">&lt;top a="1" b="2"/></example><example title="Adding Attributes with the DOM">// Create a new documentDocument doc = builder.newDocument();// Create the top elementElement top = doc.createElement("top");// Add an attributetop.setAttribute("a", "1");top.setAttribute("b", "2");</example></section><section title="Retrieving Attributes"><p/>Retrieving attributes uses the <var/getAttribute()/> method of the<var/Element/>.  Since the <var/getAttribute()/> method is specific tothe <var/Element/> and not to <var/Node/>, you'll need to cast it properly.<p/>If an attribute is missing, the value of <var/getAttribute()/> is theempty string, <var/""/>, not <var/null/>.  So you can safely use<var/equals()/> to compare attribute values without checking for <var/null/>.<example title="Retrieving Attributes">Node ptr;for (ptr = top.getFirstChild();     ptr != null && ! ptr.getNodeName().equals("b");     ptr = ptr.getNextSibling()) {}Element elt = (Element) ptr;if (elt == null)  System.out.println("No element b");else if (elt.getAttribute("id").equals("")) {  System.out.println("b has no 'id' attribute");else  System.out.println("b id=" + elt.getAttribute("id"));</example></section>

⌨️ 快捷键说明

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