Java and XML_¶ÁÊé±Ê¼Ç_2010 05 16
2010-05-16
Èý¡¢½âÎöXMLÎĵµ
l Xerces½âÎöÆ÷¡¢SAXÀàºÍ½Ó¿Ú
l SAXÔĶÁÆ÷
n Ê×ÏÈÒªµÃµ½Ò»¸ö·ûºÏSAX org.xml.sax.XMLReader½Ó¿Ú¹æ·¶µÄÀý×Ó£¬Õâ¸ö½Ó¿Ú¶¨ÒåÁ˽âÎöÐÐΪ²¢ÔÊÐíÉèÖÃijЩÌØÕ÷ºÍÊôÐÔ¡£¸Ã½Ó¿ÚÌæ»»ÁËSAX1.0ÖеÄorg.xml.sax.Parser
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.XMLReader;
XMLReader parser = new SAXParser();
parser.parse(uri);
n µ±Ò»¸ö½âÎöÆ÷µ÷Èë²¢×¼±¸¾ÍÐ÷ºó£¬Ëü¾Í¿ÉÒÔ¶ÔÎĵµ½øÐнâÎöÁË£¬Í¨³£ÓÉparse()·½·¨µÄorg.xml.sax.XMLReaderÀ´´¦ÀíÒ»¸öorg.xml.sax.InputSource»òÕßÒ»¸öURI´®¡£
n ÄÚÈݹÜÀíÆ÷£ºÔÚ½âÎö½øÐÐʱ£¬ÎªÊ¹Ó¦ÓóÌÐòÓÐЧµØ´¦ÀíXMLÊý¾Ý£¬±ØÐëÓÃSAX½âÎöÆ÷µÇ¼Ç¹ÜÀíÆ÷£¨handler£©¡£¹ÜÀíÆ÷ÊÇÒ»×éSAX¶¨ÒåµÄ»Øµ÷£¬ËüÄÜÔÚÎĵµ½âÎö¹ý³ÌÖиøÖØÒªµÄʼþ²åÈëÏàÓ¦µÄÓ¦ÓóÌÐò´úÂë¡£ÕâЩʼþÓëÎĵµ½âÎöͬʱ½øÐС£SAX³ÉΪһ¸öÇ¿´ó½Ó¿ÚµÄÔÒòÖ®Ò»£º²»ÐèÒªÔÚÆðʼʱ¾Í½«È«²¿Îĵµ¶ÁÈëÄڴ棬¶þÊ®¿ÉÒÔ¶ÔÆä½øÐÐÁ¬Ðø´¦Àí¡£
n SAX2.0¶¨ÒåÁËËĸöºËÐĵĹÜÀíÆ÷½Ó¿Ú£ºorg.xml.sax.ContentHandler¡¢org.xml.sax.ErrorHandler¡¢org.xml.sax.DTDHandler¡¢org.xml.sax.EntityResolver¡£½âÎö¹ý³ÌÖУ¬Ö´ÐÐÌض¨¶¯×÷µÄ¶¨ÖÆÓ¦ÓÃÀàÖ§³ÖËùÓнӿڣ¬ÕâЩִÐÐÀà¿ÉÒÔÓÃSetContentHandler()¡¢setDTDHandler()ºÍsetEntityResolver()µÄ·½·¨ÔÚ½âÎöÆ÷ÉÏ×¢²á¡£
u Îĵµ¶¨Î»Æ÷£ºorg.xml.sax.Locatorµ±Ä³»Øµ÷ʼþ³öÏÖʱ£¬Íê³É´¦ÀíµÄÀà±ØÐë´ÓSAX½âÎöÆ÷µÄXMLÎĵµÖÐÕÒµ½ÏàÓ¦µÄλÖá£
u ÎĵµµÄ¿ªÍ·ºÍ½áβ£ºstartDocument()ºÍendDocument()
startDocument()ÔÚÈκÎÆäËû»Øµ÷֮ǰ±»µ÷ÓÃ
endDocument()¾³£ÊÇÔÚËùÓйÜÀíÆ÷ÖÐ×îºó±»µ÷Óõķţ¬Èô²»¿É»Ö¸´ÐÔ´íÎó·¢Éú£¬ÔòErrorHandler»Øµ÷·½·¨½«±»»½ÐÑ£¬Í¬Ê±È¥µ÷ÓÃendDocument()½áÊø´Ë½âÎö¹ý³Ì¡£
ÕâÁ½¸ö»Øµ÷·½·¨¶¼»áÅ׳öSAXException£¬ÕâÒ²ÊÇSAXʼþ»áÅ׳öÒì³£µÄΨһ·½Ê½
u ´¦ÀíÖ¸ÁSAX¶¨ÒåÁËÌØÊâµÄ»Øµ÷À´´¦ÀíÖ¸Áî¡£ÕâÖз½·¨½ÓÊÜ´¦ÀíÖ¸ÁîµÄÄ¿±êºÍÄÇЩ´«µÝ¸ø´¦ÀíÖ¸ÁîµÄËùÓÐÊý¾Ý¡£
u Ãû×Ö¿Õ¼äµÄ»Øµ÷£ºÓÐÁ½ÖÖSAX»Øµ÷º¯ÊýרÃÅÓÃÓÚ´¦ÀíÃû×ֿռ䣨¾¡¹ÜÔªËػص÷ҲʹÓÃËüÃÇ£©¡£µ±½âÎöÆ÷µ½µ×ǰ׺ӳÏñ£¨prefix mapping£©µÄ¿ªÍ·ºÍ½áβʱ£¬ËüÃDZ»»½ÐÑ
startPrefixMapping()»Øµ÷¸ø³öÓëURIÏà¹ØµÄÃû×Ö¿Õ¼äǰ׺¡£Ç°×ºÓ³Ïñ»Øµ÷ÔÚÉùÃ÷Ãû×Ö¿Õ¼äµÄÔªËػص÷֮ǰÁ¢¼´·¢Éú¡£
endPrefixMapping()»Øµ÷ÔÚÉùÃ÷Ó³ÏñµÄÔªËصĽáÊø±êÇ©Ö®ºóÁ¢¼´³öÏÖ
u Ô
Ïà¹ØÎĵµ£º
ÕâƪÎÄÕÂÌÖÂۺͲûÃ÷ÁËÌṩ JavaTM I/O ÐÔÄܵĶàÖÖ¼¼Êõ¡£´ó¶à¼¼ÊõΧÈƵ÷Õû´ÅÅÌÎļþ I/O,µ«ÊÇÓÐЩÄÚÈÝҲͬÑùÊʺÏÍøÂç I/O ºÍ´°¿ÚÊä³ö¡£µÚÒ»²¿·Ö¼¼ÊõÌÖÂ۵ײãµÄI/OÎÊÌ⣬ȻºóÌÖÂÛÖîÈçѹËõ£¬¸ñʽ»¯ºÍ´®Ðл¯µÈ¸ß¼¶I/OÎÊÌ⡣Ȼ¶øÕâ¸öÌÖÂÛûÓаüº¬Ó¦ÓÃÉè¼ÆÎÊÌ⣬ÀýÈçËÑË÷Ëã·¨ºÍÊý¾Ý½á¹¹£¬Ò²Ã»ÓÐÌÖÂÛϵͳ¼¶µÄÎÊÌ⣬ÀýÈçÎļþ¸ßËÙ»º³å ......
ÍøÂç³ÌÐòµÄºÜ´óÒ»²¿·ÖÊǼòµ¥µÄÊäÈëÊä³ö£¬¼´´ÓÒ»¸öϵͳÏòÁíÒ»¸öϵͳÒƶ¯×Ö½Ú¡£×Ö½Ú¾ÍÊÇ×Ö½Ú£¬Ôںܴó³Ì¶ÈÉÏ£¬¶Á·þÎñÆ÷·¢Ë͵ÄÊý¾ÝÓë¶ÁÈ¡Îļþûʲô²»Í¬£»Ïò¿Í»§´«ËÍÊý¾ÝÓëдÈëÒ»¸öÎļþҲûÓÐʲôÇø±ð¡£
JavaÖÐÊäÈëºÍÊä³ö×éÖ¯²»Í¬ÓÚ´ó¶àÊýÆäËûÓïÑÔ¡£ËüÊǽ¨Á¢ÔÚÁ÷(stream)ÉÏ¡£²»Í¬µÄ»ù±¾Á÷Àà(Èçjava.io.FileInputStreamºÍsun.ne ......
19.1.1. Spring¶Ôlog4jµÄ¼¸¸öÔöÇ¿
×¢Òâ
¸öÈ˽¨Ò鶼²»ÒªÊ¹Óá£
¶¨Ê±Ë¢ÐÂlog4j.properties£¬ÎÞÐëÖØÆô·þÎñÆ÷¸üÐÂlog4jÉèÖá£ËäÈ»ÕâÊǸöJ2EE Best
Practice£¬µ«ÔÚSpringµÄJavaDocÀï×¢Ã÷Á˲»ÍƼöÓÃÓÚÉú²ú»·¾³£¬ÒòΪ·þÎñÆ÷ÖØÆôµÄʱºò£¬ÄÇÌõwatch thread²»»á¹Ø±Õ¡£
½«
log4j.propertiesÎļþ·ÅÔÚWEB-INF/log4j.properti ......
ÊÇ·ñÑá¾ëÁËÓÃxmlÎļþÀ´×öMagentoµÄÒ³Ãæ²¼¾Ö£¬ÊǵĻ°À´ÊÔÊÔÏÂÃæÕâÖÖ·½Ê½£¬°Ñ²¼¾Ö´úÂëдµ½controller ÀïÃæ
public function mycoolAction()
{
/* ... Some code ...*/
$update = $this->getLayout()->getUpdate();
/* ... Some code ...*/
$this->addActionLayoutHandles();
/* ... Some code ...*/
......
1 ÀàËÆxmlns=""µÄÎļþ
ʾÀýXMLÎļþ:
<?xml version="1.0" encoding="UTF-8"?>
<WebSrvMessage xmlns="http://www.lenoval.com/">
<version>1.0</version>
<DataContent>
<DateTag>2010-5-17</DateTag>
</DataCont ......