xmlµÄCDATA Çø¶Î
ËùÓÐ XML ÎĵµÖеÄÎı¾¾ù»á±»½âÎöÆ÷½âÎö¡£
Ö»ÓÐ CDATA Çø¶Î£¨CDATA section£©ÖеÄÎı¾»á±»½âÎöÆ÷ºöÂÔ¡£
Parsed Data
XML ½âÎöÆ÷ͨ³£»á½âÎö XML ÎĵµÖÐËùÓеÄÎı¾¡£
µ±Ä³¸ö XML ÔªËر»½âÎöʱ£¬Æä±êÇ©Ö®¼äµÄÎı¾Ò²»á±»½âÎö£º
<message>´ËÎı¾Ò²»á±»½âÎö</message>
½âÎöÆ÷Ö®ËùÒÔÕâô×öÊÇÒòΪ XML ÔªËØ¿É°üº¬ÆäËûÔªËØ£¬¾ÍÏñÕâ¸öÀý×ÓÖУ¬ÆäÖÐµÄ <name> ÔªËØ°üº¬×ÅÁíÍâµÄÁ½¸öÔªËØ(first ºÍ last)£º
<name><first>Bill</first><last>Gates</last></name>
¶ø½âÎöÆ÷»á°ÑËü·Ö½âΪÏñÕâÑùµÄ×ÓÔªËØ£º
<name>
<first>Bill</first>
<last>Gates</last>
</name>
תÒå×Ö·û
·Ç·¨µÄ XML ×Ö·û±ØÐë±»Ì滻ΪʵÌåÒýÓã¨entity reference£©¡£
¼ÙÈçÄúÔÚ XML ÎĵµÖзÅÖÃÁËÒ»¸öÀàËÆ "<" ×Ö·û£¬ÄÇôÕâ¸öÎĵµ»á²úÉúÒ»¸ö´íÎó£¬ÕâÊÇÒòΪ½âÎöÆ÷»á°ÑËü½âÊÍΪÐÂÔªËصĿªÊ¼¡£Òò´ËÄã²»ÄÜÕâÑùд£º
<message>if salary < 1000 then</message>
ΪÁ˱ÜÃâ´ËÀà´íÎó£¬ÐèÒª°Ñ×Ö·û "<" Ì滻ΪʵÌåÒýÓ㬾ÍÏñÕâÑù£º
<message>if salary < 1000 then</message>
ÔÚ XML ÖÐÓÐ 5 ¸öÔ¤¶¨ÒåµÄʵÌåÒýÓãº
<
<
СÓÚ
>
>
´óÓÚ
&
&
ºÍºÅ
'
'
Ê¡ÂÔºÅ
"
"
ÒýºÅ
×¢ÊÍ£ºÑϸñµØ½²£¬ÔÚ XML ÖнöÓÐ×Ö·û "<"ºÍ"&" ÊÇ·Ç·¨µÄ¡£Ê¡ÂԺš¢ÒýºÅºÍ´óÓÚºÅÊǺϷ¨µÄ£¬µ«ÊÇ°ÑËüÃÇÌ滻ΪʵÌåÒýÓÃÊǸöºÃµÄÏ°¹ß¡£
CDATA
CDATA ÄÚ²¿µÄËùÓж«Î÷¶¼»á±»½âÎöÆ÷ºöÂÔ¡£
¼ÙÈçÎı¾Öаüº¬ÁË´óÁ¿µÄ "<" ºÍ "&" ×Ö·û - ¾ÍÏñ±à³Ì´úÂëÖо³£³öÏÖµÄÇé¿öÒ»Ñù - ÄÇôÕâ¸ö XML ÔªËؾͿÉÒÔ±»¶¨ÒåΪһ¸ö CDATA ²¿·Ö¡£
CDATA Çø¶Î¿ªÊ¼ÓÚ "<![CDATA["£¬½áÊøÓÚ "]]>"£º
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0)
{
return 1
}
else
{
return 0
}
}
]]>
</script>
ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÔÚ CDATA Çø¶ÎÖеÄËùÓж«Î÷¶¼»á±»½âÎöÆ÷ºöÂÔ¡£
¹ØÓÚ CDATA Çø¶ÎµÄ×¢ÊÍ£º
CDATA Çø¶Î²»ÄÜ°üº¬×Ö·û´® "]]>"£¬ËùÒÔ£¬CDATA Çø¶ÎµÄǶÌ×ÊDz»±»ÔÊÐíµÄ¡£
ͬʱҲÐèҪȷ±£ÔÚ "]]>" ×Ö·û´®ÖÐûÓпոñ»òÕÛÐС£
Ïà¹ØÎĵµ£º
JAVATMÓëXML 2010-05-14
Ò»¡¢¸ÅÄî
l ÈκÎXMLÎĵµ¶ÔÈκÎÀàÐ͵ÄÓ¦ÓÃÒÔ¼°ÕýÈ·µÄ½âÎö¶¼±ØÐë¾ßÓÐÁ¼ºÃµÄ½á¹¹well-formed
l XMLÎĵµ¿ÉÒÔÊÇÓÐЧµØ£¨valid£©£¬µ«²¢·ÇÒ»¶¨ÒªÇóÓÐЧ¡£
l PI£¨processing instruction£©¸ñʽ£º<?target instructions?>¡£XMLÖеĴ¦ÀíÖ¸ÁîÖ»ÄÜÊǽâÎöÆ÷¿ÉÒÔʶ±ðµÄXML±ê×¼´¦ÀíÃüÁ ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Text; ......
xml:
<?xml version="1.0" encoding="utf-8" ?>
<library>
<name>Ê׶¼Í¼Êé¹Ý</name>
<address>³¯ÑôÇø»ªÍþÇÅÄÏ</address>
<books>
<book>
<id>0000</id>
</book>
< ......
using System.Xml;
//³õʼ»¯Ò»¸öxmlʵÀý
XmlDocument xml=new XmlDocument();
//µ¼ÈëÖ¸¶¨xmlÎļþ
xml.Load(path);
xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
//Ö¸¶¨Ò»¸ö½Úµã
XmlNode root=xml.SelectSingleNode("/root");
//»ñÈ¡½ÚµãÏÂËùÓÐÖ±½Ó×Ó½Úµã
XmlNodeList childlist=root ......