CXml封装库是我从2005年写的一个东东,一直都有更新.
范例代码和源代码在此地址可以下载到,我就不多说什么了
http://www.codeproject.com/KB/COM/CXml.aspx此库又 CXml CXmlNode CXmlNodes CXsl 3个类组成, 只要客户机上安装有MSXML就可以,而不必担心MSXML的版本差异
下面贴一些Sample代码
1
CXml xml;
2
if( xml.Open(strFilePath) )
3
{
4
CXmlNode node = xml.GetRoot()->GetChild(_T("a"))
5
->GetChild(_T("b"))
6
->GetChild(_T("c"))
7
->GetChild(_T("e"))
8
->GetChild(_T("f"));
9
}
CXml xml;
if( xml.Open(strFilePath) )

{
xml.GetRoot()->GetChild(_T("a"))->NewChild(_T("b"))->SetValue(_T("I am new"));
}
CXml xml;
if( xml.Open(strFilePath) )

{
strMsg.Format( _T("int=%d\n")
_T("long=%ld\n")
_T("float=%f\n")
_T("double=%e\n")
_T("DWORD=%u\n")
_T("bool=%s\n")
_T("int64=%I64d\n")
_T("string=%s\n")
, xml.GetRoot()->GetChild(_T("int"))->GetValue(0)
, xml.GetRoot()->GetChild(_T("long"))->GetValue(0L)
, xml.GetRoot()->GetChild(_T("float"))->GetValue(0.00f)
, xml.GetRoot()->GetChild(_T("double"))->GetValue(0e+0)
, xml.GetRoot()->GetChild(_T("DWORD"))->GetValue((DWORD)0)
, xml.GetRoot()->GetChild(_T("bool"))->GetValue(false) ? _T("true") : _T("false")
, xml.GetRoot()->GetChild(_T("int64"))->GetValue(0LL)
, xml.GetRoot()->GetChild(_T("string"))->GetValue()
);
AfxMessageBox(strMsg);
}
CXml xml;
if( xml.Open(strFilePath) )

{
xml.GetRoot()->GetChild(_T("b"))->AttachChild(
xml.GetRoot()->GetChild(_T("a"))->GetChild(_T("c"))->Detach()
);
}
if( xml.Open(strFilePath) )

{
xml.GetRoot()->SetAttribute(_T("int"),1);
xml.GetRoot()->SetAttribute(_T("long"),2321321LL);
xml.GetRoot()->SetAttribute(_T("float"),5.02f);
xml.GetRoot()->SetAttribute(_T("double"),2.58529e+1);
xml.GetRoot()->SetAttribute(_T("DWORD"),(DWORD)1834557);
xml.GetRoot()->SetAttribute(_T("bool"),true);
xml.GetRoot()->SetAttribute(_T("int64"),100000000000000LL);
xml.GetRoot()->SetAttribute(_T("string"),_T("hello"));
}
const CString NS_PREFIX = _T("ns");
const CString NS_URL = _T("http://www.some_domain.com");

CXml xml;
BOOL bRet = xml.Create( _T("xmlRoot")
, _T("UTF-8")
, NS_PREFIX
, NS_URL
);
if( bRet )

{
CXmlNode node = xml.CreateNode( _T("a"), NS_PREFIX, NS_URL);
xml.GetRoot()->AttachChild(node);

xml.Save(strFilePath);
}更多示例代码在前文给出的链接中