³õѧXML£¨Ò»£©
XML¶¨Ò壺Óɱê¼Ç¼°ÆäËù±ê¼ÇµÄÄÚÈݹ¹³ÉµÄÎı¾Îļþ¡£
XML×÷ÓãºÓÃÀ´ÃèÊöÊý¾ÝµÄ½á¹¹£¬ÓÐЧ·ÖÀëÊý¾ÝµÄ½á¹¹ºÍ±íʾ£¬¿ÉÒÔ×÷ΪÊý¾Ý½»»»µÄ±ê×¼¸ñʽ¡£
XMLÌص㣺1¡¢¿ÉÒÔ×Ô¶¨Òå±ê¼Ç£¬±ê¼ÇÃû³ÆÊǶÔËù±ê¼ÇµÄÊý¾ÝÄÚÈݺ¬ÒåµÄ³éÏ󣬶ø²»ÊÇÊý¾ÝµÄÏÔʾ¸ñʽ¡£
2¡¢XMLÖ»¹ØÐÄÊý¾ÝµÄ×éÖ¯»ú¹¹£¬ÒÔ±ãXML½âÎöÆ÷°´ÕÕÆä½á¹¹·Ö½â³öÊý¾Ý¡£XML±¾Éí²»ÌṩÊý¾ÝµÄÏÔʾ¸ñʽ¡£
ÈçºÎÀ´ÏÔʾXMLÎļþµÄ±ê¼ÇÄÚÈÝÄØ£¿
1¡¢¼ÈÈ»ä¯ÀÀÆ÷²»ÄÜÖ±½ÓÏÔʾXMLÎļþµÄ±ê¼ÇÄÚÈÝ£¬ÄÇôÎÒÃǾÍÐèÒªÒÔijÖÖ·½Ê½¸æËßä¯ÀÀÆ÷ÈçºÎÏÔʾ¡£
2¡¢ÓÐÁ½ÖÖ·½Ê½¡£Ò»£ºÊ¹ÓÃCSS£¨²ãµþÑùʽ±í£©,¶þ£ºÊ¹ÓÃXSL½»»»£¨ÒÔºóÔÙÏêÊö£©¡£
ÏÂÃæ¾Ù¸öÀý×Ó¡£½«XMLÎļþºÍCSS¹ØÁªÆðÀ´¡£
ÔÚCSSÖУ¬×îÖØÒªµÄ×é³É²¿·Ö¾ÍÊÇÑùʽ±í£¬Æä×÷ÓãºËµÃ÷XMLÎļþÖеıê¼ÇÄÚÈÝÓúÎÖÖ·½Ê½ÏÔʾ¡£±ÈÈ磺
ÏëÓúÚÌåÀ´ÏÔʾXMLÎļþÖеıê¼Ç”<name>...</name>“Ëù±ê¼ÇµÄÄÚÈÝ£¬ÈçÏ£º
name
{
display:block;font-size:16pt;font-weight:bold;
}
¸ÃÑùʽ±íµÄ×÷ÓÃÊǸæÖªä¯ÀÀÆ÷½«±ê¼Ç”<name>...</name>“Ëù±ê¼ÇµÄÄÚÈÝÏÔʾÔÚÒ»¸ö”¿éÇøÓò“ÖС£
ÒÔÏÂΪһ¸ö¼òµ¥µÄCSS¡£show.css.
name
{
display:block;font-size:16pt;color: #FF6600;font-weight:bold;
}
sex
{
display:line;font_size:18pt;color: #FF6600;font-weight:bold
}
birthday
{
display:line;font-size:9pt;color: #FF6600;font-weight;bold
}
ÔÙдһ¸öXMLÎļþ£ºa.xml
<?xml version="1.0" ?>
<?xml-stylesheet href="show.css" type="text/css" ?>
<man>
<name>
ÕÅÈý
<sex> ÄÐ </sex>
<birthday> 1984Äê8ÔÂ1ÈÕ</birthday>
</name>
<name>
ÀîËÄ
<sex> Å® </sex>
<birthday> 1985Äê8ÔÂ10ÈÕ</birthday>
</name>
</man>
ÐèҪעÒ⣺1¡¢ÔÚXMLÖУ¬Ã¿¸ö±ê¼Ç¶¼±ØÐë°üÀ¨¿ªÊ¼±ê¼ÇºÍ½áÊø±ê¼Ç¡£ËüÃÇÖ®¼äµÄÄÚÈÝΪ±ê¼ÇÄÚÈÝ¡£
2¡¢Ò»¸ö±ê¼ÇµÄÄÚÈÝ¿ÉÒÔ°üº¬Îı¾ºÍÆäËûµÄ±ê¼Ç¡£
3¡¢±
Ïà¹ØÎĵµ£º
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.org/config/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/bea ......
xmlÎļþ
£¼?xml version="1.0" encoding="GB2312"?£¾
£¼RESULT£¾
£¼VALUE£¾
¡¡¡¡ £¼NO£¾A1234£¼/NO£¾
¡¡¡¡ £¼ADDR£¾ËÄ´¨Ê¡XXÏØXXÕòXX·X¶ÎXXºÅ£¼/ADDR£¾
£¼/VALUE£¾
£¼VALUE£¾
¡¡¡¡ £¼NO£¾B1234£¼/NO£¾
¡¡ ¡¡£¼ADDR£¾ËÄ´¨Ê¡XXÊÐXXÏçXX´åXX×飼/ADDR£¾
£¼/VALUE£¾
£¼/RESULT£¾
ÐèҪʲô°ü×Ô¼ºµ½ÍøÉÏ ......
ÔÚÏîÄ¿ÖУ¬ÎÒÃǺܶ඼Óõ½ÁËxmlÎļþ£¬ÎÞÂÛÊDzÎÊýÅäÖû¹ÊÇÓëÆäËüϵͳµÄÊý¾Ý½»»¥¡£
½ñÌì¾ÍÀ´½²Ò»ÏÂJava ÖÐʹÓÃdom4jÀ´²Ù×÷XMLÎļþ¡£
ÎÒÃÇÐèÒªÒýÈëµÄ°ü£º
//Îļþ°ü
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
//¹¤¾ß°ü
import java.util.Itera ......
Õâ¸ö¶«Î÷¹¦Äܼܺòµ¥£¬Ã»ÓÐʲô¼¼Êõº¬Á¿¡£Ö»ÊǼǼһÏ¡£
xml µÄÊý¾Ý»ñÈ¡ºó£¬¿ÉÒÔͨ¹ýÒ»¸ö¼òµ¥·ÖÒ³´¦ÀíÀ´Íê³É¼òµ¥·ÖҳЧ¹û¡£
1.ÀûÓÃÇóÓàºÍ³ý·¨µÄ·½·¨ÅжÏÒ³Êý
Õâ¸öÊÇÒ»¸ö±È½Ï³£¼ûµÄ×ö·¨£¬Ò²ÊÇÒ»ÖÖ°ì·¨¡£ÔÚÕâÀ²»¶ÔÕâÖÖ·ÖÒ³´¦ÀíÒª´ïµ½Ê²Ã´×îÓÅ»¯µÄЧ¹û½øÐÐÌÖÂÛ£¬ÕâÀïÖ»ÊÇ̽ÌÖÒ»ÖÖ°ì·¨¡£¶ÔһР......