之前一直用MSXML解析器,但需要提前安装,不利于集成到项目中。。。
创建一个XML文档,并添加一个根结点:
m_xml.SetDoc( "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" ); m_xml.AddElem( "xx" ); m_xml.IntoElem(); m_xml.OutOfElem(); m_xml.Save(".\\WebServer\\Service.xml");
加载一个XML,查找出指定结点,并删除:
m_xml.Load(".\\WebServer\\Service.xml"); m_xml.FindChildElem(Cam); m_xml.RemoveChildElem(); m_xml.Save(".\\WebServer\\Service.xml");
添加结点:
m_xml.Load(".\\WebServer\\Service.xml"); m_xml.FindChildElem("xx"); m_xml.IntoElem(); m_xml.AddElem("CAM1",""); m_xml.AddAttrib("Name",m_Channel[0]); m_xml.IntoElem(); m_xml.AddElem("url",addr); m_xml.AddElem("name",m_Channel[0]); m_xml.OutOfElem(); m_xml.OutOfElem(); m_xml.Save(".\\WebServer\\Service.xml");