Spinning Topp Logo BlackTopp Studios
inc
Public Member Functions | List of all members
Mezzanine::XML::Document Class Reference

The root node of any xml hierarchy is a Document. More...

#include <document.h>

+ Inheritance diagram for Mezzanine::XML::Document:
+ Collaboration diagram for Mezzanine::XML::Document:

Public Member Functions

 Document ()
 Creates an empty document with just a root Node.
 
virtual ~Document ()
 Tears down a document, and incidentally invalidates all Node and Attribute handles to this document.
 
Node DocumentElement () const
 Get document element. More...
 
ParseResult Load (std::basic_istream< char, std::char_traits< char > > &stream, unsigned int options=ParseDefault, Encoding DocumentEncoding=EncodingAuto)
 Load XML from a stream. More...
 
ParseResult Load (std::basic_istream< wchar_t, std::char_traits< wchar_t > > &stream, unsigned int options=ParseDefault)
 Load XML from a wide stream. More...
 
ParseResult Load (const Char8 *contents, unsigned int options=ParseDefault)
 Load XML from a C-style string. More...
 
ParseResult LoadBuffer (const void *contents, size_t size, unsigned int options=ParseDefault, Encoding DocumentEncoding=EncodingAuto)
 Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns. More...
 
ParseResult LoadBufferInplace (void *contents, size_t size, unsigned int options=ParseDefault, Encoding DocumentEncoding=EncodingAuto)
 Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data). More...
 
ParseResult LoadBufferInplaceOwn (void *contents, size_t size, unsigned int options=ParseDefault, Encoding DocumentEncoding=EncodingAuto)
 Load document from buffer, using the buffer for in-place parsing (the buffer is modified and used for storage of document data). More...
 
ParseResult LoadFile (const char *Path, unsigned int options=ParseDefault, Encoding DocumentEncoding=EncodingAuto)
 Load document from file. More...
 
ParseResult LoadFile (const wchar_t *Path, unsigned int options=ParseDefault, Encoding DocumentEncoding=EncodingAuto)
 Load document from file. More...
 
void Reset ()
 Removes all nodes, leaving the empty document.
 
void Reset (const Document &proto)
 Removes all nodes, then copies the entire contents of the specified document. More...
 
void Save (Writer &WriterInstance, const Char8 *indent="\t", unsigned int flags=FormatDefault, Encoding DocumentEncoding=EncodingAuto) const
 Save XML document to WriterInstance. More...
 
void Save (std::basic_ostream< char, std::char_traits< char > > &stream, const Char8 *indent="\t", unsigned int flags=FormatDefault, Encoding DocumentEncoding=EncodingAuto) const
 Save XML document to a stream of characters. More...
 
void Save (std::basic_ostream< wchar_t, std::char_traits< wchar_t > > &stream, const Char8 *indent="\t", unsigned int flags=FormatDefault) const
 Save XML document to a stream of wide characters. More...
 
bool SaveFile (const char *Path, const Char8 *indent="\t", unsigned int flags=FormatDefault, Encoding DocumentEncoding=EncodingAuto) const
 Save XML to file. More...
 
bool SaveFile (const wchar_t *Path, const Char8 *indent="\t", unsigned int flags=FormatDefault, Encoding DocumentEncoding=EncodingAuto) const
 Save XML to file. More...
 
- Public Member Functions inherited from Mezzanine::XML::Node
 Node ()
 Default constructor. Constructs an empty node.
 
 Node (NodeStruct *p)
 Constructs node from internal pointer. More...
 
 ~Node ()
 Virtual deconstructor.
 
Attribute AppendAttribute (const Char8 *Name)
 Creates an Attribute and puts it at the end of this Nodes attributes. More...
 
Attribute AppendAttribute (const String &Name)
 Creates an Attribute and puts it at the end of this Nodes attributes. More...
 
Node AppendChild (NodeType Type=NodeElement)
 Creates a Node and makes it a child of this one. More...
 
Node AppendChild (const Char8 *Name)
 Creates an element Node as a child of this Node, with the given name. More...
 
Node AppendChild (const String &Name)
 Creates an element Node as a child of this Node, with the given name. More...
 
Attribute AppendCopy (const Attribute &proto)
 Copies an Attribute and puts the copy at the end of this Nodes attributes. More...
 
Node AppendCopy (const Node &proto)
 Copies a Node and puts the copy at the end of the list of this Nodes Childrem. More...
 
ObjectRange< AttributeIteratorattributes () const
 A range of iterators for just the attributes of this node. More...
 
attribute_iterator attributes_begin () const
 Get an Attribute iterator that references the first Attribute on this Node. More...
 
attribute_iterator attributes_end () const
 Get an Attribute iterator that references the one past the last Attribute on this Node. More...
 
iterator begin () const
 Get a Child node iterator that references the first child Node. More...
 
bool Empty () const
 Is this storing anything at all? More...
 
iterator end () const
 Get a Child node iterator that references one past the last child Node. More...
 
template<typename Predicate >
Attribute FindAttribute (Predicate pred) const
 Search for an Attribute using a function to check each Attribute individually. More...
 
template<typename Predicate >
Node FindChild (Predicate pred) const
 Search for an child ( only direct children ) Node using a function to check each Node individually. More...
 
Node FindChildbyAttribute (const Char8 *Name, const Char8 *AttrName, const Char8 *AttrValue) const
 Find a Node by an Attribute it has. More...
 
Node FindChildbyAttribute (const Char8 *AttrName, const Char8 *AttrValue) const
 Find a Node by an Attribute it has. More...
 
template<typename Predicate >
Node FindNode (Predicate pred) const
 Search for any Node descended from this Node using a function to check each Node individually. More...
 
XPathNodeSet FindNodes (const Char8 *query, XPathVariableSet *variables=0) const
 Select a group of nodes by evaluating an XPath query. More...
 
XPathNodeSet FindNodes (const XPathQuery &query) const
 Select a group of nodes by evaluating an XPath query. More...
 
XPathNode FindSingleNode (const Char8 *query, XPathVariableSet *variables=0) const
 Select single node by evaluating an XPath query. Returns first node from the resulting node set. More...
 
XPathNode FindSingleNode (const XPathQuery &query) const
 Select single node by evaluating an XPath query. Returns first node from the resulting node set. More...
 
Node FirstElementByPath (const Char8 *Path, Char8 delimiter= '/') const
 Search for a node by Path consisting of node names and . or .. elements. More...
 
Attribute GetAttribute (const Char8 *Name) const
 Attempt to get an Attribute on this Node with a given name. More...
 
Node GetChild (const Char8 *Name) const
 Attempt to get a child Node with a given name. More...
 
Node GetChild (const String &Name) const
 Attempt to get a child Node with a given name. More...
 
ObjectRange< NodeIteratorGetChildren () const
 Get an iterator range for this node's children nodes. More...
 
ObjectRange< NamedNodeIteratorGetChildren (const Char8 *Name) const
 Get an iterator range for this a subset of this node's children nodes. More...
 
const Char8GetChildValue () const
 Retrieve the value of this(or a child's) Nodes PCDATA child Node. More...
 
const Char8GetChildValue (const Char8 *Name) const
 Get the PCDATA of a given child. The same a calling "GetChild(Name).ChildValue()". More...
 
Attribute GetFirstAttribute () const
 Get the First Attribute in this Node. More...
 
Node GetFirstChild () const
 Get the first child Node of this Node. More...
 
Attribute GetLastAttribute () const
 Get the Last Attribute in this Node. More...
 
Node GetLastChild () const
 Get the last child Node of this Node. More...
 
Node GetNextSibling () const
 Attempt to retrieve the next sibling of this Node. More...
 
Node GetNextSibling (const Char8 *Name) const
 Like GetNextSibling except that the return will be a null Node or have a matching name. More...
 
Node GetParent () const
 Attempt to retrieve the parent of this Node. More...
 
Node GetPreviousSibling () const
 Attempt to retrieve the prvious sibling of this Node. More...
 
Node GetPreviousSibling (const Char8 *Name) const
 Like GetPreviousSibling except that the return will be a null Node or have a matching name. More...
 
Node GetRoot () const
 Attempt to retrieve the root Node, or the most base Node containing this Node. More...
 
NodeText GetText () const
 Get text object for the current node. More...
 
size_t HashValue () const
 Get hash Value (unique for handles to the same object) More...
 
Attribute InsertAttributeAfter (const Char8 *Name, const Attribute &attr)
 Creates an Attribute and puts it into the list of this Nodes attributes. More...
 
Attribute InsertAttributeBefore (const Char8 *Name, const Attribute &attr)
 Creates an Attribute and puts it into the list of this Nodes attributes. More...
 
Node InsertChildAfter (NodeType Type, const Node &node)
 Creates a Node and makes it a child of this one, and puts at the middle of the Child Nodes. More...
 
Node InsertChildAfter (const Char8 *Name, const Node &node)
 Creates an element Node as a child of this Node, with the given name at the middle of the children. More...
 
Node InsertChildBefore (NodeType Type, const Node &node)
 Creates a Node and makes it a child of this one, and puts at the middle of the Child Nodes. More...
 
Node InsertChildBefore (const Char8 *Name, const Node &node)
 Creates an element Node as a child of this Node, with the given name at the middle of the children. More...
 
Attribute InsertCopyAfter (const Attribute &proto, const Attribute &attr)
 Copies an Attribute and puts the copy into the list of this Nodes attributes. More...
 
Node InsertCopyAfter (const Node &proto, const Node &node)
 Copies a Node and puts the copy in the middle the list of this Nodes Childrem. More...
 
Attribute InsertCopyBefore (const Attribute &proto, const Attribute &attr)
 Copies an Attribute and puts the copy into the list of this Nodes attributes. More...
 
Node InsertCopyBefore (const Node &proto, const Node &node)
 Copies a Node and puts the copy in the middle the list of this Nodes Childrem. More...
 
NodeStruct * InternalObject () const
 Get internal pointer. More...
 
const Char8Name () const
 ptrdiff_tGet the name of this Node. More...
 
ptrdiff_t OffSetDebug () const
 Get node Offset in parsed file/string (in char_t units) for debugging purposes. More...
 
 operator unspecified_bool_type () const
 Used to convert this to a boolean value in a safe way. More...
 
bool operator! () const
 Used to convert this node the opposite of it's normal boolean value. More...
 
bool operator!= (const Node &r) const
 Compares the internal values to check inequality. More...
 
bool operator< (const Node &r) const
 Compares the internal values to check for lessthanness. More...
 
bool operator<= (const Node &r) const
 Compares the internal values to check for inequality and lessthanness. More...
 
bool operator== (const Node &r) const
 Compares the internal values to check equality. More...
 
bool operator> (const Node &r) const
 Compares the internal values to check for greaterthanness. More...
 
bool operator>= (const Node &r) const
 Compares the internal values to check for inequality and greaterthanness. More...
 
String Path (Char8 delimiter= '/') const
 Get the absolute path to this Node. More...
 
Attribute PrependAttribute (const Char8 *Name)
 Creates an Attribute and puts it at the begining of this Nodes attributes. More...
 
Node PrependChild (NodeType Type=NodeElement)
 Creates a Node and makes it a child of this one, and puts at the beginning of the Child Nodes. More...
 
Node PrependChild (const Char8 *Name)
 Creates an element Node as a child of this Node, with the given name at the beginning of the children. More...
 
Node PrependChild (const String &Name)
 Creates an element Node as a child of this Node, with the given name at the beginning of the children. More...
 
Attribute PrependCopy (const Attribute &proto)
 Copies an Attribute and puts the copy at the beginning of this Nodes attributes. More...
 
Node PrependCopy (const Node &proto)
 Copies a Node and puts the copy at the start of the list of this Nodes Childrem. More...
 
void Print (Writer &WriterInstance, const Char8 *indent="\t", unsigned int flags=FormatDefault, Encoding DocumentEncoding=EncodingAuto, unsigned int Depth=0) const
 Output the XML document using a Writer. More...
 
void Print (std::basic_ostream< char, std::char_traits< char > > &os, const Char8 *indent="\t", unsigned int flags=FormatDefault, Encoding DocumentEncoding=EncodingAuto, unsigned int Depth=0) const
 Output the XML document using a Output Stream. More...
 
void Print (std::basic_ostream< wchar_t, std::char_traits< wchar_t > > &os, const Char8 *indent="\t", unsigned int flags=FormatDefault, unsigned int Depth=0) const
 Output the XML document using a Output Stream. More...
 
bool RemoveAttribute (const Attribute &a)
 Remove specified Attribute. More...
 
bool RemoveAttribute (const Char8 *Name)
 Remove Attribute as specified by name. More...
 
bool RemoveChild (const Node &n)
 Remove specified child element. More...
 
bool RemoveChild (const Char8 *Name)
 Remove child element as specified by name. More...
 
bool SetName (const Char8 *rhs)
 Set the name of . More...
 
bool SetName (const String &rhs)
 Set the name of this object. More...
 
bool SetValue (const Char8 *rhs)
 Set the value of this. More...
 
bool Traverse (TreeWalker &walker)
 Perform sophisticated (or whatever) algorithms on this and all descendant Nodes in the XML tree. More...
 
NodeType Type () const
 Identify what kind of Node this is. More...
 
const Char8Value () const
 Get the Value of this Node. More...
 

Additional Inherited Members

- Public Types inherited from Mezzanine::XML::Node
typedef AttributeIterator attribute_iterator
 An iterator for Attribute members on this Node.
 
typedef NodeIterator iterator
 An iterator for child Nodes that will be easier for members of the std namespace to work with.
 
- Protected Types inherited from Mezzanine::XML::Node
typedef void(* unspecified_bool_type) (Node ***)
 Used to prevent casting to numerical types acccidentally. More...
 
- Protected Attributes inherited from Mezzanine::XML::Node
NodeStruct * NodeData
 Stores pointers to the Node data and some metadata. More...
 

Detailed Description

The root node of any xml hierarchy is a Document.

This has all the same features as a Node and include a few features for saving, loading, streaming and to a limited degree managing the document declaration.

Definition at line 83 of file document.h.

Member Function Documentation

Node Mezzanine::XML::Document::DocumentElement ( ) const

Get document element.

Returns
An XML::Node that is the root element of the xml Document
ParseResult Mezzanine::XML::Document::Load ( std::basic_istream< char, std::char_traits< char > > &  stream,
unsigned int  options = ParseDefault,
Encoding  DocumentEncoding = EncodingAuto 
)

Load XML from a stream.

Parameters
streamAn std::istream which has xml text in it.
optionsA bitset of parse options that should be set using the Parse variables. This Defaults to ParseDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto
Returns
A ParseResult that stores the the outcome of attempting to load the document.
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.
ParseResult Mezzanine::XML::Document::Load ( std::basic_istream< wchar_t, std::char_traits< wchar_t > > &  stream,
unsigned int  options = ParseDefault 
)

Load XML from a wide stream.

Parameters
streamAn std::basic_istream which has xml wide character text in it.
optionsA bitset of parse options that should be set using the Parse variables. This Defaults to ParseDefault.
Returns
A ParseResult that stores the the outcome of attempting to load the document.
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.
ParseResult Mezzanine::XML::Document::Load ( const Char8 contents,
unsigned int  options = ParseDefault 
)

Load XML from a C-style string.

Parameters
contentsA pointer to the Null terminated array of Characters.
optionsA bitset of parse options that should be set using the Parse variables. This Defaults to ParseDefault.
Returns
A ParseResult that stores the the outcome of attempting to load the document.
Note
The only Load method available in the 'Safe' scripting languages.
ParseResult Mezzanine::XML::Document::LoadBuffer ( const void *  contents,
size_t  size,
unsigned int  options = ParseDefault,
Encoding  DocumentEncoding = EncodingAuto 
)

Load document from buffer. Copies/converts the buffer, so it may be deleted or changed after the function returns.

Parameters
contentsA pointer to buffer containing the xml document to be parsed, that will remain unchanged.
sizeThe size of the buffer.
optionsA bitset of parse options that should be set using the Parse variables. This Defaults to ParseDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto
Returns
A ParseResult that stores the the outcome of attempting to load the document.
Note
All buffer loading Methods of the XML::Document are made available to all scripting languages libraries.
ParseResult Mezzanine::XML::Document::LoadBufferInplace ( void *  contents,
size_t  size,
unsigned int  options = ParseDefault,
Encoding  DocumentEncoding = EncodingAuto 
)

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 documents lifetime, and free the buffer memory manually once document is destroyed.

Parameters
contentsA pointer to buffer containing the xml document to be parsed, that must remain for the lifecycle of the XML::Document.
sizeThe size of the buffer.
optionsA bitset of parse options that should be set using the Parse variables. This Defaults to ParseDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto
Returns
A ParseResult that stores the the outcome of attempting to load the document.
Note
All buffer loading Methods of the XML::Document are made available to all scripting languages libraries.
ParseResult Mezzanine::XML::Document::LoadBufferInplaceOwn ( void *  contents,
size_t  size,
unsigned int  options = ParseDefault,
Encoding  DocumentEncoding = EncodingAuto 
)

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; XML::Document will free the buffer when it is no longer needed (you can not use it anymore).

Parameters
contentsA pointer to buffer containing the xml document to be parsed.
sizeThe size of the buffer.
optionsA bitset of parse options that should be set using the Parse variables. This Defaults to ParseDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto.
Returns
A ParseResult that stores the the outcome of attempting to load the document.
Note
All buffer loading Methods of the XML::Document are made available to all scripting languages libraries.
ParseResult Mezzanine::XML::Document::LoadFile ( const char *  Path,
unsigned int  options = ParseDefault,
Encoding  DocumentEncoding = EncodingAuto 
)

Load document from file.

Parameters
PathAn c-style char array that contains the path and filename of the xml document to load.
optionsA bitset of parse options that should be set using the Parse variables. This Defaults to ParseDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto
Returns
A ParseResult that stores the the outcome of attempting to load the document.
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.
ParseResult Mezzanine::XML::Document::LoadFile ( const wchar_t *  Path,
unsigned int  options = ParseDefault,
Encoding  DocumentEncoding = EncodingAuto 
)

Load document from file.

Parameters
PathAn c-style wide char array that contains the path and filename of the xml document to load.
optionsA bitset of parse options that should be set using the Parse variables. This Defaults to ParseDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto
Returns
A ParseResult that stores the the outcome of attempting to load the document.
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.
void Mezzanine::XML::Document::Reset ( const Document proto)

Removes all nodes, then copies the entire contents of the specified document.

Parameters
protoThe Document to copy.
void Mezzanine::XML::Document::Save ( Writer WriterInstance,
const Char8 indent = "\t",
unsigned int  flags = FormatDefault,
Encoding  DocumentEncoding = EncodingAuto 
) const

Save XML document to WriterInstance.

Parameters
WriterInstanceThe Writer that will be used to output the xml text.
indentThe Character(s) used to represent a tab in the output, this defaults to one tab character.
flagsThe output format flags, this is a bitfield that defaults to XML::FormatDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto.
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.
void Mezzanine::XML::Document::Save ( std::basic_ostream< char, std::char_traits< char > > &  stream,
const Char8 indent = "\t",
unsigned int  flags = FormatDefault,
Encoding  DocumentEncoding = EncodingAuto 
) const

Save XML document to a stream of characters.

Parameters
streamThe output stream of wide characters to send the XML document to.
indentThe Character(s) used to represent a tab in the output, this defaults to one tab character.
flagsThe output format flags, this is a bitfield that defaults to XML::FormatDefault.
DocumentEncodingThe Type of encoding to use when saving the document.
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.
void Mezzanine::XML::Document::Save ( std::basic_ostream< wchar_t, std::char_traits< wchar_t > > &  stream,
const Char8 indent = "\t",
unsigned int  flags = FormatDefault 
) const

Save XML document to a stream of wide characters.

Parameters
streamThe output stream of wide characters to send the XML document to.
indentThe Character(s) used to represent a tab in the output, this defaults to one tab character.
flagsThe output format flags, this is a bitfield that defaults to XML::FormatDefault.
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.
bool Mezzanine::XML::Document::SaveFile ( const char *  Path,
const Char8 indent = "\t",
unsigned int  flags = FormatDefault,
Encoding  DocumentEncoding = EncodingAuto 
) const

Save XML to file.

Parameters
PathA c-style array of chars that contain the filename (and any path) of the file to be output.
indentThe Character(s) used to represent a tab in the output, this defaults to one tab character.
flagsThe output format flags, this is a bitfield that defaults to XML::FormatDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto.
Returns
False if the target file could not be opened for writing
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.
bool Mezzanine::XML::Document::SaveFile ( const wchar_t *  Path,
const Char8 indent = "\t",
unsigned int  flags = FormatDefault,
Encoding  DocumentEncoding = EncodingAuto 
) const

Save XML to file.

Parameters
PathA c-style array of wide chars that contain the filename (and any path) of the file to be output.
indentThe Character(s) used to represent a tab in the output, this defaults to one tab character.
flagsThe output format flags, this is a bitfield that defaults to XML::FormatDefault.
DocumentEncodingWhat kind of text is in the stream, this defaults to Encoding::EncodingAuto.
Returns
False if the target file could not be opened for writing
Note
Not available in the 'Safe' scripting languages because of the file access it could provide.

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