<tab>这个节点不是固定的以下是XML文件样本<tab name="新浪" type="browser" show="1" refreshmode="" owner="0" state="15" cx="0" cy="0">
<icon1>tabDefault-1.png</icon1>
<icon2>tabDefault-2.png</icon2>
<hint>新浪</hint>
<url>www.126.com</url>
</tab>
以下是XML文件样本
<?xml version="1.0" encoding="UTF-8"?>
<user_channel>
<tab name="0b96fcdde38326cf475abe3c2337832f" type="browser" show="1" refreshmode="" owner="1" state="8" cx="24" cy="24">
<icon1>0b96fcdde38326cf475abe3c2337832f-0.bmp</icon1>
<icon2>0b96fcdde38326cf475abe3c2337832f-0.bmp</icon2>
<hint>OA系统</hint>
<url>http://220.113.41.201:8080/ioas/dddl.asp?account=$Account&gid=$Gid</url>
</tab>
<tab name="新浪" type="browser" show="1" refreshmode="" owner="0" state="15" cx="0" cy="0">
<icon1>tabDefault-1.png</icon1>
<icon2>tabDefault-2.png</icon2>
<hint>新浪</hint>
<url>www.126.com</url>
</tab>
<tab name="新浪2" type="browser" show="1" refreshmode="" owner="0" state="15" cx="0" cy="0">
<icon1>tabDefault-1.png</icon1>
<icon2>tabDefault-2.png</icon2>
<hint>新浪</hint>
<url>www.126.com</url>
</tab>
<tab name="57ac3f675257949a7f35a711207ee80c" type="dll" show="1" refreshmode="onactive" owner="1" state="8" cx="24" cy="24">
<icon1>57ac3f675257949a7f35a711207ee80c-0.png</icon1>
<icon2>57ac3f675257949a7f35a711207ee80c-0.png</icon2>
<hint>协作区</hint><url>TribeApp.dll</url>
</tab>
<tab name="126邮箱" type="browser" show="1" refreshmode="" owner="2" state="15" cx="0" cy="0">
<icon1>tabDefault-1.png</icon1>
<icon2>tabDefault-2.png</icon2>
<hint>126邮箱</hint><url>http://www.163.com</url>
</tab>
</user_channel>
按文本文件读进来,一部分一部分的字符匹配,找到需要的内容。
你要搜索超级链接,就先匹配<url>,再往后匹配</url>,然后截取中间部分。
<url>http://www.163.com</url>
ParseHtml
找不到,我的代码要等方便时贴给你看。
例子也很好找http://www.perfectxml.com/msxmlCPP.asp
int XMLRead(string strFileName)
{
string filename = strFileName;
iXmlUeserChannel = 0;
iXmlIndex = 0;
TiXmlDocument* doc = new TiXmlDocument(filename.c_str());
if(!doc->LoadFile())
{
return 1;
}
const TiXmlElement* root = doc->RootElement();
//循环获取该根节点下面的节点
for(const TiXmlNode* childNum = root->FirstChild();childNum;childNum=childNum->NextSibling())
{
iXmlUeserChannel++;
}
//设置
pXmlUserChannel = new UserChannel[iXmlUeserChannel];
int i=0;
for(const TiXmlNode* child = root->FirstChild();child;child=child->NextSibling())
{
//判断为元素类型并且是tab元素,Value()获取该标签的名称
if((child->Type() == TiXmlNode::ELEMENT) && (!strcmp(child->Value(),"tab")))
{
const TiXmlElement *box = (const TiXmlElement*)child; pXmlUserChannel[i].name = box->Attribute("name");
pXmlUserChannel[i].type = box->Attribute("type");
pXmlUserChannel[i].show = box->Attribute("show");
pXmlUserChannel[i].refreshmode = box->Attribute("refreshmode");
pXmlUserChannel[i].owner = box->Attribute("owner");
pXmlUserChannel[i].state = box->Attribute("state");
pXmlUserChannel[i].cx = box->Attribute("cx");
pXmlUserChannel[i].cy = box->Attribute("cy");
//继续循环获取子节点相关数据
for(const TiXmlNode *sub_tag = box->FirstChild();sub_tag; sub_tag = sub_tag->NextSibling() )
{
if(sub_tag->Type() == TiXmlNode::ELEMENT)
{
const TiXmlElement *sub_element = (const TiXmlElement*)sub_tag;
if(!strcmp(sub_tag->Value(),"icon1"))
{
pXmlUserChannel[i].icon1 = sub_tag->FirstChild()->Value();
}//if(!strcmp(sub_tag->Value(),"position"))
else if(!strcmp(sub_tag->Value(),"icon2"))
{
pXmlUserChannel[i].icon2 = sub_tag->FirstChild()->Value();
}
else if(!strcmp(sub_tag->Value(),"hint"))
{
pXmlUserChannel[i].hint = sub_tag->FirstChild()->Value();
}
else if(!strcmp(sub_tag->Value(),"url"))
{
pXmlUserChannel[i].url = sub_tag->FirstChild()->Value();
}// if(sub_tag->Type() == TiXmlNode::ELEMENT)
}//if(sub_tag->Type() == TiXmlNode::ELEMENT)
}//for(const TiXmlNode *sub_tag = box->FirstChild(); sub_tag; sub_tag = sub_tag->NextSibling() )
i++;
}
}
delete doc;
return 0;
}