ÓÃVC++2005¶ÁXMLÎļþµÄСÀý×Ó
1¡£Ð´Ò»¸öxmlÎļþ
<?xml version="1.0" encoding="utf-8" ?>
- <root>
- <user id="101">
<name>abc</name>
<password>abc</password>
</user>
- <user id="102">
<name>ccc</name>
<password>ccc</password>
</user>
</root>
2¡£Ð½¨Ò»¸övc++2005¹¤³Ì ¿ÉÒÔÊǶԻ°¿ò¹¤³Ì ÒòΪֻÊǾÙÀý˵Ã÷
£¨1£©ÔÚ¶Ô»°¿òµÄ.HÎļþÌí¼Ó
#import "msxml3.dll"
using namespace MSXML2;
£¨2£©ÔÚ³õʼ»¯º¯ÊýÀïÌí¼Ó
try
{
CoInitialize(NULL);//³õʼ»¯COM×é¼þ
MSXML2::IXMLDOMDocumentPtr pDoc;
HRESULT hr=pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument)) ;//´´½¨Ò»¸öCOM½ø³Ì
if(!SUCCEEDED(hr))
{
AfxMessageBox(_T("FAILSE"),MB_OK,NULL);
}
pDoc->load("d:\\user.xml");//xmlÎļþµÄµØÖ· ÎÒ·ÅÔÚDÅÌÏÂÁË Ò²¿ÉÒÔд³ÉÏà¶ÔµØÖ·
MSXML2::IXMLDOMNodeListPtr pNodeList=NULL;//¶¨Òå½ÚµãÁбí
pNodeList=pDoc->selectNodes("root/user");//Ñ¡Ôñ½Úµã
MSXML2::IXMLDOMNodePtr pSubNode;
CString strTemp;
for(int i=0;i<(pNodeList->Getlength());i++)//ÅжÏÓм¸¸ö½Úµã
{
pSubNode=pNodeList->nextNode()->selectSingleNode("name");
_bstr_t strRequestType=pSubNode->Gettext();
strTemp=strRequestType.operator char*();
AfxMessageBox(strTemp,MB_OK,NULL);
}
}
catch (...)
{
AfxMessageBox(_T("Òì³£"));
}
Ïà¹ØÎĵµ£º
±¾ÎĽéÉÜÁ˸÷ÖÖ½âÎö·½·¨£¬×ÅÖØ·ÖÎöÁ˸÷×ÔµÄÓÅȱµã:
½âÎöµÄÖØÒªÐÔ
¡¡¡¡½âÎöÎªÊ²Ã´ÖØÒª?ÒòΪËùÓÐ XML ´¦Àí¶¼´Ó½âÎö¿ªÊ¼¡£ÎÞÂÛʹÓø߲ã±à³ÌÓïÑÔ(Èç XSLT)»¹ÊǵͲã Java ±à³Ì£¬µÚÒ»²½¶¼ÊÇÒª¶ÁÈë XML Îļþ£¬½âÂë½á¹¹ºÍ¼ìË÷ÐÅÏ¢µÈµÈ£¬Õâ¾ÍÊǽâÎö¡£
¡¡¡¡½âÎöÎĵµÊ±ÃæÁٵĵÚÒ»¸öÑ¡ÔñÊDzÉÓÃÏֳɵĽâÎö¿â(»ù±¾ÉÏÿÖÖ±à³ÌÓïÑÔ¶¼Ó ......
ËùÓÐ XML ÎĵµÖеÄÎı¾¾ù»á±»½âÎöÆ÷½âÎö¡£
Ö»ÓÐ CDATA Çø¶Î£¨CDATA section£©ÖеÄÎı¾»á±»½âÎöÆ÷ºöÂÔ¡£
Parsed Data
XML ½âÎöÆ÷ͨ³£»á½âÎö XML ÎĵµÖÐËùÓеÄÎı¾¡£
µ±Ä³¸ö XML ÔªËØ±»½âÎöʱ£¬Æä±êǩ֮¼äµÄÎı¾Ò²»á±»½âÎö£º
<message>´ËÎı¾Ò²»á±»½âÎö</message>
½âÎöÆ÷Ö®ËùÒÔÕâô×öÊÇÒòΪ XML ÔªËØ¿É°ü ......
[C/C++ Digestion] –
×Ôµ×ÏòÉϵØÌ½¾¿Ð麯Êý
×÷Õߣº
Jason Lee @
http://blog.csdn.net/jasonblog
ÈÕÆÚ£º
2010-05-19
»·¾³£º
Visual C++ Express
2008
ÉùÃ÷£º±¾ÎÄ·¢±íÔÚ
csdn
²©¿Í£¬ÈçÓÐ×ªÔØ£¬Çë×¢Ã÷³ö´¦
[1]C++
¶ÔÏóÄ£ÐÍ»ù´¡
Ò»¸öÀàÖпÉÒÔ°üº¬¾²Ì¬Êý¾Ý³ÉÔ±¡¢¾²Ì¬³ÉÔ±º¯Êý¡¢·Ç¾²Ì¬³ÉÔ±º¯Êýº ......
(ת)C/C++ÖеÄÈÕÆÚºÍʱ¼ä time_tÓëstruct tmת»»
ͻ񻣼
±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼ÆÊ±¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£ºUTC£¨ÊÀ½ç±ê ......