欢迎访问三明灵光网络科技服务公司

三明灵光网络科技服务公司

---专业计算机软件领域开发

pugixml 笔记


另外,node.text().set()方法也不错,提供了常用的数据类型写入XML的重载方法:
复制代码

        // Set text (returns false if object is empty or there is not enough memory)
        bool set(const char_t* rhs);

        // Set text with type conversion (numbers are converted to strings, boolean is converted to "true"/"false")
        bool set(int rhs);
        bool set(unsigned int rhs);
        bool set(double rhs);
        bool set(bool rhs);

    #ifdef PUGIXML_HAS_LONG_LONG
        bool set(long long rhs);
        bool set(unsigned long long rhs);
    #endif

复制代码

而node.text().as_xxx()方法可以按需要直接从XML文件中读取出指定类型的数据:
复制代码

        // Get text, or "" if object is empty
        const char_t* get() const;

        // Get text, or the default value if object is empty
        const char_t* as_string(const char_t* def = PUGIXML_TEXT("")) const;

        // Get text as a number, or the default value if conversion did not succeed or object is empty
        int as_int(int def = 0) const;
        unsigned int as_uint(unsigned int def = 0) const;
        double as_double(double def = 0) const;
        float as_float(float def = 0) const;

    #ifdef PUGIXML_HAS_LONG_LONG
        long long as_llong(long long def = 0) const;
        unsigned long long as_ullong(unsigned long long def = 0) const;
    #endif

复制代码