?? dom1.java
字號:
package xmloperation;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class dom1
{
public dom1() {}
public static void main(String[] args)
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("candidate.xml");
NodeList nl = doc.getElementsByTagName("PERSON");
for(int i = 0; i < nl.getLength(); i++)
{
Element node = (Element)nl.item(i);
System.out.print("NAME:");
System.out.println(node.getElementsByTagName("NAME").item(0).getFirstChild().getNodeValue());
System.out.print("ADDRESS:");
System.out.println(node.getElementsByTagName("ADDRESS").item(0).getFirstChild().getNodeValue());
System.out.print("TEL:");
System.out.println(node.getElementsByTagName("TEL").item(0).getFirstChild().getNodeValue());
System.out.print("FAX:");
System.out.println(node.getElementsByTagName("FAX").item(0).getFirstChild().getNodeValue());
System.out.print("EMAIL:");
System.out.println(node.getElementsByTagName("EMAIL").item(0).getFirstChild().getNodeValue());
System.out.println();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -