vc6 怎么用xml? 传说, xml流行,问问。plz,give a simple! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用msxml可以解析xml的。xml本身没有什么神奇的。要结合具体应用。 BOOL CWeatherForecast::WriteWeatherIntoFile(CString strWeather,CString strFileName){ COleDateTime odtDate; CString strPath,strPathFile; TCHAR * ptPath; CString strMonth,strDay; ptPath=strPath.GetBuffer(_MAX_PATH); ::GetModuleFileName(AfxGetInstanceHandle(),ptPath,_MAX_PATH); strPath.ReleaseBuffer(); ptPath=NULL; strPathFile=strPath.Left(strPath.ReverseFind(_T('\\'))+1)+strFileName; if ( !PathFileExists (strPathFile) ) return FALSE ; if( FALSE == ExtractDateAndMonth( strDay , strMonth , strWeather )) { return FALSE; } //The following codes are used to generate COleDateTime object if( strMonth != CString("1") || COleDateTime::GetCurrentTime().GetMonth() != 12 ) { odtDate.SetDate( COleDateTime::GetCurrentTime().GetYear() , _ttoi(strMonth), atoi(strDay) ); } else{ odtDate.SetDate( COleDateTime::GetCurrentTime().GetYear() +1 , _ttoi(strMonth), atoi(strDay) ); } TRACE0(odtDate.Format()); try { BOOL bUpdated = FALSE ; IXMLDOMDocumentPtr pXMLDom; HRESULT hr; hr= pXMLDom.CreateInstance(__uuidof(DOMDocument40)); if (FAILED(hr)) { return FALSE; } pXMLDom->async = VARIANT_FALSE; // default - true, pXMLDom->validateOnParse= VARIANT_FALSE; if(pXMLDom->load((_bstr_t)strPathFile)!=VARIANT_TRUE) { return FALSE; } IXMLDOMNodeListPtr pnl = pXMLDom->selectNodes("/weather/*"); IXMLDOMNodePtr pNode=NULL; for (int i=0; i<pnl->length; i++) { pNode = pnl->item[i]; COleDateTime odtXMLDate(pNode->attributes->getNamedItem("date")->nodeTypedValue); if(odtXMLDate==odtDate) { pNode->text=(_bstr_t)strWeather; bUpdated = TRUE; break; } } if ( ! bUpdated ){ IXMLDOMElementPtr pe; pe = pXMLDom->createElement("weatherreport"); if (pe != NULL) { // Add newline + tab for indentation. pXMLDom->documentElement->appendChild(pXMLDom->createTextNode("\n\t")); pe->text = (_bstr_t)strWeather; IXMLDOMAttributePtr pa; pa = pXMLDom->createAttribute("date"); if (pa != NULL) { _variant_t varDate; varDate.ChangeType(VT_DATE); varDate.date=odtDate; //memcpy( &varDate,&odtDate,sizeof() ); pa->value =varDate ; pe->setAttributeNode(pa); pa.Release(); } pXMLDom->documentElement->appendChild(pe); // Add newline + tab for indentation. pXMLDom->documentElement->appendChild(pXMLDom->createTextNode("\n")); pe.Release(); } } if(FAILED(pXMLDom->save((_bstr_t)strPathFile))) { return FALSE; } pXMLDom.Release(); pnl.Release(); } catch(_com_error &ex) { TRACE(ex.ErrorMessage()); } return TRUE;} ocx加载在JSP页面 GetSafeHwnd为空 cstring to char 不是cstring to char*??? 求解:关于WinSock的C/S服务 gina在2K下和xp下有不同么?? VC6中使用ADO执行SQL语句时可以用变量代替SQL语句里的条件吗? 帮帮忙,谢谢~~~~~~~~~~~~~~~~` Win32是否有打开目录的通用对话框? 实现透明CEdit控件,,送高分!! 在dll中怎么样用一个icon或者bitmap资源 有多个客端同时上传大文件,服务端如何接受有没有好的方法。谢谢 求助:为什么程序会结束?请大侠赐教。 如何进一步提高网络编程水平
{
COleDateTime odtDate;
CString strPath,strPathFile;
TCHAR * ptPath;
CString strMonth,strDay;
ptPath=strPath.GetBuffer(_MAX_PATH);
::GetModuleFileName(AfxGetInstanceHandle(),ptPath,_MAX_PATH);
strPath.ReleaseBuffer();
ptPath=NULL; strPathFile=strPath.Left(strPath.ReverseFind(_T('\\'))+1)+strFileName; if ( !PathFileExists (strPathFile) )
return FALSE ; if( FALSE == ExtractDateAndMonth( strDay , strMonth , strWeather ))
{
return FALSE;
}
//The following codes are used to generate COleDateTime object
if( strMonth != CString("1") || COleDateTime::GetCurrentTime().GetMonth() != 12 )
{
odtDate.SetDate( COleDateTime::GetCurrentTime().GetYear() , _ttoi(strMonth), atoi(strDay) );
}
else{
odtDate.SetDate( COleDateTime::GetCurrentTime().GetYear() +1 , _ttoi(strMonth), atoi(strDay) );
}
TRACE0(odtDate.Format()); try
{
BOOL bUpdated = FALSE ;
IXMLDOMDocumentPtr pXMLDom;
HRESULT hr;
hr= pXMLDom.CreateInstance(__uuidof(DOMDocument40));
if (FAILED(hr))
{
return FALSE;
}
pXMLDom->async = VARIANT_FALSE; // default - true,
pXMLDom->validateOnParse= VARIANT_FALSE;
if(pXMLDom->load((_bstr_t)strPathFile)!=VARIANT_TRUE)
{
return FALSE;
}
IXMLDOMNodeListPtr pnl = pXMLDom->selectNodes("/weather/*");
IXMLDOMNodePtr pNode=NULL;
for (int i=0; i<pnl->length; i++)
{
pNode = pnl->item[i];
COleDateTime odtXMLDate(pNode->attributes->getNamedItem("date")->nodeTypedValue);
if(odtXMLDate==odtDate)
{
pNode->text=(_bstr_t)strWeather;
bUpdated = TRUE;
break;
}
} if ( ! bUpdated ){
IXMLDOMElementPtr pe;
pe = pXMLDom->createElement("weatherreport");
if (pe != NULL)
{
// Add newline + tab for indentation.
pXMLDom->documentElement->appendChild(pXMLDom->createTextNode("\n\t"));
pe->text = (_bstr_t)strWeather;
IXMLDOMAttributePtr pa;
pa = pXMLDom->createAttribute("date");
if (pa != NULL)
{
_variant_t varDate;
varDate.ChangeType(VT_DATE);
varDate.date=odtDate;
//memcpy( &varDate,&odtDate,sizeof() );
pa->value =varDate ;
pe->setAttributeNode(pa);
pa.Release();
}
pXMLDom->documentElement->appendChild(pe); // Add newline + tab for indentation.
pXMLDom->documentElement->appendChild(pXMLDom->createTextNode("\n"));
pe.Release();
}
} if(FAILED(pXMLDom->save((_bstr_t)strPathFile)))
{
return FALSE;
}
pXMLDom.Release();
pnl.Release();
}
catch(_com_error &ex)
{
TRACE(ex.ErrorMessage());
}
return TRUE;
}