栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

tinyxml 库

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

tinyxml 库

C++读取xml配置文件 - tinyxml2tinyxml基本结构


xml文件示例
animals.xml
    
        Herby
        elephant
        1992-04-23
        
        
    
类结构

Tinyxml类结构

  • 1, TiXmlbase 为所有类型的基类, 提供基本的打印功能和部分工具函数;

  • 2, TiXmlNode 为所有节点的父类;

    • 2.1 TiXmlComment 对应 xml 中的注释, 即 ``;

    • 2.2 TiXmlDeclaration 对应 xml 中的文档属性, 即

    • 2.3 TiXmldocument 为容器类,指代 animals.xml 文档本身;

    • 2.4 TiXmlElement 为xml元素, 可以嵌套, 如 为 xml 元素,可以继续嵌套 ... 等元素;

    • 2.5 TiXmlText 指代 xml 元素的 val, 同 TiXmlAttribute 基本只在生成文档时使用.

    • 2.6 指代 xml 文档中不能正常解析的部分.

  • 3, TiXmlAttribute 对应 xml 中的属性,即 name 和 phone 属性,在生成 xml 文档时用到,读取时没有用到.

demo
#include "tinyxml.h"#include int main(){    using namespace std;    TiXmldocument docAnml("animals.xml");
    docAnml.LoadFile();
    TiXmlNode* dec = docAnml.FirstChild();    cout << "xml declaration: "<Value() << endl;    // 输出 xml declaration: , 没有 declaration 的内容
    dec = dec->NextSibling();    cout << "xml comment: "<Value() << endl;    //  xml declaration:  Feldman Family Circus Animals

    TiXmlElement* root = docAnml.RootElement();    cout << "root element is " << root->Value() << endl;    // root element is animalList
    TiXmlElement* animal = root->FirstChildElement(); // animal
    TiXmlElement* name   = animal->FirstChildElement(); // name
    cout << "name is : " << name->FirstChild()->Value() << endl;
    name = name->NextSiblingElement(); // species
    name = name->NextSiblingElement(); // date - of - birth
    TiXmlElement* Vet = name->NextSiblingElement(); // veterinarian
    cout << "attribute name : " << Vet->Attribute("name") << endl;    // ttribute name : Dr. Hal Brown}// g++ -o demo_tixml demo_tixml.cpp -I./inc -L./lib -ltinyxml -DTIXML_USE_STL



作者:呆呆的张先生
链接:https://www.jianshu.com/p/fd4228b9c444


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/232486.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号