Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cXmlNode Class Referenceabstract

#include <cXmlDocument.h>

Inheritance diagram for GrayLib::cXmlNode:
Gray::cListNodeT< cXmlNode > GrayLib::cXml Gray::cNonCopyable Gray::cListNodeBase Gray::cHeapObject Gray::IHeapObject GrayLib::cXmlComment GrayLib::cXmlDeclaration GrayLib::cXmlDocument GrayLib::cXmlElement GrayLib::cXmlText GrayLib::cXmlUnknown

Public Member Functions

virtual ~cXmlNode ()
 
XMLNODE_TYPE get_Type () const
 
bool isType (XMLNODE_TYPE eType) const
 
void put_UserData (void *pUserData)
 
void * get_UserData () const
 
virtual void SetClear ()
 Delete all the children of this node. Does not affect 'this'. More...
 
void put_Value (cXmlString sValue)
 
const cXmlStringget_Value () const
 
HRESULT QueryValueInt (int *piValue) const
 
HRESULT QueryValueDouble (double *pdValue) const
 QueryValueDouble examines the value string. See QueryValueInt(). More...
 
int get_ValueInt () const
 Return the value of this attribute, converted to an integer. More...
 
double get_ValueDouble () const
 Return the value of this attribute, converted to a double. More...
 
void put_ValueInt (int iValue)
 Set the value from an integer. More...
 
void put_ValueDouble (double dValue)
 Set the value from a double. More...
 
cXmlDocumentget_Document () const
 
cXmlNodeGetPreviousSibling (const char *pszValue) const
 Navigate to a sibling node. More...
 
cXmlNodeGetNextSiblingX (const char *pszValue) const
 Navigate to a sibling node with the given 'value'. More...
 
cXmlElementget_NextSiblingElement () const
 
cXmlElementGetNextSiblingElement (const char *pszValue) const
 
virtual cXmlContainerToContainer ()
 
virtual cXmlNodeClone () const =0
 
virtual HRESULT SetParseNode (cXmlReader &rReader)=0
 
HRESULT SetParse (const char *pszData, CXML_ENCODING_TYPE eEncoding=CXML_ENCODING_UNKNOWN)
 
virtual HRESULT Print (cStreamOutput &rOut, int nDepth=0) const =0
 
virtual bool OnVisit (IXmlVisitor *pVisitor) const =0
 
ITERATE_t get_Row () const
 
StrLen_t get_Column () const
 
- Public Member Functions inherited from Gray::cListNodeT< cXmlNode >
cXmlNode * get_Next () const
 
cXmlNode * get_Prev () const
 
- Public Member Functions inherited from Gray::cListNodeBase
virtual ~cListNodeBase ()
 
cListBaseget_Parent () const noexcept
 
cListNodeBaseget_Next () const noexcept
 
cListNodeBaseget_Prev () const noexcept
 
bool hasParent () const noexcept
 
void RemoveFromParent ()
 
virtual HRESULT DisposeThis ()
 
- Public Member Functions inherited from Gray::cHeapObject
 cHeapObject ()
 
virtual ~cHeapObject ()
 
bool IsValidInsideN (INT_PTR index) const
 
bool IsValidInsidePtr (void const *pTest) const
 
virtual size_t GetHeapStatsThis (OUT ITERATE_t &iAllocCount) const
 
virtual bool isValidCheck () const noexcept
 

Static Public Member Functions

static HRESULT PrintDepth (cStreamOutput &rOut, int nDepth)
 
- Static Public Member Functions inherited from GrayLib::cXml
static StrLen_t GRAYCALL ParseMicrosoftBOM (const BYTE *pszData)
 
static bool GRAYCALL IsXML (const IniChar_t *pszStr, StrLen_t iLenMax=StrT::k_LEN_MAX)
 
static cXmlString GRAYCALL GetAttributeStr (const IniChar_t *pszName, const cXmlString &sValue)
 
static void AddPathElement (cXmlString &sPath, const cXmlString &sElement)
 
static void RemovePathElement (cXmlString &sPath, const cXmlString &sElement)
 

Public Attributes

cTextPos m_Pos
 Where (line,col) in the parsed XML document is this node? m_PosNode. More...
 

Protected Member Functions

 cXmlNode (XMLNODE_TYPE eNodeType, cXmlString sValue="")
 Only instantiate as a derived type. More...
 
virtual void SetCopy (const cXmlNode &n)
 
- Protected Member Functions inherited from Gray::cListNodeBase
virtual void put_Parent (cListBase *pParent)
 
 cListNodeBase () noexcept
 
- Protected Member Functions inherited from Gray::cHeapObject
const void * get_HeapPtr () const noexcept override
 Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr(). More...
 
- Protected Member Functions inherited from Gray::cNonCopyable
 cNonCopyable () noexcept
 Force the use of Factory creation via protected constructor. More...
 
 ~cNonCopyable () noexcept
 

Protected Attributes

const XMLNODE_TYPE m_eNodeType
 
cXmlString m_sValue
 parent usage dependent m_eNodeType. More...
 
void * m_pUserData
 Field containing a generic pointer to arbitrary user data. More...
 

Additional Inherited Members

- Public Types inherited from GrayLib::cXml
enum  XMLNODE_TYPE { XMLNODE_QTY }
 
- Static Public Attributes inherited from GrayLib::cXml
static const char k_xmlHeader [6] = "<?xml"
 "<?xml" // not case sensitive ! More...
 
static const char k_xmlEnd [3] = "?>"
 "?>" More...
 
static const char k_commentHeader [5] = "<!--"
 "<!--" // comments are not reentrant! More...
 
static const char k_commentEnd [4] = "-->"
 "-->" More...
 
static const char k_cdataHeader [10] = "<![CDATA["
 "<![CDATA[" More...
 
static const char k_cdataEnd [4] = "]]>"
 "]]>" More...
 
static const char k_dtdHeader [3] = "<!"
 "<!" More...
 

Detailed Description

Store a base node of data in the XML tree cXmlDocument. The parent/base class for everything in the cXmlDocument Object Model. (Except for attributes). Nodes have siblings, a parent, and children. A node can be in a document, or stand on its own. The type of a cXmlNode can be queried, and it can be cast to its more defined type. In XML, the document and elements can contain other elements and other types of nodes.

//!     A Document can contain: Element (container or leaf)
//!                                                     Comment (leaf)
//!                                                     Unknown (leaf)
//!                                                     Declaration( leaf )
//!
//!     An Element can contain: Element (container or leaf)
//!                                                     Text    (leaf)
//!                                                     Attributes (not on tree)
//!                                                     Comment (leaf)
//!                                                     Unknown (leaf)
//!
//!     A Declaration contains: Attributes (not on tree)
//!     

Constructor & Destructor Documentation

◆ cXmlNode()

GrayLib::cXmlNode::cXmlNode ( XMLNODE_TYPE  eNodeType,
cXmlString  sValue = "" 
)
protected

Only instantiate as a derived type.

◆ ~cXmlNode()

GrayLib::cXmlNode::~cXmlNode ( )
virtual

Member Function Documentation

◆ Clone()

virtual cXmlNode* GrayLib::cXmlNode::Clone ( ) const
pure virtual

Create an exact duplicate of this node and return it. The memory must be deleted by the caller.

Implemented in GrayLib::cXmlDocument, GrayLib::cXmlElement, GrayLib::cXmlUnknown, GrayLib::cXmlDeclaration, GrayLib::cXmlText, and GrayLib::cXmlComment.

◆ get_Column()

StrLen_t GrayLib::cXmlNode::get_Column ( ) const
inline

◆ get_Document()

cXmlDocument * GrayLib::cXmlNode::get_Document ( ) const

Return a pointer to the Document this node lives in. Returns nullptr if not in a document.

Walk up the tree to my top level parent document.

◆ get_NextSiblingElement()

cXmlElement * GrayLib::cXmlNode::get_NextSiblingElement ( ) const

Convenience function to get through elements. Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns nullptr if there is not another element.

◆ get_Row()

ITERATE_t GrayLib::cXmlNode::get_Row ( ) const
inline

Return the position, in the original source file, of this node or attribute. The row and column are 1-based. (That is the first row and first column is 1,1). If the returns values are 0 or less, then the parser does not have a row and column value.

Generally, the row and column value will be set when the cXmlDocument::Load(), cXmlDocument::LoadFile(), or any cXmlNode::ParseNode() is called. It will NOT be set when the DOM was created from operator>>.

The values reflect the initial load. Once the DOM is modified programmatically (by adding or changing nodes and attributes) the new values will NOT update to reflect changes in the document.

There is a minor performance cost to computing the row and column. Computation can be disabled if cXmlDocument::SetTabSize() is called with 0 as the value.

See also
cXmlDocument::SetTabSize()

◆ get_Type()

XMLNODE_TYPE GrayLib::cXmlNode::get_Type ( ) const
inline

< Query the type (as an enumerated value, above) of this node.

◆ get_UserData()

void* GrayLib::cXmlNode::get_UserData ( ) const
inline

< Get a pointer to arbitrary user data.

◆ get_Value()

const cXmlString& GrayLib::cXmlNode::get_Value ( void  ) const
inline

< Return the value of this attribute. string.

◆ get_ValueDouble()

double GrayLib::cXmlNode::get_ValueDouble ( ) const

Return the value of this attribute, converted to a double.

◆ get_ValueInt()

int GrayLib::cXmlNode::get_ValueInt ( ) const

Return the value of this attribute, converted to an integer.

◆ GetNextSiblingElement()

cXmlElement * GrayLib::cXmlNode::GetNextSiblingElement ( const char *  pszValue) const

Convenience function to get through elements. Calls NextSibling and ToElement. Will skip all non-Element nodes. Returns nullptr if there is not another element.

◆ GetNextSiblingX()

cXmlNode * GrayLib::cXmlNode::GetNextSiblingX ( const char *  pszValue) const

Navigate to a sibling node with the given 'value'.

Get the next element/node with this value.

Note
this name conflicts with something in WIN32 . no idea what.

◆ GetPreviousSibling()

cXmlNode * GrayLib::cXmlNode::GetPreviousSibling ( const char *  pszValue) const

Navigate to a sibling node.

Get the previous element/node with this value.

◆ isType()

bool GrayLib::cXmlNode::isType ( XMLNODE_TYPE  eType) const
inline

◆ OnVisit()

virtual bool GrayLib::cXmlNode::OnVisit ( IXmlVisitor pVisitor) const
pure virtual

OnVisit a hierarchical visit the nodes in the cXml DOM. Every node in the XML tree will be conditionally visited and the host will be called back via the IXmlVisitor interface.

This is essentially a SAX interface for cXml. (Note however it doesn't re-parse the XML for the callbacks, so the performance of cXml is unchanged by using this interface versus any other.)

The interface has been based on ideas from:

Which are both good references for "visiting". An example of using OnVisit():

//! cXmlWriter printer;
//! xmlDoc.OnVisit( &printer );
//! const char* xmlcstr = printer.CStr();
//! 

Implemented in GrayLib::cXmlElement, GrayLib::cXmlDeclaration, GrayLib::cXmlComment, GrayLib::cXmlDocument, GrayLib::cXmlUnknown, and GrayLib::cXmlText.

◆ Print()

virtual HRESULT GrayLib::cXmlNode::Print ( cStreamOutput rOut,
int  nDepth = 0 
) const
pure virtual

All cXml classes can print themselves to a filestream or the string class (cXmlString in non-STL mode, std::string in STL mode.) Either or both pFile and string can be null.

This is a formatted print, and will insert tabs and newlines.

(For an unformatted stream, use the << operator.)

Implemented in GrayLib::cXmlDocument, GrayLib::cXmlElement, GrayLib::cXmlUnknown, GrayLib::cXmlDeclaration, GrayLib::cXmlText, and GrayLib::cXmlComment.

◆ PrintDepth()

HRESULT GrayLib::cXmlNode::PrintDepth ( cStreamOutput rOut,
int  nDepth 
)
static

Tab in the file to show depth.

◆ put_UserData()

void GrayLib::cXmlNode::put_UserData ( void *  pUserData)
inline

< Set a pointer to arbitrary user data.

◆ put_Value()

void GrayLib::cXmlNode::put_Value ( cXmlString  sValue)
inline

< Set the value.

◆ put_ValueDouble()

void GrayLib::cXmlNode::put_ValueDouble ( double  dValue)

Set the value from a double.

like StrT::sprintfN( szBuffer, STRMAX(szBuffer), "%lf", dValue);

◆ put_ValueInt()

void GrayLib::cXmlNode::put_ValueInt ( int  iValue)

Set the value from an integer.

◆ QueryValueDouble()

HRESULT GrayLib::cXmlNode::QueryValueDouble ( double *  pdValue) const

QueryValueDouble examines the value string. See QueryValueInt().

error as if using scanf("%lf")

◆ QueryValueInt()

HRESULT GrayLib::cXmlNode::QueryValueInt ( int *  piValue) const

QueryValueInt examines the value string. It is an alternative to the IntValue() method with richer error checking. If the value is an integer, it is stored in 'value' and the call returns S_OK. If it is not an integer, it returns HRESULT_WIN32_C(ERROR_DATATYPE_MISMATCH).

A specialized but useful call. Note that for success it returns 0, which is the opposite of almost all other cXml calls.

error as if using scanf("%d")

◆ SetClear()

void GrayLib::cXmlNode::SetClear ( )
virtual

Delete all the children of this node. Does not affect 'this'.

Reimplemented in GrayLib::cXmlDocument, GrayLib::cXmlElement, GrayLib::cXmlDeclaration, and GrayLib::cXmlText.

◆ SetCopy()

void GrayLib::cXmlNode::SetCopy ( const cXmlNode n)
protectedvirtual

Copy to the allocated object. Shared functionality between Clone, Copy constructor, and the assignment operator.

◆ SetParse()

HRESULT GrayLib::cXmlNode::SetParse ( const char *  pszData,
CXML_ENCODING_TYPE  eEncoding = CXML_ENCODING_UNKNOWN 
)

Populate node. Just parse a block of text for this node type. Like JavaScript DOMParser.parseFromString()

◆ SetParseNode()

virtual HRESULT GrayLib::cXmlNode::SetParseNode ( cXmlReader rReader)
pure virtual

◆ ToContainer()

virtual cXmlContainer* GrayLib::cXmlNode::ToContainer ( )
inlinevirtual

Is this Node a child container? Can it have children?

Reimplemented in GrayLib::cXmlDocument, and GrayLib::cXmlElement.

Member Data Documentation

◆ m_eNodeType

const XMLNODE_TYPE GrayLib::cXmlNode::m_eNodeType
protected

◆ m_Pos

cTextPos GrayLib::cXmlNode::m_Pos

Where (line,col) in the parsed XML document is this node? m_PosNode.

◆ m_pUserData

void* GrayLib::cXmlNode::m_pUserData
protected

Field containing a generic pointer to arbitrary user data.

◆ m_sValue

cXmlString GrayLib::cXmlNode::m_sValue
protected

parent usage dependent m_eNodeType.


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