Main MRPT website > C++ reference for MRPT 1.5.7
List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
XMLNode Struct Reference

Detailed Description

Main Class representing a XML node.

All operations are performed using this class.

Note
The constructors of the XMLNode class are protected, so use instead one of these four methods to get your first instance of XMLNode:

Definition at line 275 of file xmlParser.h.

#include <utils/xmlparser/xmlParser.h>

Classes

struct  XMLNodeDataTag
 

Public Types

enum  XMLCharEncoding {
  char_encoding_error =0, char_encoding_UTF8 =1, char_encoding_legacy =2, char_encoding_ShiftJIS =3,
  char_encoding_GB2312 =4, char_encoding_Big5 =5, char_encoding_GBK =6
}
 Enumeration for XML character encoding. More...
 
typedef enum XMLNode::XMLCharEncoding XMLCharEncoding
 Enumeration for XML character encoding. More...
 

Public Member Functions

XMLSTR createXMLString (int nFormat=1, int *pnSize=NULL) const
 Create an XML string starting from the current XMLNode. More...
 
XMLError writeToFile (XMLCSTR filename, const char *encoding=NULL, char nFormat=1) const
 Save the content of an xmlNode inside a file. More...
 
XMLCSTR getName () const
 name of the node More...
 
XMLCSTR getText (int i=0) const
 return ith text field More...
 
int nText () const
 nbr of text field More...
 
XMLNode getParentNode () const
 return the parent node More...
 
XMLNode getChildNode (int i=0) const
 return ith child node More...
 
XMLNode getChildNode (XMLCSTR name, int i) const
 return ith child node with specific name (return an empty node if failing). If i==-1, this returns the last XMLNode with the given name. More...
 
XMLNode getChildNode (XMLCSTR name, int *i=NULL) const
 return next child node with specific name (return an empty node if failing) More...
 
XMLNode getChildNodeWithAttribute (XMLCSTR tagName, XMLCSTR attributeName, XMLCSTR attributeValue=NULL, int *i=NULL) const
 return child node with specific name/attribute (return an empty node if failing) More...
 
XMLNode getChildNodeByPath (XMLSTR path, char createNodeIfMissing=0, XMLCHAR sep='/')
 return the first child node with specific path. WARNING: the value of the parameter "path" is destroyed! More...
 
XMLNode getChildNodeByPath (XMLCSTR path, char createNodeIfMissing=0, XMLCHAR sep='/')
 return the first child node with specific path More...
 
int nChildNode (XMLCSTR name) const
 return the number of child node with specific name More...
 
int nChildNode () const
 nbr of child node More...
 
XMLAttribute getAttribute (int i=0) const
 return ith attribute More...
 
XMLCSTR getAttributeName (int i=0) const
 return ith attribute name More...
 
XMLCSTR getAttributeValue (int i=0) const
 return ith attribute value More...
 
char isAttributeSet (XMLCSTR name) const
 test if an attribute with a specific name is given More...
 
XMLCSTR getAttribute (XMLCSTR name, int i) const
 return ith attribute content with specific name (return a NULL if failing) More...
 
XMLCSTR getAttribute (XMLCSTR name, int *i=NULL) const
 return next attribute content with specific name (return a NULL if failing) More...
 
int nAttribute () const
 nbr of attribute More...
 
XMLClear getClear (int i=0) const
 return ith clear field (comments) More...
 
int nClear () const
 nbr of clear field More...
 
XMLNodeContents enumContents (XMLElementPosition i) const
 enumerate all the different contents (attribute,child,text, clear) of the current XMLNode. The order is reflecting the order of the original file/string. NOTE: 0 <= i < nElement(); More...
 
int nElement () const
 nbr of different contents for current node More...
 
char isEmpty () const
 is this node Empty? More...
 
char isDeclaration () const
 is this node a declaration <? .... ?> More...
 
XMLNode deepCopy () const
 deep copy (duplicate/clone) a XMLNode More...
 
 ~XMLNode ()
 
 XMLNode (const XMLNode &A)
 to allow shallow/fast copy: More...
 
XMLNodeoperator= (const XMLNode &A)
 to allow shallow/fast copy: More...
 
 XMLNode ()
 
XMLNode addChild (XMLCSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1)
 Add a new child node. More...
 
XMLNode addChild (XMLNode nodeToAdd, XMLElementPosition pos=-1)
 If the "nodeToAdd" has some parents, it will be detached from it's parents before being attached to the current XMLNode. More...
 
XMLAttributeaddAttribute (XMLCSTR lpszName, XMLCSTR lpszValuev)
 Add a new attribute. More...
 
XMLCSTR addText (XMLCSTR lpszValue, XMLElementPosition pos=-1)
 Add a new text content. More...
 
XMLClearaddClear (XMLCSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, XMLElementPosition pos=-1)
 Add a new clear tag. More...
 
XMLCSTR updateName (XMLCSTR lpszName)
 change node's name More...
 
XMLAttributeupdateAttribute (XMLAttribute *newAttribute, XMLAttribute *oldAttribute)
 if the attribute to update is missing, a new one will be added More...
 
XMLAttributeupdateAttribute (XMLCSTR lpszNewValue, XMLCSTR lpszNewName=NULL, int i=0)
 if the attribute to update is missing, a new one will be added More...
 
XMLAttributeupdateAttribute (XMLCSTR lpszNewValue, XMLCSTR lpszNewName, XMLCSTR lpszOldName)
 set lpszNewName=NULL if you don't want to change the name of the attribute if the attribute to update is missing, a new one will be added More...
 
XMLCSTR updateText (XMLCSTR lpszNewValue, int i=0)
 if the text to update is missing, a new one will be added More...
 
XMLCSTR updateText (XMLCSTR lpszNewValue, XMLCSTR lpszOldValue)
 if the text to update is missing, a new one will be added More...
 
XMLClearupdateClear (XMLCSTR lpszNewContent, int i=0)
 if the clearTag to update is missing, a new one will be added More...
 
XMLClearupdateClear (XMLClear *newP, XMLClear *oldP)
 if the clearTag to update is missing, a new one will be added More...
 
XMLClearupdateClear (XMLCSTR lpszNewValue, XMLCSTR lpszOldValue)
 if the clearTag to update is missing, a new one will be added More...
 
void deleteNodeContent ()
 The "deleteNodeContent" function forces the deletion of the content of this XMLNode and the subtree. More...
 
void deleteAttribute (int i=0)
 Delete the ith attribute of the current XMLNode. More...
 
void deleteAttribute (XMLCSTR lpszName)
 Delete the attribute with the given name (the "strcmp" function is used to find the right attribute) More...
 
void deleteAttribute (XMLAttribute *anAttribute)
 Delete the attribute with the name "anAttribute->lpszName" (the "strcmp" function is used to find the right attribute) More...
 
void deleteText (int i=0)
 Delete the Ith text content of the current XMLNode. More...
 
void deleteText (XMLCSTR lpszValue)
 Delete the text content "lpszValue" inside the current XMLNode (direct "pointer-to-pointer" comparison is used to find the right text) More...
 
void deleteClear (int i=0)
 Delete the Ith clear tag inside the current XMLNode. More...
 
void deleteClear (XMLCSTR lpszValue)
 Delete the clear tag "lpszValue" inside the current XMLNode (direct "pointer-to-pointer" comparison is used to find the clear tag) More...
 
void deleteClear (XMLClear *p)
 Delete the clear tag "p" inside the current XMLNode (direct "pointer-to-pointer" comparison on the lpszName of the clear tag is used to find the clear tag) More...
 
XMLNode addChild_WOSD (XMLSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1)
 Add a new child node. More...
 
XMLAttributeaddAttribute_WOSD (XMLSTR lpszName, XMLSTR lpszValue)
 Add a new attribute. More...
 
XMLCSTR addText_WOSD (XMLSTR lpszValue, XMLElementPosition pos=-1)
 Add a new text content. More...
 
XMLClearaddClear_WOSD (XMLSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, XMLElementPosition pos=-1)
 Add a new clear Tag. More...
 
XMLCSTR updateName_WOSD (XMLSTR lpszName)
 change node's name More...
 
XMLAttributeupdateAttribute_WOSD (XMLAttribute *newAttribute, XMLAttribute *oldAttribute)
 if the attribute to update is missing, a new one will be added More...
 
XMLAttributeupdateAttribute_WOSD (XMLSTR lpszNewValue, XMLSTR lpszNewName=NULL, int i=0)
 if the attribute to update is missing, a new one will be added More...
 
XMLAttributeupdateAttribute_WOSD (XMLSTR lpszNewValue, XMLSTR lpszNewName, XMLCSTR lpszOldName)
 set lpszNewName=NULL if you don't want to change the name of the attribute if the attribute to update is missing, a new one will be added More...
 
XMLCSTR updateText_WOSD (XMLSTR lpszNewValue, int i=0)
 if the text to update is missing, a new one will be added More...
 
XMLCSTR updateText_WOSD (XMLSTR lpszNewValue, XMLCSTR lpszOldValue)
 if the text to update is missing, a new one will be added More...
 
XMLClearupdateClear_WOSD (XMLSTR lpszNewContent, int i=0)
 if the clearTag to update is missing, a new one will be added More...
 
XMLClearupdateClear_WOSD (XMLClear *newP, XMLClear *oldP)
 if the clearTag to update is missing, a new one will be added More...
 
XMLClearupdateClear_WOSD (XMLSTR lpszNewValue, XMLCSTR lpszOldValue)
 if the clearTag to update is missing, a new one will be added More...
 
XMLElementPosition positionOfText (int i=0) const
 
XMLElementPosition positionOfText (XMLCSTR lpszValue) const
 
XMLElementPosition positionOfClear (int i=0) const
 
XMLElementPosition positionOfClear (XMLCSTR lpszValue) const
 
XMLElementPosition positionOfClear (XMLClear *a) const
 
XMLElementPosition positionOfChildNode (int i=0) const
 
XMLElementPosition positionOfChildNode (XMLNode x) const
 
XMLElementPosition positionOfChildNode (XMLCSTR name, int i=0) const
 return the position of the ith childNode with the specified name if (name==NULL) return the position of the ith childNode More...
 

Static Public Member Functions

static XMLCSTR getVersion ()
 Return the XMLParser library version number. More...
 
static XMLNode parseString (XMLCSTR lpXMLString, XMLCSTR tag=NULL, XMLResults *pResults=NULL)
 Parse an XML string and return the root of a XMLNode tree representing the string. More...
 
static XMLNode parseFile (XMLCSTR filename, XMLCSTR tag=NULL, XMLResults *pResults=NULL)
 Parse an XML file and return the root of a XMLNode tree representing the file. More...
 
static XMLNode openFileHelper (XMLCSTR filename, XMLCSTR tag=NULL)
 Parse an XML file and return the root of a XMLNode tree representing the file. A very crude error checking is made. An attempt to guess the Char Encoding used in the file is made. More...
 
static XMLCSTR getError (XMLError error)
 this gives you a user-friendly explanation of the parsing error More...
 
static XMLNode emptyNode ()
 return XMLNode::emptyXMLNode; More...
 
static XMLNode createXMLTopNode (XMLCSTR lpszName, char isDeclaration=FALSE)
 Create the top node of an XMLNode structure. More...
 
static XMLNode createXMLTopNode_WOSD (XMLSTR lpszName, char isDeclaration=FALSE)
 Create the top node of an XMLNode structure. More...
 
static char setGlobalOptions (XMLCharEncoding characterEncoding=XMLNode::char_encoding_UTF8, char guessWideCharChars=1, char dropWhiteSpace=1, char removeCommentsInMiddleOfText=1)
 Sets the global options for the conversions. More...
 
static XMLCharEncoding guessCharEncoding (void *buffer, int bufLen, char useXMLEncodingAttribute=1)
 Guess the character encoding of the string (ascii, utf8 or shift-JIS) More...
 

Static Public Attributes

static XMLNode emptyXMLNode
 
static XMLClear emptyXMLClear ={ NULL, NULL, NULL}
 
static XMLAttribute emptyXMLAttribute ={ NULL, NULL}
 

Private Types

typedef struct XMLNode::XMLNodeDataTag XMLNodeData
 

Private Member Functions

 XMLNode (struct XMLNodeDataTag *pParent, XMLSTR lpszName, char isDeclaration)
 Constructors are protected, so use instead one of: XMLNode::parseString, XMLNode::parseFile, XMLNode::openFileHelper, XMLNode::createXMLTopNode. More...
 
 XMLNode (struct XMLNodeDataTag *p)
 Constructors are protected, so use instead one of: XMLNode::parseString, XMLNode::parseFile, XMLNode::openFileHelper, XMLNode::createXMLTopNode. More...
 
char parseClearTag (void *px, void *pa)
 
char maybeAddTxT (void *pa, XMLCSTR tokenPStr)
 
int ParseXMLElement (void *pXML)
 
voidaddToOrder (int memInc, int *_pos, int nc, void *p, int size, XMLElementType xtype)
 
int indexText (XMLCSTR lpszValue) const
 
int indexClear (XMLCSTR lpszValue) const
 
XMLNode addChild_priv (int, XMLSTR, char, int)
 
XMLAttributeaddAttribute_priv (int, XMLSTR, XMLSTR)
 
XMLCSTR addText_priv (int, XMLSTR, int)
 
XMLClearaddClear_priv (int, XMLSTR, XMLCSTR, XMLCSTR, int)
 
void emptyTheNode (char force)
 

Static Private Member Functions

static XMLElementPosition findPosition (XMLNodeData *d, int index, XMLElementType xtype)
 
static int CreateXMLStringR (XMLNodeData *pEntry, XMLSTR lpszMarker, int nFormat)
 
static int removeOrderElement (XMLNodeData *d, XMLElementType t, int index)
 
static void exactMemory (XMLNodeData *d)
 
static int detachFromParent (XMLNodeData *d)
 

Private Attributes

XMLNodeDatad
 

Member Typedef Documentation

◆ XMLCharEncoding

typedef enum XMLNode::XMLCharEncoding XMLNode::XMLCharEncoding

Enumeration for XML character encoding.

◆ XMLNodeData

typedef struct XMLNode::XMLNodeDataTag XMLNode::XMLNodeData
private

Member Enumeration Documentation

◆ XMLCharEncoding

enum XMLNode::XMLCharEncoding

Enumeration for XML character encoding.

Enumerator
char_encoding_error 
char_encoding_UTF8 
char_encoding_legacy 
char_encoding_ShiftJIS 
char_encoding_GB2312 
char_encoding_Big5 
char_encoding_GBK 

Definition at line 527 of file xmlParser.h.

Constructor & Destructor Documentation

◆ XMLNode() [1/4]

XMLNode::XMLNode ( struct XMLNodeDataTag pParent,
XMLSTR  lpszName,
char  isDeclaration 
)
private

Constructors are protected, so use instead one of: XMLNode::parseString, XMLNode::parseFile, XMLNode::openFileHelper, XMLNode::createXMLTopNode.

◆ XMLNode() [2/4]

XMLNode::XMLNode ( struct XMLNodeDataTag p)
private

Constructors are protected, so use instead one of: XMLNode::parseString, XMLNode::parseFile, XMLNode::openFileHelper, XMLNode::createXMLTopNode.

Definition at line 976 of file xmlParser.cpp.

References d.

◆ ~XMLNode()

XMLNode::~XMLNode ( )

Definition at line 2048 of file xmlParser.cpp.

References d, and emptyTheNode().

◆ XMLNode() [3/4]

XMLNode::XMLNode ( const XMLNode A)

to allow shallow/fast copy:

Definition at line 2111 of file xmlParser.cpp.

References d.

◆ XMLNode() [4/4]

XMLNode::XMLNode ( )
inline

Definition at line 400 of file xmlParser.h.

Referenced by addChild_priv(), createXMLTopNode(), createXMLTopNode_WOSD(), and getParentNode().

Member Function Documentation

◆ addAttribute_priv()

XMLAttribute * XMLNode::addAttribute_priv ( int  memoryIncrease,
XMLSTR  lpszName,
XMLSTR  lpszValuev 
)
private

◆ addChild_priv()

XMLNode XMLNode::addChild_priv ( int  memoryIncrease,
XMLSTR  lpszName,
char  isDeclaration,
int  pos 
)
private

Definition at line 1066 of file xmlParser.cpp.

References addToOrder(), d, emptyXMLNode, eNodeChild, isDeclaration(), and XMLNode().

Referenced by addChild(), addChild_WOSD(), and ParseXMLElement().

◆ addClear_priv()

XMLClear * XMLNode::addClear_priv ( int  memoryIncrease,
XMLSTR  lpszValue,
XMLCSTR  lpszOpen,
XMLCSTR  lpszClose,
int  pos 
)
private

◆ addText_priv()

XMLCSTR XMLNode::addText_priv ( int  memoryIncrease,
XMLSTR  lpszValue,
int  pos 
)
private

Definition at line 1091 of file xmlParser.cpp.

References addToOrder(), d, eNodeText, myFree(), XMLCSTR, and XMLSTR.

Referenced by addText(), addText_WOSD(), and maybeAddTxT().

◆ addToOrder()

void * XMLNode::addToOrder ( int  memInc,
int *  _pos,
int  nc,
void p,
int  size,
XMLElementType  xtype 
)
private

Definition at line 1039 of file xmlParser.cpp.

References d, and myRealloc().

Referenced by addChild(), addChild_priv(), addClear_priv(), and addText_priv().

◆ CreateXMLStringR()

int XMLNode::CreateXMLStringR ( XMLNodeData pEntry,
XMLSTR  lpszMarker,
int  nFormat 
)
staticprivate

◆ detachFromParent()

int XMLNode::detachFromParent ( XMLNodeData d)
staticprivate

Definition at line 2037 of file xmlParser.cpp.

References d, eNodeChild, and removeOrderElement().

Referenced by addChild(), deleteNodeContent(), and emptyTheNode().

◆ emptyTheNode()

void XMLNode::emptyTheNode ( char  force)
private

Definition at line 2060 of file xmlParser.cpp.

References d, detachFromParent(), emptyTheNode(), and myFree().

Referenced by deleteNodeContent(), emptyTheNode(), operator=(), and ~XMLNode().

◆ exactMemory()

void XMLNode::exactMemory ( XMLNodeData d)
staticprivate

Definition at line 1162 of file xmlParser.cpp.

References d, XMLCSTR, and XMLSTR.

Referenced by ParseXMLElement().

◆ findPosition()

XMLElementPosition XMLNode::findPosition ( XMLNodeData d,
int  index,
XMLElementType  xtype 
)
inlinestaticprivate

Definition at line 1018 of file xmlParser.cpp.

References d.

Referenced by positionOfChildNode(), positionOfClear(), positionOfText(), and removeOrderElement().

◆ getVersion()

XMLCSTR XMLNode::getVersion ( )
static

Return the XMLParser library version number.

Definition at line 27 of file xmlParser.cpp.

References _CXML.

◆ indexClear()

int XMLNode::indexClear ( XMLCSTR  lpszValue) const
private

Definition at line 2293 of file xmlParser.cpp.

References d.

Referenced by deleteClear(), positionOfClear(), and updateClear_WOSD().

◆ indexText()

int XMLNode::indexText ( XMLCSTR  lpszValue) const
private

Definition at line 2244 of file xmlParser.cpp.

References d, and XMLCSTR.

Referenced by deleteText(), positionOfText(), and updateText_WOSD().

◆ maybeAddTxT()

char XMLNode::maybeAddTxT ( void pa,
XMLCSTR  tokenPStr 
)
private

◆ operator=()

XMLNode & XMLNode::operator= ( const XMLNode A)

to allow shallow/fast copy:

Definition at line 2099 of file xmlParser.cpp.

References d, and emptyTheNode().

◆ parseClearTag()

char XMLNode::parseClearTag ( void px,
void pa 
)
private

◆ ParseXMLElement()

int XMLNode::ParseXMLElement ( void pXML)
private

◆ removeOrderElement()

int XMLNode::removeOrderElement ( XMLNodeData d,
XMLElementType  t,
int  index 
)
staticprivate

Definition at line 1026 of file xmlParser.cpp.

References d, and findPosition().

Referenced by deleteClear(), deleteText(), and detachFromParent().

Member Data Documentation

◆ d

XMLNodeData* XMLNode::d
private

◆ emptyXMLAttribute

XMLAttribute XMLNode::emptyXMLAttribute ={ NULL, NULL}
static

Definition at line 403 of file xmlParser.h.

Referenced by addAttribute_priv(), and getAttribute().

◆ emptyXMLClear

XMLClear XMLNode::emptyXMLClear ={ NULL, NULL, NULL}
static

Definition at line 402 of file xmlParser.h.

Referenced by addClear_priv(), and getClear().

◆ emptyXMLNode

XMLNode XMLNode::emptyXMLNode
static



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019