xml Îĵµ½âÎö
XMLÎļþµÄ½âÎö££libxml¿âº¯Êý½âÊÍ
ÕªÒª
LibxmlÊÇÒ»¸öÓÐÃâ·ÑÐí¿ÉµÄÓÃÓÚ´¦ÀíXML¡¢¿ÉÒÔÇáËÉ¿çÔ½¶à¸öƽ̨µÄCÓïÑÔ¿â¡£Õâ¸öÖ¸ÄÏÌṩËüµÄ»ù±¾º¯ÊýµÄÀý×Ó¡£
Ð÷ÂÛ
Libxml ÊÇÒ»¸öʵÏÖ¶Á¡¢´´½¨¼°²Ù×ÝXMLÊý¾Ý¹¦ÄܵÄCÓïÑÔ¿â¡£Õâ¸öÖ¸ÄÏÌṩÀý×Ó´úÂë²¢¸ø³öËü»ù±¾¹¦ÄܵĽâÊÍ¡£ÔÚÕâ¸öÏîÄ¿µÄÖ÷Ò³ÉÏÓÐLibxml¼°¸ü¶à¹ØÓÚËü¿ÉÓõÄ×ÊÁÏ¡£°üº¬ÓÐÍêÕûµÄAPIÎĵµ¡£Õâ¸öÖ¸Äϲ¢²»ÄÜÌæ´úÕâЩÍêÕûµÄÎĵµ£¬µ«ÊDzûÃ÷¹¦ÄÜÐèҪʹÓÿâÀ´Íê³É»ù±¾²Ù×÷¡£
Õâ¸öÖ¸ÄÏ»ùÓÚÒ»¸ö¼òµ¥µÄXMLÓ¦Óã¬ËüʹÓÃÎÒдµÄһƪÎÄÕÂÉú³É£¬Ëü°üº¬ÓÐÔªÊý¾ÝºÍÎÄÕµÄÖ÷Ìå¡£
±¾Ö¸ÄÏÖеÄÀý×Ó´úÂëʾ·¶ÈçºÎ×öµ½£º
• ½âÎöÎĵµ
• È¡µÃÖ¸¶¨ÔªËصÄÎı¾
• Ìí¼ÓÒ»¸öÔªËؼ°ËüµÄÄÚÈÝ
• Ìí¼ÓÒ»¸öÊôÐÔ
• È¡µÃÒ»¸öÊôÐÔµÄÖµ
Àý×ÓµÄÍêÕû´úÂë°üº¬ÔÚ¸½Â¼ÖÐ
Êý¾ÝÀàÐÍ
Libxml ¶¨ÒåÁËÐí¶àÊý¾ÝÀàÐÍ£¬ÎÒÃǽ«·´¸´Åöµ½ËüÃÇ£¬ËüÒþ²ØÁËÔÓÂÒµÄÀ´Ô´ÒÔÖÂÄã²»±Ø´¦ÀíËü³ý·ÇÄãÓÐÌض¨µÄÐèÒª¡£xmlChar Ìæ´úchar,ʹÓÃUTF-8±àÂëµÄÒ»×Ö½Ú×Ö·û´®¡£Èç¹ûÄãµÄÊý¾ÝʹÓÃÆäËü±àÂ룬Ëü±ØÐ뱻ת»»µ½UTF-8²ÅÄÜʹÓÃlibxmlµÄº¯Êý¡£ÔÚlibxml±àÂëÖ§³ÖWEBÒ³ÃæÓиü¶à¹ØÓÚ±àÂëµÄÓÐÓÃÐÅÏ¢¡£
XmlDoc °üº¬ÓɽâÎöÎĵµ½¨Á¢µÄÊ÷½á¹¹£¬xmlDocPtrÊÇÖ¸ÏòÕâ¸ö½á¹¹µÄÖ¸Õë¡£
xmlNodePtr and xmlNode °üº¬µ¥Ò»½áµãµÄ½á¹¹xmlNodePtrÊÇÖ¸ÏòÕâ¸ö½á¹¹µÄÖ¸Õ룬Ëü±»ÓÃÓÚ±éÀúÎĵµÊ÷¡£
½âÎöÎĵµ
½âÎöÎĵµÊ±½ö½öÐèÒªÎļþÃû²¢Ö»µ÷ÓÃÒ»¸öº¯Êý£¬²¢ÓдíÎó¼ì²é¡£ÍêÕû´úÂ룺¸½Â¼C, KeywordÀý³Ì´úÂë
¢ÙxmlDocPtr doc;
¢ÚxmlNodePtr cur;
¢Ûdoc = xmlParseFile(docname);
¢Üif (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
return;
}
¢Ýcur = xmlDocGetRootElement(doc);
¢Þif (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return;
}
¢ßif (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
fprintf(stderr,"document of the wrong type, root node != story");
xmlFreeDoc(doc);
return;
}
¢Ù¶¨Òå½âÎöÎĵµÖ¸Õë¡£
¢Ú¶¨Òå½áµãÖ¸Õë(ÄãÐèÒªËüΪÁËÔÚ¸÷¸ö½áµã¼äÒƶ¯)¡£
¢Ü¼ì²é½âÎöÎĵµÊÇ·ñ³É¹¦£¬Èç¹û²»³É¹¦£¬libxml½«Ö¸Ò»¸ö×
Ïà¹ØÎĵµ£º
½ÓÉÏһƪ
ÏÔʾËùÓнáµãµÄÄÚÈÝ
1 ÔxmlÎļþ bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book ISBN="1234123">
<title>who am i </title>
<author>who</author>
<price> ......
Ìí¼Ó¼Ç¼µ½ds±£´æµ½xml
DataSet ds = new DataSet("myDs");
//´ÓXMLÖжÁÈ¡Êý¾Ý
ds.ReadXml(Serve ......
5. ÃüÃû¹æÔò£¨²»ÄÜ°üÀ¨ xml£¬¿Õ¸ñ£¬¼âÀ¨ºÅ£¬µÈÌØÊâ·ûºÅ£¬²»ÄÜÊý×Ö¿ªÍ·£©
6. ¿ÉÒÔ×Ô´øÊôÐÔ¡£ÊôÐÔÖµÓÓ”±êʾ
7. ×¢ÊÍ<!--×¢Ê͵ÄÄÚÈÝ-->
8. Èç¹ûÒªÏÔʾÌØÊâ·ûºÅ¿ÉÓÃ<![CDATA[ ÕâÀïдÌØÊâ·ûºÅ ]]>
´´½¨
var xml:XML=<shuiGuo>
& ......
Ò». ²»Í¬XML¸ñʽÉϵIJîÒì
<Bil BilID="09120005">
<Product PID="XS000-3">
<Package Needuan="10"/>
<Package Needuan="8"/>
</Product>
</Bil>
Óë
<channel>
<title>Meerkat: An Open2 Wire Service</title>
<link>http://meerkat. ......
1£©
XMLÊÇÒ»ÏîÈÈÃŵļ¼Êõ¡£ËüÖ®ËùÒÔÄܹ»ÒýÆðÈËÃǵÄÐËȤ£¬Ò»¸öÖ÷ÒªµÄÔÒòÔÚÓÚËüÊ®·ÖµÄ¼òµ¥£¬ÈËÃÇ¿ÉÒÔºÜÈÝÒ×µØÀí½âºÍʹÓÃËü¡£Ã¿Ò»¸ö³ÌÐòÔ±¶¼ÄÜÇáÒ׵ؿ´¶®Ò»¸öXMLÎļþ£¬Àí½âËü°üº¬µÄÄÚÈÝ¡£
.NETÖаüº¬Á˺ܶàÖ§³ÖXMLµÄÀ࣬ÕâЩÀàʹµÃ³ÌÐòԱʹÓÃXML±à³Ì¾ÍÈçͬÀí½âXMLÎļþÒ»Ñù¼òµ¥¡£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒ½«¸ø³öÕâÑùµÄÒ»¸öÀàµÄʹÓÃʾ ......