Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

xml::CXMLNode Class Reference

#include <XMLNode.h>


Public Member Functions

 CXMLNode (void)
 CXMLNode (xmlNodePtr node)
virtual ~CXMLNode (void)
bool getName (std::string *destination)
int getType (void)
bool getFirstChildNode (CXMLNode *destination)
 This returns the first child node of this node.

bool getNextSiblingNode (CXMLNode *destination)
 This returns the next sibling node of this node.

bool getNameSpace (CXMLNameSpace *destination)
bool hasNameSpace (void)
bool getContent (std::string *destination)
bool getFirstDescendantByName (const std::string &name, CXMLNode *node)
 Returns the first descendant of this node with the given name.

bool getText (std::string *destination)
 Returns the text of this node.

bool getAttributes (CXMLAttributeList *destination)
 Returns the attributes of a node.

bool getAttributeByName (const std::string &attrName, CXMLAttribute *destination)
 Returns the attribute of this node with the given name.

void print (bool recursive=false)
 Prints out this node.


Static Private Member Functions

xmlNodePtr getFirstDescendantByNamexmlPtr (const std::string &name, xmlNodePtr current)

Private Attributes

xmlNode * m_node


Constructor & Destructor Documentation

xml::CXMLNode::CXMLNode void   ) 
 

Definition at line 97 of file XMLNode.cpp.

References m_node.

Referenced by getFirstChildNode(), getFirstDescendantByName(), getNextSiblingNode(), and print().

00097                                {
00098                 this->m_node = NULL;
00099         }

xml::CXMLNode::CXMLNode xmlNodePtr  node  ) 
 

Definition at line 105 of file XMLNode.cpp.

References m_node.

00105                                           {
00106                 this->m_node = node;
00107         }

xml::CXMLNode::~CXMLNode void   )  [virtual]
 

Definition at line 113 of file XMLNode.cpp.

00113                                 {
00114                 // TODO: Currently it seems that xmlCleanup() does all the work
00115                 //       for all libxml objects.
00116                 //if(m_node != NULL) {
00117                 //      delete m_node;
00118                 //      m_node = NULL;
00119                 //}
00120         }


Member Function Documentation

bool xml::CXMLNode::getAttributeByName const std::string &  attrName,
CXMLAttribute destination
 

Returns the attribute of this node with the given name.

Definition at line 302 of file XMLNode.cpp.

References xml::CXMLAttributeList::get(), getAttributes(), xml::CXMLAttributeList::getSize(), and xml::CXMLAttribute::m_name.

Referenced by pge::SGFFile::parseLight(), pge::SGFFile::parseMesh(), and pge::TextureResourceFile::parseTexture().

00302                                                                                                {
00303                 xml::CXMLAttributeList attrList;
00304                 xml::CXMLAttribute attr;
00305                 int i;
00306 
00307         
00308                 // Get the attribute of the node.
00309                 if(getAttributes(&attrList)) {
00310                         for(i = 0; i < attrList.getSize(); i++) {
00311                                 attr = attrList.get(i);
00312                                 if(attr.m_name == attrName) {
00313                                         *destination = attr;
00314                                         return true;
00315                                 }
00316                         }
00317                 }
00318                 return false;
00319         }

Here is the call graph for this function:

bool xml::CXMLNode::getAttributes CXMLAttributeList destination  ) 
 

Returns the attributes of a node.

Definition at line 274 of file XMLNode.cpp.

References xml::CXMLAttributeList::add(), and m_node.

Referenced by getAttributeByName().

00274                                                                    {
00275                 xmlAttr *aPtr;
00276 
00277 
00278                 if(destination == NULL) {
00279                         return false;
00280                 }
00281 
00282                 if(m_node != NULL) {
00283                         if(m_node->properties != NULL) {
00284 
00285                                 aPtr = m_node->properties;
00286 
00287                                 while(aPtr != NULL) {
00288                                         CXMLAttribute attr = CXMLAttribute(aPtr);
00289                                         destination->add(attr);
00290                                         aPtr = aPtr->next;
00291                                 }
00292                                 return true;
00293                         }
00294                 }
00295                 return false;
00296         }

Here is the call graph for this function:

bool xml::CXMLNode::getContent std::string *  destination  ) 
 

Definition at line 229 of file XMLNode.cpp.

References m_node.

00229                                                         {
00230                 if(this->m_node) {
00231                         if(this->m_node->content) {
00232                                 *destination = std::string((char*)this->m_node->content);
00233                                 return true;
00234                         }
00235                 }
00236                 return false;
00237         }

bool xml::CXMLNode::getFirstChildNode CXMLNode destination  ) 
 

This returns the first child node of this node.

This returns the first child node of this node. The child must be an element node. No text nodes or other nodes are returned, only element nodes.

Definition at line 148 of file XMLNode.cpp.

References CXMLNode(), and m_node.

Referenced by pge::SGFFile::parseLight(), pge::SGFFile::parseMesh(), and pge::TextureResourceFile::parseTexture().

00148                                                               {
00149                 xmlNode *nPtr;
00150 
00151 
00152                 if(m_node != NULL) {
00153                         if(m_node->children != NULL) {
00154 
00155                                 nPtr = m_node->children;
00156 
00157                                 while(nPtr != NULL) {
00158 
00159                                         // Get the first child element node, no text nodes!
00160                                         if(nPtr->type == XML_ELEMENT_NODE) {
00161                                                 *destination = CXMLNode(nPtr);
00162                                                 return true;
00163                                         }
00164                                         nPtr = nPtr->next;
00165                                 }
00166                         }
00167                 }
00168                 return false;
00169         }

Here is the call graph for this function:

bool xml::CXMLNode::getFirstDescendantByName const std::string &  name,
CXMLNode node
 

Returns the first descendant of this node with the given name.

Returns the first descendant of this node with the given name. The function returns false, if there is no such node.

Definition at line 243 of file XMLNode.cpp.

References CXMLNode(), and m_node.

Referenced by pge::SGFFile::parseMesh().

00243                                                                                             {
00244                 if(this->m_node) {
00245                         xmlNodePtr result = CXMLNode::getFirstDescendantByNamexmlPtr(name, this->m_node);
00246                         if(result) {
00247                                 *destination = CXMLNode(result);
00248                                 return true;
00249                         }
00250                 }
00251                 return false;
00252         }

Here is the call graph for this function:

xmlNodePtr xml::CXMLNode::getFirstDescendantByNamexmlPtr const std::string &  name,
xmlNodePtr  current
[static, private]
 

Definition at line 364 of file XMLNode.cpp.

00364                                                                                                      {
00365                 //
00366                 // Variables
00367                 //
00368                 xmlNodePtr nodePtr = NULL;
00369                 xmlNodePtr recNode = NULL;
00370 
00371 
00372                 // Loop through all children of this node and check against name.
00373                 // Do this first loop without recursion, because we want to first check the
00374                 // first complete sibling level. If its not found, then procede with recursion.
00375                 for(nodePtr = current->children; nodePtr != NULL; nodePtr = nodePtr->next) {
00376                         // Ignore text only nodes
00377                         if(nodePtr->type != XML_TEXT_NODE) {
00378                                 // Check for same name
00379                                 if(nodePtr->name) {
00380                                         if(std::string((char*)nodePtr->name) == name) {
00381                                                 return nodePtr;
00382                                         }
00383                                 }
00384                         }
00385                 }
00386 
00387                 // It was not found in the above loop, so go ahead with recursion;
00388                 for(nodePtr = current->children; nodePtr != NULL; nodePtr = nodePtr->next) {
00389                         // Ignore text only nodes
00390                         if(nodePtr->type != XML_TEXT_NODE) {
00391                                 recNode = CXMLNode::getFirstDescendantByNamexmlPtr(name, nodePtr);
00392                                 if(recNode) {
00393                                         return recNode;
00394                                 }
00395                         }
00396                 }
00397 
00398                 return NULL;
00399         }

bool xml::CXMLNode::getName std::string *  destination  ) 
 

Definition at line 126 of file XMLNode.cpp.

References m_node.

Referenced by pge::SGFFile::parseMesh(), and pge::TextureResourceFile::parseTexture().

00126                                                      {
00127                 if(this->m_node) {
00128                         if(this->m_node->name) {
00129                                 *destination = std::string((char*)this->m_node->name);
00130                                 return true;
00131                         }
00132                 }
00133                 return false;
00134         }

bool xml::CXMLNode::getNameSpace CXMLNameSpace destination  ) 
 

Definition at line 202 of file XMLNode.cpp.

References m_node.

00202                                                               {
00203                 if(this->m_node) {
00204                         if(this->m_node->ns) {
00205                                 *destination = CXMLNameSpace(this->m_node->ns);
00206                                 return true;
00207                         }
00208                 }
00209                 return false;
00210         }

bool xml::CXMLNode::getNextSiblingNode CXMLNode destination  ) 
 

This returns the next sibling node of this node.

This returns the next sibling node of this node. The sibling must be an element node. No text nodes or other nodes are returned, only element nodes.

Definition at line 175 of file XMLNode.cpp.

References CXMLNode(), and m_node.

Referenced by pge::SGFFile::parseLight(), pge::SGFFile::parseMesh(), and pge::TextureResourceFile::parseTexture().

00175                                                                {
00176                 xmlNode *nPtr;
00177 
00178 
00179                 if(m_node != NULL) {
00180                         if(m_node->next != NULL) {
00181 
00182                                 nPtr = m_node->next;
00183 
00184                                 while(nPtr != NULL) {
00185 
00186                                         // Get the first child element node, no text nodes!
00187                                         if(nPtr->type == XML_ELEMENT_NODE) {
00188                                                 *destination = CXMLNode(nPtr);
00189                                                 return true;
00190                                         }
00191                                         nPtr = nPtr->next;
00192                                 }
00193                         }
00194                 }
00195                 return false;
00196         }

Here is the call graph for this function:

bool xml::CXMLNode::getText std::string *  destination  ) 
 

Returns the text of this node.

Returns the text of this node. This only returns text, if the node has a child with text content. If not, the function returns false.

Definition at line 258 of file XMLNode.cpp.

References m_node.

Referenced by pge::SGFFile::parseLight(), pge::SGFFile::parseMesh(), and pge::TextureResourceFile::parseTexture().

00258                                                      {
00259                 if(this->m_node) {
00260                         if(this->m_node->children) {
00261                                 if(this->m_node->children->content) {
00262                                         *destination = std::string((char*)this->m_node->children->content);
00263                                         return true;
00264                                 }
00265                         }
00266                 }
00267                 return false;
00268         }

int xml::CXMLNode::getType void   ) 
 

Definition at line 140 of file XMLNode.cpp.

References m_node.

00140                                   {
00141                 return this->m_node->type;
00142         }

bool xml::CXMLNode::hasNameSpace void   ) 
 

Definition at line 216 of file XMLNode.cpp.

References m_node.

Referenced by print().

00216                                         {
00217                 if(this->m_node != NULL) {
00218                         if(this->m_node->ns != NULL) {
00219                                 return true;
00220                         }
00221                 }
00222                 return false;
00223         }

void xml::CXMLNode::print bool  recursive = false  ) 
 

Prints out this node.

Definition at line 325 of file XMLNode.cpp.

References CXMLNode(), hasNameSpace(), and m_node.

00325                                            {
00326                 //
00327                 // Variablen
00328                 //
00329                 xmlNodePtr nodePtr = NULL;
00330 
00331 
00332                 // Gebe den momentanen Knoten aus
00333                 switch(this->m_node->type) {
00334                 case 1: printf("XML Element Node: "); break;
00335                 case 2: printf("XML Attribute Node: "); break;
00336                 case 3: printf("XML Text Node: "); break;
00337                 case 6: printf("XML Entity Node: "); break;
00338                 case 8: printf("XML Comment Node: "); break;
00339                 default: break;
00340                 }
00341 
00342                 if(hasNameSpace()) {
00343                         // Name with namespace.
00344                         printf("Name=\"%s::%s\";\n", this->m_node->ns->prefix, this->m_node->name);
00345                 } else {
00346                         printf("Name=\"%s\";\n", this->m_node->name);
00347                 }
00348 
00349                 if(recursive) {
00350                         // Gebe alle Kinder des aktuellen Knotens aus
00351                         for(nodePtr = this->m_node->children; nodePtr != NULL; nodePtr = nodePtr->next) {
00352                                 // Ignoriere Text Knoten, da dies unheimlich viele Leerzeichenausgaben ergeben wuerde
00353                                 if(nodePtr->type != XML_TEXT_NODE) {
00354                                         CXMLNode(nodePtr).print(true);
00355                                 }
00356                         }
00357                 }
00358         }

Here is the call graph for this function:


Field Documentation

xmlNode* xml::CXMLNode::m_node [private]
 

Definition at line 162 of file XMLNode.h.

Referenced by CXMLNode(), getAttributes(), getContent(), getFirstChildNode(), getFirstDescendantByName(), getName(), getNameSpace(), getNextSiblingNode(), getText(), getType(), hasNameSpace(), and print().


The documentation for this class was generated from the following files:
Generated on Mon Oct 16 12:10:03 2006 for Phobosengine by doxygen 1.3.4