libxml¿â½âÎöXMLÎļþ
Ð÷ÂÛ
LibxmlÊÇÒ»¸öÓÐÃâ·ÑÐí¿ÉµÄÓÃÓÚ´¦ÀíXML¡¢¿ÉÒÔÇáËÉ¿çÔ½¶à¸öƽ̨µÄCÓïÑÔ¿â¡£LibxmlʵÏÖÁ˶Á¡¢´´½¨¼°²Ù×ÝXMLÊý¾Ý¹¦ÄÜ¡£
Õâ¸öÖ¸ÄÏ»ùÓÚÒ»¸ö¼òµ¥µÄXMLÓ¦Óá£
Êý¾ÝÀàÐÍ
Libxml ¶¨ÒåÁËÐí¶àÊý¾ÝÀàÐÍ£¬ËüÒþ²ØÁËÔÓÂÒµÄÀ´Ô´ÒÔÖÂÄã²»±Ø´¦ÀíËü³ý·ÇÄãÓÐÌض¨µÄÐèÒª¡£xmlChar Ìæ´úchar,ʹÓÃUTF-8±àÂëµÄÒ»×Ö½Ú×Ö·û´®¡£Èç¹ûÄãµÄÊý¾ÝʹÓÃÆäËü±àÂ룬Ëü±ØÐ뱻ת»»µ½UTF-8²ÅÄÜʹÓÃlibxmlµÄº¯Êý¡£ÔÚlibxml±àÂëÖ§³ÖWEBÒ³ÃæÓиü¶à¹ØÓÚ±àÂëµÄÓÐÓÃÐÅÏ¢¡£
XmlDoc °üº¬ÓɽâÎöÎĵµ½¨Á¢µÄÊ÷½á¹¹£¬xmlDocPtrÊÇÖ¸ÏòÕâ¸ö½á¹¹µÄÖ¸Õë¡£
xmlNodePtr and xmlNode °üº¬µ¥Ò»½áµãµÄ½á¹¹xmlNodePtrÊÇÖ¸ÏòÕâ¸ö½á¹¹µÄÖ¸Õ룬Ëü±»ÓÃÓÚ±éÀúÎĵµÊ÷¡£
½âÎöÎĵµ
½âÎöÎĵµÊ±½ö½öÐèÒªÎļþÃû²¢Ö»µ÷ÓÃÒ»¸öº¯Êý£¬²¢ÓдíÎó¼ì²é¡£
¢Ù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½«Ö¸Ò»¸ö×¢²áµÄ´íÎó²¢Í£Ö¹¡£
×¢ÊÍ
Ò»¸ö³£¼û´íÎóÊDz»Êʵ±µÄ±àÂë¡£XML±ê×¼Îĵµ³ýÁËÓÃUTF-8»òUTF-16Í⻹¿ÉÓÃÆäËü±àÂë±£´æ¡£Èç¹ûÎĵµÊÇÕâÑù£¬libxml½«×Ô¶¯µØΪÄãת»»µ½UTF-8¡£
¢ÝÈ¡µÃÎĵµ¸ùÔªËØ
¢Þ¼ì²éÈ·Èϵ±Ç°ÎĵµÖаüº¬ÄÚÈÝ¡£
¢ßÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇÐèҪȷÈÏÎĵµÊÇÕýÈ·µÄÀàÐÍ¡£¡°Story¡±ÊÇÔÚÕâ¸öÖ¸ÄÏÖÐʹÓÃÎĵµµÄ¸ùÀàÐÍ¡£
È¡µÃÔªËØÄÚÈÝ
ÕÒµ½ÔÚÎĵµÊ÷ÖÐÒª²éÕÒµÄÔªËغó¿ÉÒÔÈ¡µÃËüµÄÄÚÈÝ¡£ÔÚÕâ¸öÀý×ÓÖÐÎÒÃDzéÕÒ¡°story¡±ÔªËØ¡£½ø³Ì½«ÔÚÈß³¤µÄÊ÷ÖвéÕÒÎÒÃǸÐÐËȤµÄÔªËØ¡£ÎÒÃǼٶ¨ÆÚÄãÒѾÓÐÁËÒ»¸öÃûΪdocµÄxmlDocPtrºÍÒ»¸öÃûΪcurµÄxmlNodPtr¡£
¢Ùcur = cur->xmlChildrenNode;
¢Úwhile (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){
parseStory (doc, cur);
}
cur = cur->next;
}
¢ÙÈ¡µÃcurµÄµÚÒ»¸ö×Ó½áµã£¬curÖ¸ÏòÎĵµµÄ¸ù£¬¼´¡°story¡±ÔªËØ¡£
Ïà¹ØÎĵµ£º
¶ÔXmlµÄ½Úµã½øÐмòµ¥²éѯµÄʱºò£¬³£ÓõĿÉÒÔʹÓÃÈçÏ·½·¨£º
(1) XmlNode node = doc.selectSingleNode("//AllNode/Node[@ID = ’aaa’]");
ÔÚÕû¸öXmlÖвéÕÒAllNode½ÚµãϵĽڵãÃûΪNodeµÄ½Úµã£¬¸Ã×Ó½ÚµãµÄIDÊôÐÔֵΪaaa
(2)XmlNode node = doc.selectSingleNode("//AllNode /*[@ID = ’aaa& ......
XSDÎļþ £¨XML Schema ÓïÑÔÒ²³Æ×÷ XML Schema ¶¨Ò壨XML Schema Definition£¬XSD£©¡£ ¾ßÌåʹÓ÷½·¨ºÍ¶¨ÒåÇë²Î¿´£º
http://www.w3school.com.cn/schema/index.asp
java×Ôjdk1.5ÒÔÉÏÐÂÔöÁËSchemaFactoryÀà ¿ÉÒÔʵÏÖ¶ÔXSDÑéÖ¤µÄÖ§³Ö£¬Ê¹ÓÃÆðÀ´Ò²ºÜ·½±ã¡£
ÒÔÏ´úÂë¿ÉÓÃÔÚJDK1.5+ ÑéÖ¤xml
public class SimpleErrorHandler i ......
ʲôÊÇ XML?
XML Ö¸¿ÉÀ©Õ¹±ê¼ÇÓïÑÔ£¨EXtensible Markup Language£©
XML ÊÇÒ»ÖÖ±ê¼ÇÓïÑÔ£¬ºÜÀàËÆ HTML
XML µÄÉè¼Æ×ÚÖ¼ÊÇ´«ÊäÊý¾Ý£¬¶ø·ÇÏÔʾÊý¾Ý
XML ±êǩûÓб»Ô¤¶¨Òå¡£ÄúÐèÒª×ÔÐж¨Òå±êÇ©¡£
XML ±»Éè¼ÆΪ¾ßÓÐ×ÔÎÒÃèÊöÐÔ¡£
XML ÊÇ W3C µÄÍƼö±ê×¼
XML Óë HTML µÄÖ÷Òª²îÒì
XML ²»ÊÇ HTML µÄÌæ´ú¡£
XML ºÍ HTML Ϊ² ......
¡¡¡¡ÔÚÉÏһƪÎÄÕÂÖУ¬ÎÒÃÇÌÖÂÛÁËÈçºÎͨ¹ýjavascript´ÓÒ»¸öÔ¶³ÌXMLÎļþÖÐÈ¡µÃÊý¾Ý¡£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒÃǽ«Ñ§»áÔõÑù¶ÔÊý¾Ý×÷¸ü¸´ÔӵĴ¦Àí¡£×÷Ϊһ¸öʾÀý£¬ÎÒÃÇ»á×¼±¸Ò»×éXMLÊý¾Ý£¬½«Êý¾Ý·Ö¸î³É¶ÀÁ¢µÄƬ¶Ï²¢ÒÔ²»Í¬µÄ·½Ê½Õ¹Ê¾ÕâЩƬ¶Ï£¨È¡¾öÓÚËüÃÇÊÇÈçºÎ±»±êʶµÄ£©¡£
¡¡¡¡ÕâƪÎÄÕÂÊǽ¨Á¢ÔÚÉÏһƪÎÄÕÂÖй¹ÔìµÄʾÀý´úÂëµÄ»ù´¡Ö®ÉÏ ......