Class xml_document

Synopsis

#include <src/pugixml.hpp>

class PUGIXML_CLASS xml_document: public xml_node

Description

Document class (DOM tree root)

Mentioned in

Inheritance

Ancestors: xml_node

Methods

xml_document overloadDefault constructor, makes empty document.
xml_document overloadMove semantics support.
~xml_documentDestructor, invalidates all node/attribute handles to this document.
document_elementGet document element.
load overloadLoad document from stream.
load overload(deprecated: use load_string instead) Load document from zero-terminated string. No encoding conversions are applied.
load_bufferLoad document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.
load_buffer_inplaceLoad document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data)
load_buffer_inplace_ownLoad document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data)
load_file overloadLoad document from file.
load_stringLoad document from zero-terminated string. No encoding conversions are applied.
operator=
reset overloadRemoves all nodes, leaving the empty document.
reset overloadRemoves all nodes, then copies the entire contents of the specified document.
save overloadSave XML document to writer (semantics is slightly different from xml_node::print, see documentation for details).
save overloadSave XML document to stream (semantics is slightly different from xml_node::print, see documentation for details).
save_file overloadSave XML to file.

Source

Lines 1022-1098 in src/pugixml.hpp.

class PUGIXML_CLASS xml_document: public xml_node
{
private:
    char_t* _buffer;
    char _memory[192];
    // Non-copyable semantics
    xml_document(const xml_document&);
    xml_document& operator=(const xml_document&);
    void _create();
    void _destroy();
    void _move(xml_document& rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT;
public:
    // Default constructor, makes empty document
    xml_document();
    // Destructor, invalidates all node/attribute handles to this document
    ~xml_document();
#ifdef PUGIXML_HAS_MOVE
    // Move semantics support
    xml_document(xml_document&& rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT;
    xml_document& operator=(xml_document&& rhs) PUGIXML_NOEXCEPT_IF_NOT_COMPACT;
#endif
    // Removes all nodes, leaving the empty document
    void reset();
    // Removes all nodes, then copies the entire contents of the specified document
    void reset(const xml_document& proto);
#ifndef PUGIXML_NO_STL
    // Load document from stream.
    xml_parse_result load(std::basic_istream<char, std::char_traits<char> >& stream, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
    xml_parse_result load(std::basic_istream<wchar_t, std::char_traits<wchar_t> >& stream, unsigned int options = parse_default);
#endif
    // (deprecated: use load_string instead) Load document from zero-terminated string. No encoding conversions are applied.
    PUGIXML_DEPRECATED xml_parse_result load(const char_t* contents, unsigned int options = parse_default);
    // Load document from zero-terminated string. No encoding conversions are applied.
    xml_parse_result load_string(const char_t* contents, unsigned int options = parse_default);
    // Load document from file
    xml_parse_result load_file(const char* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
    xml_parse_result load_file(const wchar_t* path, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
    // Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.
    xml_parse_result load_buffer(const void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
    // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
    // You should ensure that buffer data will persist throughout the document's lifetime, and free the buffer memory manually once document is destroyed.
    xml_parse_result load_buffer_inplace(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
    // Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data).
    // You should allocate the buffer with pugixml allocation function; document will free the buffer when it is no longer needed (you can't use it anymore).
    xml_parse_result load_buffer_inplace_own(void* contents, size_t size, unsigned int options = parse_default, xml_encoding encoding = encoding_auto);
    // Save XML document to writer (semantics is slightly different from xml_node::print, see documentation for details).
    void save(xml_writer& writer, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
#ifndef PUGIXML_NO_STL
    // Save XML document to stream (semantics is slightly different from xml_node::print, see documentation for details).
    void save(std::basic_ostream<char, std::char_traits<char> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
    void save(std::basic_ostream<wchar_t, std::char_traits<wchar_t> >& stream, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default) const;
#endif
    // Save XML to file
    bool save_file(const char* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
    bool save_file(const wchar_t* path, const char_t* indent = PUGIXML_TEXT("\t"), unsigned int flags = format_default, xml_encoding encoding = encoding_auto) const;
    // Get document element
    xml_node document_element() const;
};





Add Discussion as Guest

Log in