易截截图软件、单文件、免安装、纯绿色、仅160KB

JAVA根据XML节点读取XML文件内容

XML文件 book.xml
<book>
<person>
<first>Kiran</first>
<last>Pai</last>
<age>22</age>
</person>
<person>
<first>Bill</first>
<last>Gates</last>
<age>46</age>
</person>
<person>
<first>Steve</first>
<last>Jobs</last>
<age>40</age>
</person>
</book>
程序输出
Root element of the doc is book
Total no of people: 3
First Name: Kiran
Last Name: Pai
Age: 22
First Name: Bill
Last Name: Gates
Age: 46
First Name: Steve
Last Name: Jobs
Age: 40
程序清单
import java.io.File;
import org.w3c.dom.Document;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class ReadAndPrintXMLFile{
    public static void main (String argv []){
    try {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            Document doc = docBuilder.parse (new File("book.xml"));
            // normalize text representation           
            doc.getDocumentElement ().normalize ();
            System.out.println ("Root element of the doc is " + doc.getDocumentElement().getNodeName());
            NodeList listOfPersons = doc.getElementsByTagName("person");
     


相关文档:

我的java学习日记

   load-on-startup元素一般是配合servlet的配置使用的,load-on-startup 元素在web应用启动的时候指定了servlet被加载的顺序,它的值必须是一个整数。如果它的值是一个负整数或是这个元素不存在,那么容器会在该servlet被调用的时候,加载这个servlet 。如果值是正整数或零,容器在配置的时候就加载并初始化 ......

java学习网址

1.Java学习网站:
Java中文世界论坛        http://www.chinajavaworld.com/index.jspa
Java世纪网              http://www.java2000.net/
Java 中文站            http://www.java-cn.com/
Java学习室      ......

使用EditPlus配置Java编译环境

初学者更适合使用文本编辑软件来学习Java,对Java有一定认识后推荐使用Eclipse,对那些要求开发效率的程序员当然首选就是JBuilder。
         对于文本编辑软件我推荐EditPlus,EditPlus是很多程序员非常熟悉的编辑工具,它以占用系统资
源小、操作简便灵活、支持文件类型丰富 ......

Java中HashMap使用自定义Key类

自定义的Key类需要重载equals, hashCode函数。。 
package com.albert.test;
import java.util.Vector;
import java.util.HashMap;
/**
* @author tough_guy
*
*/
//对于自定义的key, 需要重载hashCode函数和equals函数
class IPSegment
{
long ip_s;
long ip_e;
int p;
IPSegment Reset(long f ......

java读取xml文件的四种方法

xml文件:
Xml代码
<?xml version="1.0" encoding="GB2312"?>  
<RESULT>  
 <VALUE>     
  <NO>A1234</NO>     
  <ADDR>河南省郑州市</ADDR>  
 </VALUE>&nbs ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号