libxml++
3.2.3
|
Represents an XML document in the DOM model. More...
#include <libxml++/document.h>
Public Member Functions | |
LIBXMLPP_API | Document (_xmlDoc* doc) |
Create a new C++ wrapper for an xmlDoc struct. More... | |
LIBXMLPP_API | Document (const Glib::ustring& version="1.0") |
Create a new document. More... | |
LIBXMLPP_API | ~Document () override |
LIBXMLPP_API CommentNode* | add_comment (const Glib::ustring& content) |
Append a new comment node. More... | |
LIBXMLPP_API ProcessingInstructionNode* | add_processing_instruction (const Glib::ustring& name, const Glib::ustring& content) |
Append a new processing instruction node. More... | |
LIBXMLPP_API const _xmlDoc* | cobj () const noexcept |
Access the underlying libxml implementation. More... | |
LIBXMLPP_API _xmlDoc* | cobj () noexcept |
Access the underlying libxml implementation. More... | |
LIBXMLPP_API Element* | create_root_node (const Glib::ustring& name, const Glib::ustring& ns_uri=Glib::ustring(), const Glib::ustring& ns_prefix=Glib::ustring()) |
Create the root element node. More... | |
LIBXMLPP_API Element* | create_root_node_by_import (const Node* node, bool recursive=true) |
Create a root element node by importing the node from another document, without affecting the source node. More... | |
LIBXMLPP_API Glib::ustring | get_encoding () const |
LIBXMLPP_API Dtd* | get_internal_subset () const |
Get the internal subset of this document. More... | |
LIBXMLPP_API Element* | get_root_node () |
Return the root node. More... | |
LIBXMLPP_API const Element* | get_root_node () const |
Return the root node. More... | |
LIBXMLPP_API int | process_xinclude (bool generate_xinclude_nodes, bool fixup_base_uris) |
Perform XInclude substitution on the XML document. More... | |
int | process_xinclude (bool generate_xinclude_nodes=true) |
Perform XInclude substitution on the XML document. More... | |
virtual LIBXMLPP_API void | set_entity_declaration (const Glib::ustring& name, XmlEntityType type, const Glib::ustring& publicId, const Glib::ustring& systemId, const Glib::ustring& content) |
Add an Entity declaration to the document. More... | |
LIBXMLPP_API void | set_internal_subset (const Glib::ustring& name, const Glib::ustring& external_id, const Glib::ustring& system_id) |
Create the internal subset of this document. More... | |
LIBXMLPP_API void | write_to_file (const std::string& filename, const Glib::ustring& encoding=Glib::ustring()) |
Write the document to a file. More... | |
LIBXMLPP_API void | write_to_file_formatted (const std::string& filename, const Glib::ustring& encoding=Glib::ustring()) |
Write the document to a file. More... | |
LIBXMLPP_API void | write_to_stream (std::ostream& output, const Glib::ustring& encoding=Glib::ustring()) |
Write the document to a std::ostream. More... | |
LIBXMLPP_API void | write_to_stream_formatted (std::ostream& output, const Glib::ustring& encoding=Glib::ustring()) |
Write the document to a std::ostream. More... | |
LIBXMLPP_API Glib::ustring | write_to_string (const Glib::ustring& encoding=Glib::ustring()) |
Write the document to the memory. More... | |
LIBXMLPP_API Glib::ustring | write_to_string_formatted (const Glib::ustring& encoding=Glib::ustring()) |
Write the document to the memory. More... | |
Protected Member Functions | |
LIBXMLPP_API _xmlEntity* | get_entity (const Glib::ustring& name) |
Retrieve an Entity. More... | |
![]() | |
NonCopyable () noexcept | |
NonCopyable (const NonCopyable&)=delete | |
NonCopyable (NonCopyable&&)=delete | |
virtual | ~NonCopyable () |
NonCopyable& | operator= (const NonCopyable&)=delete |
NonCopyable& | operator= (NonCopyable&&)=delete |
Represents an XML document in the DOM model.
|
explicit |
Create a new document.
version | XML version. |
xmlpp::internal_error | If memory allocation fails. |
|
explicit |
Create a new C++ wrapper for an xmlDoc struct.
The created xmlpp::Document takes ownership of the xmlDoc. When the Document is deleted, so is the xmlDoc and all its nodes.
doc | A pointer to an xmlDoc struct. Must not be nullptr . |
xmlpp::internal_error | If doc is nullptr . |
|
override |
LIBXMLPP_API CommentNode* xmlpp::Document::add_comment | ( | const Glib::ustring & | content | ) |
Append a new comment node.
content | The text. This should be unescaped - see ContentNode::set_content(). |
xmlpp::internal_error |
LIBXMLPP_API ProcessingInstructionNode* xmlpp::Document::add_processing_instruction | ( | const Glib::ustring & | name, |
const Glib::ustring & | content | ||
) |
Append a new processing instruction node.
name | The name of the application to which the instruction is directed. |
content | The content of the instruction. This should be unescaped - see ContentNode::set_content(). |
xmlpp::internal_error |
|
noexcept |
Access the underlying libxml implementation.
|
noexcept |
Access the underlying libxml implementation.
LIBXMLPP_API Element* xmlpp::Document::create_root_node | ( | const Glib::ustring & | name, |
const Glib::ustring & | ns_uri = Glib::ustring() , |
||
const Glib::ustring & | ns_prefix = Glib::ustring() |
||
) |
Create the root element node.
If the document already contains a root element node, it is replaced, and the old root element node and all its descendants are deleted.
name | The node's name. |
ns_uri | The namespace URI. A namespace declaration will be added to this node, because it could not have been declared before. |
ns_prefix | The namespace prefix to associate with the namespace. If no namespace prefix is specified then the namespace URI will be the default namespace. |
xmlpp::internal_error | If memory allocation fails. |
xmlpp::exception | If a new namespace node cannot be created. |
LIBXMLPP_API Element* xmlpp::Document::create_root_node_by_import | ( | const Node* | node, |
bool | recursive = true |
||
) |
Create a root element node by importing the node from another document, without affecting the source node.
If the document already contains a root element node, it is replaced, and the old root element node and all its descendants are deleted.
node | The node to copy and insert as the root node of the document. It must be an element node. |
recursive | Whether to import the child nodes also. Defaults to true. |
xmlpp::exception | If the node can't be copied. |
LIBXMLPP_API Glib::ustring xmlpp::Document::get_encoding | ( | ) | const |
|
protected |
Retrieve an Entity.
The entity can be from an external subset or internally declared.
name | The name of the entity to get. |
nullptr
if not found. LIBXMLPP_API Dtd* xmlpp::Document::get_internal_subset | ( | ) | const |
Get the internal subset of this document.
nullptr
if not found. LIBXMLPP_API Element* xmlpp::Document::get_root_node | ( | ) |
Return the root node.
This function does not create a default root node if it doesn't exist.
nullptr
otherwise. LIBXMLPP_API const Element* xmlpp::Document::get_root_node | ( | ) | const |
Return the root node.
This function does not create a default root node if it doesn't exist.
nullptr
otherwise. LIBXMLPP_API int xmlpp::Document::process_xinclude | ( | bool | generate_xinclude_nodes, |
bool | fixup_base_uris | ||
) |
Perform XInclude substitution on the XML document.
XInclude substitution may both add and delete nodes in the document, as well as change the type of some nodes. All pointers to deleted nodes and nodes whose type is changed become invalid. (The node type represented by an underlying xmlNode struct can change. The type of a C++ wrapper can't change. The old wrapper is deleted, and a new one is created if and when it's required.)
Parser::set_parser_options() and DomParser::set_xinclude_options() do not affect Document::process_xinclude().
generate_xinclude_nodes | Generate XIncludeStart and XIncludeEnd nodes. |
fixup_base_uris | Add or replace xml:base attributes in included element nodes, if necessary to preserve the target of relative URIs. |
xmlpp::exception |
int xmlpp::Document::process_xinclude | ( | bool | generate_xinclude_nodes = true | ) |
Perform XInclude substitution on the XML document.
XInclude substitution may both add and delete nodes in the document, as well as change the type of some nodes. All pointers to deleted nodes and nodes whose type is changed become invalid. (The node type represented by an underlying xmlNode struct can change. The type of a C++ wrapper can't change. The old wrapper is deleted, and a new one is created if and when it's required.)
Parser::set_parser_options() and DomParser::set_xinclude_options() do not affect Document::process_xinclude().
generate_xinclude_nodes | Generate XIncludeStart and XIncludeEnd nodes. |
xmlpp::exception |
|
virtual |
Add an Entity declaration to the document.
name | The name of the entity that will be used in an entity reference. |
type | The type of entity. |
publicId | The public ID of the subset. |
systemId | The system ID of the subset. |
content | The value of the Entity. In entity reference substitutions, this is the replacement value. |
xmlpp::internal_error |
LIBXMLPP_API void xmlpp::Document::set_internal_subset | ( | const Glib::ustring & | name, |
const Glib::ustring & | external_id, | ||
const Glib::ustring & | system_id | ||
) |
Create the internal subset of this document.
If the document already has an internal subset, a new one is not created.
name | The DTD name. |
external_id | The external (PUBLIC) ID, or an empty string. |
system_id | The system ID, or an empty string. |
LIBXMLPP_API void xmlpp::Document::write_to_file | ( | const std::string & | filename, |
const Glib::ustring & | encoding = Glib::ustring() |
||
) |
Write the document to a file.
filename | |
encoding | If not provided, UTF-8 is used |
xmlpp::exception |
LIBXMLPP_API void xmlpp::Document::write_to_file_formatted | ( | const std::string & | filename, |
const Glib::ustring & | encoding = Glib::ustring() |
||
) |
Write the document to a file.
The output is formatted by inserting whitespaces, which is easier to read for a human, but may insert unwanted significant whitespaces. Use with care !
filename | |
encoding | If not provided, UTF-8 is used |
xmlpp::exception |
LIBXMLPP_API void xmlpp::Document::write_to_stream | ( | std::ostream & | output, |
const Glib::ustring & | encoding = Glib::ustring() |
||
) |
Write the document to a std::ostream.
output | A reference to the stream in which the document will be written |
encoding | If not provided, UTF-8 is used |
xmlpp::exception | |
xmlpp::internal_error |
LIBXMLPP_API void xmlpp::Document::write_to_stream_formatted | ( | std::ostream & | output, |
const Glib::ustring & | encoding = Glib::ustring() |
||
) |
Write the document to a std::ostream.
The output is formatted by inserting whitespaces, which is easier to read for a human, but may insert unwanted significant whitespaces. Use with care !
output | A reference to the stream in which the document will be written |
encoding | If not provided, UTF-8 is used |
xmlpp::exception | |
xmlpp::internal_error |
LIBXMLPP_API Glib::ustring xmlpp::Document::write_to_string | ( | const Glib::ustring & | encoding = Glib::ustring() | ) |
Write the document to the memory.
encoding | If not provided, UTF-8 is used |
xmlpp::exception |
LIBXMLPP_API Glib::ustring xmlpp::Document::write_to_string_formatted | ( | const Glib::ustring & | encoding = Glib::ustring() | ) |
Write the document to the memory.
The output is formatted by inserting whitespaces, which is easier to read for a human, but may insert unwanted significant whitespaces. Use with care !
encoding | If not provided, UTF-8 is used |
xmlpp::exception |