Class xml_document
Synopsis
#include <src/pugixml.hpp>
class PUGIXML_CLASS xml_document: public xml_node
Description
Document class (DOM tree root)
Mentioned in
- Getting Started / Example
- Quickstart / Document object model
- Quickstart / Loading document
- Manual / 3.2. C++ interface
- Manual / 4.1. Loading document from file
- Manual / 4.2. Loading document from memory
- Manual / 4.3. Loading document from C++ IOstreams
- Manual / 4.4. Handling parsing errors
- Manual / 6.5. Cloning nodes/attributes
- Manual / 6.7. Assembling document from fragments
- Manual / 7.1. Saving document to a file
- Manual / 7.2. Saving document to C++ IOstreams
- Manual / 7.3. Saving document via writer interface
- Manual / 7.4. Saving a single subtree
- Manual / 7.5. Output options
- Manual / 7.7. Customizing document declaration
- Manual / v1.9 2018-04-04
- Manual / v1.0 2010-11-01
- Manual / v0.3 2007-02-21
- Manual / 10.5. Classes
- Samples / custom_memory_management
- Samples / include
- Samples / load_error_handling
- Samples / load_file
- Samples / load_memory
- Samples / load_options
- Samples / load_stream
- Samples / modify_add
- Samples / modify_base
- Samples / modify_remove
- Samples / save_custom_writer
- Samples / save_declaration
- Samples / save_file
- Samples / save_options
- Samples / save_stream
- Samples / save_subtree
- Samples / text
- Samples / traverse_base
- Samples / traverse_iter
- Samples / traverse_predicate
- Samples / traverse_rangefor
- Samples / traverse_walker
- Samples / xpath_error
- Samples / xpath_query
- Samples / xpath_select
- Samples / xpath_variables
Inheritance
Ancestors: xml_node
Methods
xml_document overload | Default constructor, makes empty document. | |
xml_document overload | Move semantics support. | |
~xml_document | Destructor, invalidates all node/attribute handles to this document. | |
document_element | Get document element. | |
load overload | Load document from stream. | |
load overload | (deprecated: use load_string instead) Load document from zero-terminated string. No encoding conversions are applied. | |
load_buffer | Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns. | |
load_buffer_inplace | Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data) | |
load_buffer_inplace_own | Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data) | |
load_file overload | Load document from file. | |
load_string | Load document from zero-terminated string. No encoding conversions are applied. | |
operator= | ||
reset overload | Removes all nodes, leaving the empty document. | |
reset overload | Removes all nodes, then copies the entire contents of the specified document. | |
save overload | Save XML document to writer (semantics is slightly different from xml_node::print, see documentation for details). | |
save overload | Save XML document to stream (semantics is slightly different from xml_node::print, see documentation for details). | |
save_file overload | Save 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;
};