xml的创建 c++哦

来源:互联网 发布:常州科教城淘宝装修 编辑:程序博客网 时间:2024/06/01 23:57

http://blog.sina.com.cn/s/blog_69e905cd0100ks5v.html

工作中遇到了空难,,,,,,遇到了一篇好文章,虽然有点小错误,但不妨碍优大于劣,,哈哈

TiXmlDocument *pDoc=new TiXmlDocument; //定义一个文档的指针//添加一个xml头。TiXmlDeclaration *pDeclaration=new TiXmlDeclaration("1.0","UTF-8","");pDoc->LinkEndChild(pDeclaration);//添加XMl的根节点TiXmlElement *lengquan= new TiXmlElement("lengquan");pDoc->LinkEndChild(lengquan);//添加xml父节点,其实父节点跟子节点一样,这里为了我自己明白的更清楚一点,所以我自己称根节点的下一结点为父节点。TiXmlElement *parent=new TiXmlElement("qiu");lengquan->LinkEndChild(parent);//添加属性parent->SetAttribute("time","12:10");//添加子节点。TiXmlElement *name4NewNode=new TiXmlElement("name");parent->LinkEndChild(name4NewNode);//添加节点下文本CString strName="pipi";TiXmlText *pNameValue=new TiXmlText(strName);name4NewNode->LinkEndChild(pNameValue);//TiXmlElement* addr4NewNode=new TiXmlElement("addr");parent->LinkEndChild(addr4NewNode);CString strAddr="Shaanxi Xianyang";TiXmlText *pAddrValue=new TiXmlText(strAddr);addr4NewNode->LinkEndChild(pAddrValue);//TiXmlElement* tel4NewNode=new TiXmlElement("tel");parent->LinkEndChild(tel4NewNode);CString strTel="02937310627";TiXmlText *pTelValue=new TiXmlText(strTel);tel4NewNode->LinkEndChild(pTelValue);//保存pDoc->SaveFile("lengquan1.xml"); 


0 0
原创粉丝点击