如果是標(biāo)準(zhǔn)庫函數(shù), 都已經(jīng)封裝好了,直接引用對(duì)應(yīng)頭文件, 調(diào)用即可
創(chuàng)新互聯(lián)公司基于成都重慶香港及美國(guó)等地區(qū)分布式IDC機(jī)房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動(dòng)大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)成都移動(dòng)機(jī)房托管報(bào)價(jià),主機(jī)托管價(jià)格性價(jià)比高,為金融證券行業(yè)服務(wù)器托管,ai人工智能服務(wù)器托管提供bgp線路100M獨(dú)享,G口帶寬及機(jī)柜租用的專業(yè)成都idc公司。
如果是自己寫的C文件, 調(diào)用的時(shí)候 需要加上extern "C"聲明
/***************
?xml?version="1.0"?encoding="utf-8"?
Cases
case
No001/No
CopyFile?src="C:\test.txt"?dest="D:\test.txt"/CopyFile
/case
case
No002/No
DelFileC:\test.txt/DelFile
/case
/Cases
*******************/
//?我們用MFC來讀取上述xml,代碼如下:
void?ReadXml(CString?strXmlPath)
{
MSXML2::IXMLDOMDocumentPtr?pDoc;
::CoInitialize(NULL);
HRESULT?hr?=?pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));?
if?(!SUCCEEDED(hr))?
{??
MessageBox(_T("創(chuàng)建DOMDocument對(duì)象失敗。\n請(qǐng)檢查運(yùn)行環(huán)境"),?_T("錯(cuò)誤"),?MB_ICONERROR);?
return;
}
//?讀取xml
pDoc-put_async(VARIANT_FALSE);
VARIANT_BOOL?bhr?=?pDoc-load((_variant_t)strXmlPath);
if?(bhr?!=?VARIANT_TRUE)?{
MessageBox(_T("無法正確讀取xml文件"),?_T("錯(cuò)誤"),?MB_ICONERROR);
return;
}
//?根節(jié)點(diǎn)取得
MSXML2::IXMLDOMElementPtr?root?=?pDoc-documentElement;
//?取得根節(jié)點(diǎn)的名字
_variant_t?strRootName?=?root-nodeName;
_bstr_t?wstrRootName(strRootName.bstrVal);
MSXML2::IXMLDOMNodeListPtr?nodeList?=?root-GetchildNodes();//cases
//?解析cases的子節(jié)點(diǎn)
ReadCases(nodeList);
}
void?ReadCases(MSXML2::IXMLDOMNodeListPtr?nodeList)
{
int?ilength?=?nodeList-Getlength();
for?(int?nodeCount?=?0;?nodeCount??ilength;?nodeCount++)?{
MSXML2::IXMLDOMNodePtr?nodePtr?=?nodeList-nextNode();
_variant_t?strNodeName?=?nodePtr-GetnodeName();
_variant_t?strNodeValue?=?nodePtr-GetnodeValue();
//?讀取case節(jié)點(diǎn)下的子節(jié)點(diǎn)
ReadCase(nodePtr-GetchildNodes());
}
}
void?ReadCase(MSXML2::IXMLDOMNodeListPtr?nodeList)
{
CString?strLogInfo;
strLogInfo.Empty();
CString?strNo;??????????????//?case編號(hào)
CString?strSrcFile;?????????//?源文件
CString?strDestFile;????????//?目標(biāo)文件
for?(int?nodeCount?=?0;?nodeCount??nodeList-Getlength();?nodeCount++)
{
MSXML2::IXMLDOMNodePtr?nodePtr?=?nodeList-nextNode();
_variant_t?strCaseNodeName?=?nodePtr-GetnodeName();
_variant_t?strCaseNodeValue?=?nodePtr-Gettext();
BSTR?bStrTemp?=?strCaseNodeName.bstrVal;
CString?strTemp?=?CString(bStrTemp);
SysFreeString(bStrTemp);
CString?strNodeName?=?strTemp;
//??節(jié)點(diǎn)的值,如何取得?
if?(0?==?strNodeName.CompareNoCase(_T("NO")))
{
strNo?=?(BSTR)strCaseNodeValue.pbstrVal;
//?取得的值可以打印出來
printf(strNo);
}
//?節(jié)點(diǎn)有屬性值,該怎么處理?
else?if?(0?==?strNodeName.CompareNoCase(_T("CopyFile")))
{
strSrcFile.Empty();
strDestFile.Empty();
//?取得節(jié)點(diǎn)的屬性值
MSXML2::IXMLDOMNamedNodeMapPtr?pDOMAttrList=?nodePtr-Getattributes();
for?(int?j?=?0;?j??pDOMAttrList-Getlength();?j++)
{
MSXML2::IXMLDOMNodePtr?pDOMAttr=?pDOMAttrList-Getitem(j);?
//?取得源文件路徑
if?(CompareNoCase((char*)pDOMAttr-GetnodeName(),?_T("src")))
{
strSrcFile?=?pDOMAttr-GetnodeTypedValue();
//?取得目標(biāo)文件路徑
}?else?if?(CompareNoCase((char*)pDOMAttr-GetnodeName(),?_T("dest")))
{
strDestFile?=pDOMAttr-GetnodeTypedValue();
}
CopyFile(strSrcFile,?strDestFile,?FALSE);
}
else?if?(0?==?strNodeName.CompareNoCase(_T("DelFile")))
{
strDestFile.Empty();
strDestFile?=?CString((BSTR)strCaseNodeValue.pbstrVal);
DeleteFile(strDestFile);
}?
}
}
//?為了能夠讓MFC認(rèn)識(shí)MSXML2,我們需要引入相應(yīng)的dll,代碼如下;
#import?"msxml4.dll"
#includestdio.h
void main()
{
FILE *fp;
int i;
fp=fopen("ffff.doc","w");
for(i=0;i100;i++)
fprintf(fp,"%d\n",i);
close(fp);
}