libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
crn::xml::Document Class Reference

XML document. More...

#include <CRNXml.h>

+ Inheritance diagram for crn::xml::Document:

Public Member Functions

 Document (const StringUTF8 &encoding="UTF-8", const StringUTF8 &version="1.0", bool char_conversion_throws=true)
 Constructor. More...
 
 Document (const Path &fname, bool char_conversion_throws=true)
 Constructor from file. More...
 
 Document (const char *content, bool char_conversion_throws=true)
 Constructor from buffer. More...
 
 Document (const Document &)=delete
 
 Document (Document &&)
 
Documentoperator= (const Document &)=delete
 
Documentoperator= (Document &&)
 
virtual ~Document ()
 Destructor. More...
 
 operator bool () const noexcept
 Checks if the document is open. More...
 
bool operator! () const noexcept
 Checks if the document is not open. More...
 
void Save (const Path &fname)
 Saves to file. More...
 
void Save ()
 Saves to file. More...
 
const PathGetFilename () const noexcept
 Gets the filename if the document exists on the disk. More...
 
const StringUTF8GetEncoding () const noexcept
 Gets the character encoding of the file. More...
 
const StringUTF8GetVersion () const noexcept
 Gets the XML version of the file. More...
 
Element GetRoot ()
 Gets the first element. More...
 
Node GetFirstNode ()
 Gets the first child node. More...
 
Node GetLastNode ()
 Gets the last child node. More...
 
Node BeginNode ()
 Gets the first child node. More...
 
Node EndNode ()
 Gets a null node. More...
 
Element GetFirstElement (const StringUTF8 &name="")
 Gets the first child element. More...
 
Element GetLastElement (const StringUTF8 &name="")
 Gets the last child element. More...
 
Element BeginElement ()
 Gets the first child element. More...
 
Element EndElement ()
 Gets a null node. More...
 
Element PushBackElement (const StringUTF8 &name)
 Adds an element at the end of the children list. More...
 
Element InsertElement (Node &n, const StringUTF8 &name)
 Inserts an element after a node. More...
 
Comment PushBackComment (const StringUTF8 &text)
 Adds a comment at the end of the children list. More...
 
Comment InsertComment (Node &n, const StringUTF8 &text)
 Inserts a comment after a node. More...
 
Node PushBackClone (Node &n, bool recursive=false)
 Adds a copy of a node at the end of the children list. More...
 
StringUTF8 AsString ()
 Exports the document to a string. More...
 

Detailed Description

XML document.

An XML document

Version
1.0
Author
Yann LEYDIER
Date
August 2012

Definition at line 429 of file CRNXml.h.

Constructor & Destructor Documentation

crn::xml::Document::Document ( const StringUTF8 encoding = "UTF-8",
const StringUTF8 version = "1.0",
bool  char_conversion_throws = true 
)

Constructor.

crn::xml::Document::Document ( const Path fname,
bool  char_conversion_throws = true 
)

Constructor from file.

crn::xml::Document::Document ( const char *  content,
bool  char_conversion_throws = true 
)

Constructor from buffer.

crn::xml::Document::Document ( const Document )
delete
crn::xml::Document::Document ( Document &&  )
virtual crn::xml::Document::~Document ( )
virtual

Destructor.

Member Function Documentation

StringUTF8 Document::AsString ( )

Exports the document to a string.

Exports the document to a string

Returns
a string containing the document

Definition at line 1218 of file CRNXml.cpp.

Element crn::xml::Document::BeginElement ( )
inline

Gets the first child element.

Definition at line 479 of file CRNXml.h.

Node crn::xml::Document::BeginNode ( )
inline

Gets the first child node.

Definition at line 470 of file CRNXml.h.

Element crn::xml::Document::EndElement ( )
inline

Gets a null node.

Definition at line 481 of file CRNXml.h.

Node crn::xml::Document::EndNode ( )
inline

Gets a null node.

Definition at line 472 of file CRNXml.h.

const StringUTF8& crn::xml::Document::GetEncoding ( ) const
inlinenoexcept

Gets the character encoding of the file.

Definition at line 458 of file CRNXml.h.

const Path& crn::xml::Document::GetFilename ( ) const
inlinenoexcept

Gets the filename if the document exists on the disk.

Definition at line 455 of file CRNXml.h.

Element Document::GetFirstElement ( const StringUTF8 name = "")

Gets the first child element.

Gets the first element

Exceptions
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]namethe name of the element or empty string for any element
Returns
the first element or null element

Definition at line 1064 of file CRNXml.cpp.

Node Document::GetFirstNode ( )

Gets the first child node.

Gets the first node

Returns
the first node or null node

Definition at line 1045 of file CRNXml.cpp.

Element Document::GetLastElement ( const StringUTF8 name = "")

Gets the last child element.

Gets the last element

Exceptions
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]namethe name of the element or empty string for any element
Returns
the last element or null element

Definition at line 1075 of file CRNXml.cpp.

Node Document::GetLastNode ( )

Gets the last child node.

Gets the last node

Returns
the last child node or null node

Definition at line 1053 of file CRNXml.cpp.

Element Document::GetRoot ( )

Gets the first element.

Gets the first element

Exceptions
ExceptionNotFoundno element in the xml
Returns
a handle on the first element in the document

Definition at line 1034 of file CRNXml.cpp.

const StringUTF8& crn::xml::Document::GetVersion ( ) const
inlinenoexcept

Gets the XML version of the file.

Definition at line 460 of file CRNXml.h.

Comment Document::InsertComment ( Node n,
const StringUTF8 text 
)

Inserts a comment after a node.

Inserts a comment after a node

Exceptions
ExceptionNotFoundnode not found
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]nthe node after which the new comment will be inserted
[in]textthe content of the comment
Returns
a handle on the newly created comment

Definition at line 1141 of file CRNXml.cpp.

Element Document::InsertElement ( Node n,
const StringUTF8 name 
)

Inserts an element after a node.

Inserts an element after a node

Exceptions
ExceptionInvalidArgumentnull node or empty element name
ExceptionNotFoundnode not found
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]nthe node after which the new element will be inserted
[in]namethe name of the element
Returns
a handle on the newly created element

Definition at line 1105 of file CRNXml.cpp.

crn::xml::Document::operator bool ( ) const
inlinenoexcept

Checks if the document is open.

Definition at line 446 of file CRNXml.h.

bool crn::xml::Document::operator! ( ) const
inlinenoexcept

Checks if the document is not open.

Definition at line 448 of file CRNXml.h.

Document& crn::xml::Document::operator= ( const Document )
delete
Document& crn::xml::Document::operator= ( Document &&  )
Node Document::PushBackClone ( Node n,
bool  recursive = false 
)

Adds a copy of a node at the end of the children list.

Adds a copy of a node at the end of the children list

Exceptions
ExceptionInvalidArgumentnull or invalid node
Parameters
[in]nthe node to copy
[in]recursiveshall the subelements be copied too? (only if n is an Element)
Returns
a handle on the newly created node

Definition at line 1160 of file CRNXml.cpp.

Comment Document::PushBackComment ( const StringUTF8 text)

Adds a comment at the end of the children list.

Adds a comment at the end of the document

Exceptions
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]textthe content of the comment
Returns
a handle on the newly created comment

Definition at line 1126 of file CRNXml.cpp.

Element Document::PushBackElement ( const StringUTF8 name)

Adds an element at the end of the children list.

Adds an element at the end of the document

Exceptions
ExceptionInvalidArgumentempty element name
CharsetConverter::ExceptionInvalidCharacterinvalid character
CharsetConverter::ExceptionIncompleteCodeincomplete multibyte character
Parameters
[in]namethe name of the element
Returns
a handle on the newly created element

Definition at line 1087 of file CRNXml.cpp.

void Document::Save ( const Path fname)

Saves to file.

Saves the XML to a file

Exceptions
ExceptionNotFoundfile not found
ExceptionIOcannot open file
ExceptionRuntimeerror creating the file
Parameters
[in]fnamethe xml file name

Definition at line 1009 of file CRNXml.cpp.

void Document::Save ( )

Saves to file.

Saves the XML to a file

Exceptions
ExceptionUninitializedemtpy filename
ExceptionNotFoundfile not found
ExceptionIOcannot open file
ExceptionRuntimeerror creating the file

Definition at line 1022 of file CRNXml.cpp.


The documentation for this class was generated from the following files: