JAVA ½âÎö XML
XMLÎļþʱºÜ¶àÏîÄ¿¾³£Ê¹ÓõÄÅäÖûòÕ߯äËûÓÃ;µÄÎļþ¸ñʽ£¬½âÎöxmlÎļþ¸ñʽµÄ¿ª·¢°üÒ²ºÜ¶à£¬±¾ÎÄÖ÷ҪʹÓÃjava×Ô´øµÄDOM½âÎö°ü¡£±¾ÎÄÒÔÒ»¸öʵ¼ÊÀý×ÓÀ´½²Êö½âÎöxmlÎļþµÄ¹ý³Ì¡£
Ä¿±ê£º½âÎöÕâÑùÒ»¸öXMLÎļþ
employees.xml
=======ÄÚÈÝ¿ªÊ¼========
<?xml version="1.0" encoding="UTF-8"?>
<Personnel>
<Employee type="permanent">
<Name>Seagull</Name>
<Id>3674</Id>
<Age>34</Age>
</Employee>
<Employee type="contract">
<Name>Robin</Name>
<Id>3675</Id>
<Age>25</Age>
</Employee>
<Employee type="permanent">
<Name>Crow</Name>
<Id>3676</Id>
<Age>28</Age>
</Employee>
</Personnel>
=======ÄÚÈݽáÊø========
Ä¿±êÊÇ£ºÊä³öÈçÏÂÄÚÈÝ
Employee Details - Name:Seagull, Type:permanent, Id:3674, Age:34.
Employee Details - Name:Robin, Type:contract, Id:3675, Age:25.
Employee Details - Name:Crow, Type:permanent, Id:3676, Age:28.
Ö÷Òª²½Öè
1£¬
Get a document builder using document builder factory and parse the xml
file to create a DOM object
Get a list of employee elements from the DOM
For each employee element get the id, name, age and type. Create an
employee value object and add it to the list.
At the end iterate through the list and print the employees to verify we
parsed it right.
a) »ñÈ¡document builder
public void parseXmlFile(){
//get the factory
DocumentBuilderFactory dbf = DocumentBu
Ïà¹ØÎĵµ£º
±¾ÎĽéÉÜÈçºÎÔÚLinuxÏÂÅäÖÃJava»·¾³±äÁ¿¡£ÅäÖù²·ÖÊ®¸ö²½Ö裬´ÓÏÂÔØJDK¿ªÊ¼£¬µ½LinuxÉÏJDKµÄ°²×°£¬EclipseµÄÏàÓ¦ÅäÖã¬×îÖÕÔÚ×ÀÃæÉÏ´´½¨Ò»¸öÆô¶¯Æ÷£¬Â·¾¶ÉèÖõ½Eclipse£¬¾Í´ËÍê³ÉJava»·¾³±äÁ¿µÄÅäÖá£
1.È¥http://java.sun.com/j2se/1.4.2/download.html
ÏÂÔØÒ»¸öLinux PlatformµÄJDK£¬
½¨ÒéÏÂÔØRPM×Ô½âѹ¸ñʽµÄ£¨RP ......
×Ô¶¯×°ÏäÓë²ðÏäµÄ¹¦ÄÜÊÂʵÉÏÊDZàÒëÆ÷À´°ïÄúµÄ棬±àÒëÆ÷ÔÚ±àÒëʱÆÚÒÀÄúËù±àдµÄÓï·¨£¬¾ö¶¨ÊÇ·ñ½øÐÐ×°Ïä»ò²ðÏ䶯×÷¡£ÀýÈ磺
Integer i = 100.Ï൱ÓÚ±àÒëÆ÷×Ô¶¯ÎªÄú×÷ÒÔϵÄÓï·¨±àÒ룺
Integer i = new Integer(100).ËùÒÔ×Ô¶¯×°ÏäÓë²ðÏäµÄ¹¦ÄÜÊÇËùνµÄ“±àÒëÆ÷ÃÛÌÇ”(Compiler Sugar)£¬ËäȻʹÓÃÕâ¸ö¹¦Äܷܺ½±ã£¬µ ......
Ïà¶Ô·¾¶µÄ»ñµÃ
¡¡¡¡ ˵Ã÷:Ïà¶Ô·¾¶(¼´²»Ð´Ã÷ʱºòµ½µ×Ïà¶ÔË)¾ù¿Éͨ¹ýÒÔÏ·½Ê½»ñµÃ£¨²»ÂÛÊÇÒ»°ãµÄjavaÏîÄ¿»¹ÊÇwebÏîÄ¿£©
¡¡¡¡ String
relativelyPath=System.getProperty("user.dir");
¡¡¡¡
ÉÏÊöÏà¶Ô·¾¶ÖУ¬javaÏîÄ¿ÖеÄÎļþÊÇÏà¶ÔÓÚÏîÄ¿µÄ¸ùĿ¼
¡¡¡¡ webÏîÄ¿ÖеÄÎļþ·¾¶ÊÓ²»Í¬µÄweb·þÎñÆ÷²»Í¬¶ø²»Í¬£¨tomcatÊÇ ......
11.дÈëÊôÐÔ
//import java.io.*;
File filereadonly=new File(%%1);
try {
boolean b=filereadonly.setReadOnly();
}
catch (Exception e) {
System.out.println("¾Ü¾øÐ´·ÃÎÊ£º"+e.printStackTrace());
}
12.ö¾ÙÒ»¸öÎļþ¼ÐÖеÄËùÓÐÎļþ
//import  ......
34.¶ÁÈ¡iniÎļþÊôÐÔ
//import java.io.*;
//import java.util.*;
//import java.util.regex.*;
//private HashMap configMap=null;
private Map<String, Serializable> configMap=null;
String %%2=null;
if (configMap == null)&n ......