xml開發筆記(一):tinyXml2庫介紹、編譯和工程模板

若該文爲原創文章,轉載請註明原文出處
本文章博客地址:https://blog.csdn.net/qq21497936/article/details/111828450
長期持續帶來更多項目與技術分享,諮詢請加QQ:2149793六、微信:yangsir198808
紅胖子(紅模仿)的博文大全:開發技術集合(包含Qt實用技術、樹莓派、三維、OpenCV、OpenGL、ffmpeg、OSG、單片機、軟硬結合等等)持續更新中…(點擊傳送門)html

Qt開發專欄:三方庫開發技術


前言

  Qt開發Xml相關技術,使用到tinyxml2庫。git


TinyXML

  TinyXML是一個簡單的、小的C++的XML解析器,能夠集成到其餘程序中。它是ROS的標準XML解析器。
  最新的已是TinyXML2版本了。
  github下載地址:https://github.com/leethomason/tinyxml2
  CSDN下載地址:https://download.csdn.net/download/qq21497936/13944558
  QQ羣:1047134658(點擊「文件」搜索「tinyxml2」,羣內與博文同步更新)github


TinyXML編譯

步驟一:解壓

在這裏插入圖片描述

步驟二:Cmake配置

在這裏插入圖片描述
在這裏插入圖片描述
  直接強上,先修改C編譯器的
在這裏插入圖片描述
  而後修改CXX編譯器的
在這裏插入圖片描述
在這裏插入圖片描述微信

步驟三:生成工程

在這裏插入圖片描述

步驟四:命令行編譯

在這裏插入圖片描述

步驟五:安裝install

在這裏插入圖片描述


模塊化

在這裏插入圖片描述


Demo

void TinyXmlManager::testEnv()
{
    // 測試建立一個簡單html文件
    tinyxml2::XMLDocument doc;
    // 添加第一行
    doc.Parse("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    // 添加第一個節點
    // 添加第一個節點中的屬性 <ofd:OFD xmlns:ofd="http://www.ofdspec.org" DocType="OFD" Version="1.0">
    tinyxml2::XMLElement * pXmlElement;
    pXmlElement = doc.NewElement("ofd:OFD");
    pXmlElement->SetAttribute("xmlns:ofd", "http://www.ofdspec.org");
    pXmlElement->SetAttribute("DocType", "OFD");
    pXmlElement->SetAttribute("Version", "1.0");
    // 子節點 <ofd:DocBody>
    tinyxml2::XMLElement * pXmlElement2;
    pXmlElement2 = doc.NewElement("ofd:DocBody");
    pXmlElement2->SetAttribute("Author", "紅模仿");
    pXmlElement2->SetAttribute("QQ", 21497936);
    pXmlElement2->SetAttribute("Blog", "https://blog.csdn.net/qq21497936");
    pXmlElement->InsertEndChild(pXmlElement2);

    doc.InsertEndChild(pXmlElement);

    // 保存
    doc.SaveFile("1.xml");
}


測試結果

在這裏插入圖片描述


工程模板v1.0.0

  對應工程模板:tinyXmlDemo_v1.0.0_基礎工程_運行環境測試.rar模塊化


若該文爲原創文章,轉載請註明原文出處
本文章博客地址:https://blog.csdn.net/qq21497936/article/details/111828450測試

相關文章
相關標籤/搜索