xml文件格式如下:
<?xml version="1.0" encoding="utf-8" ?>
<test>
<year aa="11">2009</year>
<junk1>1</junk1>
<junk2>22</junk2>
</test>
读取xml的代码如下所示:
void ReadXMLData()
{
CkXmlW xml;
if (!xml.LoadXmlFile(L"test.xml"))
{
return;
}
CkXmlW *pxml = xml.GetRoot(); //test
CkXmlW *pxmlnode = xml.FirstChild();
while (pxmlnode != nullptr)
{
const wchar_t * strTag = pxmlnode->tag();
const wchar_t * strText = pxmlnode->content();
int nNumAttributes = pxmlnode->get_NumAttributes();
int i = 0;
while (i < nNumAttributes) {
const wchar_t * strAttributeName = pxmlnode->getAttributeName(i);
const wchar_t * strAttributeValueEx = pxmlnode->getAttrValue(L"aa");
const wchar_t * strAttributeValue = pxmlnode->getAttributeValue(i);
i = i + 1;
}
pxmlnode = pxmlnode->NextSibling();
}
}