在这里我要说明一下,在解析XML文件的时候,我借用了CMarkup类,十分感谢它的作者,因为他们的努力使得我们在解析XML文件的时候可以轻而已举,这里再一次感谢他们!也推荐大家在解析XML文件的时候不妨试试这个类,非常的好用!
上面的代码还比较好懂,我也就不多解释什么了(高手们可别笑话我哦~~)
在接受到服务器端的SOAP消息后,客户端就可以解析SOAP消息并把结果显示出来了:
CFile file;
file.Open(/"Temp.xml/",CFile::modeCreate | CFile::typeBinary | CFile::modeWrite );
file.WriteHuge(recvBuf,strlen(recvBuf));
file.Flush();
file.Close();
CMarkup xml;
if(!xml.Load(/"Temp.xml/"))
{
MessageBox(/"加载XML文件失败!/");
return ;
}
...
int item=0;
xml.ResetMainPos(); //make sure to move the point to the begin
while (xml.FindChildElem(/"BOOK/"))
{
int subItem=0;
xml.IntoElem(); //into BOOK
m_listCtrl.InsertItem(item,/"/",0); //插入一行
CString index;
index.Format(/"%d/",item+1); //每行的序号
m_listCtrl.SetItemText(item,subItem,index);
while(xml.FindChildElem()) //循环得到节点值,也就是书的各个信息
{
xml.IntoElem();
CString value=xml.GetData(); //得到值
//MessageBox(value);
m_listCtrl.SetItemText(item,subItem+1,value);
subItem++;
xml.OutOfElem();
}
item++;
xml.OutOfElem(); //out BOOK
}
这就是格式化SOAP消息和解析SOAP消息主要的部分