xml 学生管理系统



小明

90
90
89



小李

9
70
8



小韩

90
70
85



小明名

34
50
58



小红

29
39
88


二狗969688


package com.dom.exercises;
import java.util.*;

import javax.xml.parsers.*;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.*;

public class stuManage {

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		
		Scanner in = new Scanner(System.in);
		StudentService studentService = new StudentService();
		Student student = new Student();
		
		//显示操作界面
		System.out.println("查看所有学生的成绩----view");
		System.out.println("按照学生id号码查询学生成绩---view of id");
		System.out.println("添加一个学生---add");
		System.out.println("按照id更改一个学生的信息----change");
		System.out.println("按照id去删除一个学生-----remove");
		System.out.println("保存学生信息----save");
		System.out.println("退出系统-----exit");
		
		String operType = in.next();
		if(operType.equals("view")){
			studentService.showStudsFen();
		}else if(operType.equals("id")){
			//id查找
			System.out.println("输入要查询的id:");
			String sid = in.next();
			studentService.serchThroughId(sid);
		}else if(operType.equals("add")){
			//添加
			student.setSid("005");
			student.setName("二狗");
			student.setMy_java(96);
			student.setMy_oracle(98);
			student.setMy_vb(88);
			studentService.add(student);
		}else if(operType.equals("change")){
			//修改
		}else if(operType.equals("remove")){
			//删除
		}else if(operType.equals("save")){
			//保存
		}else if(operType.equals("exit")){
			//退出
		}
	}

}

//写一个服务类
class StudentService{
	//显示所有学生成绩的方法
	public void showStudsFen() throws Exception{
		//1.得到DocumentBuilderFactory
		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
		//2.得到DocumentBuilder
		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
		
		//3.指定文件
		Document document = documentBuilder.parse("src/com/dom/exercises/stu.xml");
		
		//4.显示学生信息
		NodeList nodeList = document.getElementsByTagName("student");
		for(int i = 0;i


你可能感兴趣的:(xml)