JavaÓëXMLÁªºÏ±à³ÌÖ®DOMƪ
DOM³õ²½
DOMÊÇDocument Object ModelµÄËõд£¬¼´Îĵµ¶ÔÏóÄ£ÐÍ¡£Ç°Ãæ˵¹ý£¬XML½«Êý¾Ý×é֯Ϊһ¿ÅÊ÷£¬ËùÒÔDOM¾ÍÊǶÔÕâ¿ÅÊ÷µÄÒ»¸ö¶ÔÏóÃèÐð¡£Í¨Ë×µÄ˵£¬¾ÍÊÇͨ¹ý½âÎöXMLÎĵµ£¬ÎªXMLÎĵµÔÚÂß¼ÉϽ¨Á¢Ò»¸öÊ÷Ä£ÐÍ£¬Ê÷µÄ½ÚµãÊÇÒ»¸ö¸ö¶ÔÏó¡£ÎÒÃÇͨ¹ý´æÈ¡ÕâЩ¶ÔÏó¾ÍÄܹ»´æÈ¡XMLÎĵµµÄÄÚÈÝ¡£
ÏÂÃæÎÒÃÇÀ´¿´Ò»¸ö¼òµ¥µÄÀý×Ó£¬¿´¿´ÔÚDOMÖУ¬ÎÒÃÇÊÇÈçºÎÀ´²Ù×÷Ò»¸öXMLÎĵµµÄ¡£
ÕâÊÇÒ»¸öXMLÎĵµ£¬Ò²ÊÇÎÒÃÇÒª²Ù×÷µÄ¶ÔÏó£º
<?xml version="1.0" encoding="UTF-8"?>
<messages>
<message>Good-bye serialization, hello Java!</message>
</messages>
ÏÂÃ棬ÎÒÃÇÐèÒª°ÑÕâ¸öÎĵµµÄÄÚÈݽâÎöµ½Ò»¸ö¸öµÄJava¶ÔÏóÖÐÈ¥¹©³ÌÐòʹÓã¬ÀûÓÃJAXP£¬ÎÒÃÇÖ»Ð輸ÐдúÂë¾ÍÄÜ×öµ½ÕâÒ»µã¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒª½¨Á¢Ò»¸ö½âÎöÆ÷¹¤³§£¬ÒÔÀûÓÃÕâ¸ö¹¤³§À´»ñµÃÒ»¸ö¾ßÌåµÄ½âÎöÆ÷¶ÔÏó£º
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
ÎÒÃÇÔÚÕâÀïʹÓÃDocumentBuilderFacotryµÄÄ¿µÄÊÇΪÁË´´½¨Óë¾ßÌå½âÎöÆ÷Î޹صijÌÐò£¬µ±DocumentBuilderFactoryÀàµÄ¾²Ì¬·½·¨newInstance()±»µ÷ÓÃʱ£¬Ëü¸ù¾ÝÒ»¸öϵͳ±äÁ¿À´¾ö¶¨¾ßÌåʹÓÃÄÄÒ»¸ö½âÎöÆ÷¡£ÓÖÒòΪËùÓеĽâÎöÆ÷¶¼·þ´ÓÓÚJAXPËù¶¨ÒåµÄ½Ó¿Ú£¬ËùÒÔÎÞÂÛ¾ßÌåʹÓÃÄÄÒ»¸ö½âÎöÆ÷£¬´úÂ붼ÊÇÒ»ÑùµÄ¡£ËùÒÔµ±ÔÚ²»Í¬µÄ½âÎöÆ÷Ö®¼ä½øÐÐÇл»Ê±£¬Ö»ÐèÒª¸ü¸Äϵͳ±äÁ¿µÄÖµ£¬¶ø²»Óøü¸ÄÈκδúÂë¡£Õâ¾ÍÊǹ¤³§Ëù´øÀ´µÄºÃ´¦¡£Õâ¸ö¹¤³§Ä£Ê½µÄ¾ßÌåʵÏÖ£¬¿ÉÒԲο´ÏÂÃæµÄÀàͼ¡£
DocumentBuilder db = dbf.newDocumentBuilder();
µ±»ñµÃÒ»¸ö¹¤³§¶ÔÏóºó£¬Ê¹ÓÃËüµÄ¾²Ì¬·½·¨newDocumentBuilder()·½·¨¿ÉÒÔ»ñµÃÒ»¸öDocumentBuilder¶ÔÏó£¬Õâ¸ö¶ÔÏó´ú±íÁ˾ßÌåµÄDOM½âÎöÆ÷¡£µ«¾ßÌåÊÇÄÄÒ»ÖÖ½âÎöÆ÷£¬Î¢ÈíµÄ»òÕßIBMµÄ£¬¶ÔÓÚ³ÌÐò¶øÑÔ²¢²»ÖØÒª¡£
È»ºó£¬ÎÒÃǾͿÉÒÔÀûÓÃÕâ¸ö½âÎöÆ÷À´¶ÔXMLÎĵµ½øÐнâÎöÁË£º
Document doc = db.parse("c:/xml/message.xml");
DocumentBuilderµÄparse()·½·¨½ÓÊÜÒ»¸öXMLÎĵµÃû×÷ΪÊäÈë²ÎÊý£¬·µ»ØÒ»¸öDocument¶ÔÏó£¬Õâ¸öDocument¶ÔÏó¾Í´ú±íÁËÒ»¸öXMLÎĵµµÄÊ÷Ä£ÐÍ¡£ÒÔºóËùÓеĶÔXMLÎĵµµÄ²Ù×÷£¬¶¼Óë½âÎöÆ÷Î޹أ¬Ö±½ÓÔÚÕâ¸öDocument¶ÔÏóÉϽøÐвÙ×÷¾Í¿ÉÒÔÁË¡£¶ø¾ßÌå¶ÔDocument²Ù×÷µÄ·½·¨£¬¾ÍÊÇÓÉDOMËù¶¨ÒåµÄÁË¡£
JaxpÖ§³ÖW3CËùÍƼöµÄDOM 2¡£Èç¹ûÄã¶ÔDOMºÜÊìϤ£¬ÄÇôÏÂÃæµÄÄÚÈݾͺܼòµ¥ÁË£ºÖ»ÐèÒª°´ÕÕDOMµÄ¹æ·¶À´½øÐз½·¨µ÷ÓþͿÉÒÔ¡£µ±È»£¬Èç¹ûÄã¶ÔDOM²»Çå³þ£¬Ò²²»ÓÃ׿±£¬ºóÃæÎÒÃÇ»áÓÐÏêϸµÄ
Ïà¹ØÎĵµ£º
2£®DOMʵÀý
ÓÐÁËÉÏÃæµÄ½éÉÜ£¬ÏàÐÅÄã¶ÔDOMÀí½âµÄ¸ü¶àÁË°É¡£ÏÂÃæµÄÀý×Ó½«ÈÃÄã¶ÔDOM¸ü¼ÓÊìϤÆðÀ´¡£
ÏÈ˵˵Õâ¸öÀý×Óµ½µ×Òª×öµÄÊÇʲô°É£¬ÎÒÃÇÏ£ÍûÔÚÒ»¸öÃûΪlink.xmlÎļþÖб£´æÁËһЩURLµØÖ·£¬Í¨¹ýÒ»¸ö¼òµ¥µÄ³ÌÐò£¬ÎÒÃÇ¿ÉÒÔͨ¹ýDOM°ÑÕâЩURL¶Á³ö²¢ÏÔʾ³öÀ´£¬Ò²¿ÉÒÔ·´¹ýÀ´ÏòÕâ¸öXMLÎļþÖÐдÈë¼ÓÈëµÄURLµØÖ·¡£ºÜ¼òµ¥£¬È´ºÜÊµÓ ......
1. ÏÈ´ÓÍøÉÏÏÂÔØjdk(jdk-1_5_0_02-linux-i586.rpm) £¬ÍƼöSUNµÄ¹Ù·½ÍøÕ¾www.sun.com£¬ÏÂÔغó·ÅÔÚ/homeĿ¼ÖУ¬µ±È»ÆäËüµØ·½Ò²ÐС£
½øÈ밲װĿ¼
#cd /home
#cp jdk-1_5_0_02-linux-i586.rpm /usr/local
#cd /usr/local
¸øËùÓÐÓû§Ìí¼Ó¿ÉÖ´ÐеÄȨÏÞ
#chmod +x jdk-1_5_0_02-linux-i586.rpm.bin
#./jdk-1_5_0_02-lin ......
Ctrl+1 ¿ìËÙÐÞ¸´(×î¾µäµÄ¿ì½Ý¼ü,¾Í²»Óöà˵ÁË)
Ctrl+D: ɾ³ýµ±Ç°ÐÐ
Ctrl+Alt+↓ ¸´ÖƵ±Ç°Ðе½ÏÂÒ»ÐÐ(¸´ÖÆÔö¼Ó)
Ctrl+Alt+↑ ¸´ÖƵ±Ç°Ðе½ÉÏÒ»ÐÐ(¸´ÖÆÔö¼Ó)
Alt+↓ µ±Ç°ÐкÍÏÂÃæÒ»Ðн»»¥Î»ÖÃ(ÌرðʵÓÃ,¿ÉÒÔÊ¡È¥ÏȼôÇÐ,ÔÙÕ³ÌùÁË)
Alt+↑ µ±Ç°ÐкÍÉÏÃæÒ»Ðн»»¥Î»ÖÃ(ͬÉÏ)
Alt+← Ç°Ò»¸ö±à¼µÄÒ³Ãæ ......
public static Object getCloneObject(Object bean) {
Object cloneBean = null;
try {
ByteArrayOutputStream byout = new ByteArrayOutputStream();
ObjectOutputStream obj = new ObjectOutputStream(byout);
obj.writeObject(bean);
ByteArrayInputStream byin = new ByteArrayInputStream(byou ......