e531. getting a dom element by id.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 24 行
TXT
24 行
// Obtain an XML document; this method is implemented in
// e510 The Quintessential Program to Create a DOM Document from an XML File
Document doc = parseXmlFile("infilename.xml", true);
// Retrieve the element using id
Element element = doc.getElementById("key1");
// Get the element's attribute
String attrValue = element.getAttribute("value"); // value1
This is the sample input for the example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map [ <!ELEMENT map (entry*) >
<!ELEMENT entry EMPTY >
<!ATTLIST entry key ID #REQUIRED
value CDATA "mydefault"> ]>
<map>
<entry key="key1" value="value1"/>
<entry key="key2" />
</map>
Related Examples
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?