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

📄 test.java

📁 基于xml的数据库管理系统
💻 JAVA
字号:
import java.io.*;
import java.util.*; 
import javax.xml.parsers.*; 
import org.w3c.dom.*; 
import org.apache.crimson.tree.XmlDocument;

public class test
{
	static Document doc = null;
	private void readXMLFile(String inFile) throws Exception {
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	DocumentBuilder db = null;
	try {
			db = dbf.newDocumentBuilder();
	} catch (ParserConfigurationException pce) {
		System.err.println(pce); file://出异常时输出异常信息,然后退出,下同
		System.exit(1);
		}

	
	try {
		  File file=new File(inFile);
		  
			doc = db.parse(file);

		} catch (DOMException dom) {
					System.err.println(dom.getMessage());
					System.exit(1);
				} catch (IOException ioe) {
				System.err.println(ioe);
				System.exit(1);
				}
		Element root = doc.getDocumentElement();

}




	
	
	public static void main(String[] args) throws Exception 
	{ 
		test xmlTest = new test();
			

			System.out.println("开始读Input.xml文件");
		xmlTest.readXMLFile("mm.xml");
        
		Element root=doc.getDocumentElement();//root是根元素
    	    
    	    System.out.println(root.getNodeName());
    	    
    	    NodeList nodes=root.getChildNodes();
    	    for(int i=0;i<nodes.getLength();i++)
	    	{
		    		System.out.println(nodes.item(i).getNodeName());

	    	}
    	    System.out.print(nodes.getLength());
			
	}

}

⌨️ 快捷键说明

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