00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #include "TXMLNode.h"
00026 #include "TXMLAttr.h"
00027 #include "TList.h"
00028 #include <libxml/tree.h>
00029 
00030 
00031 ClassImp(TXMLNode);
00032 
00033 
00034 TXMLNode::TXMLNode(xmlNode *node, TXMLNode *parent, TXMLNode *previous) :
00035    fXMLNode(node), fParent(parent), fChildren(0), fNextNode(0),
00036    fPreviousNode(previous), fAttrList(0)
00037 {
00038    
00039 }
00040 
00041 
00042 TXMLNode::~TXMLNode()
00043 {
00044    
00045    
00046 
00047    delete fChildren;
00048    delete fNextNode;
00049    if (fAttrList)
00050       fAttrList->Delete();
00051    delete fAttrList;
00052 
00053 }
00054 
00055 
00056 TXMLNode::EXMLElementType TXMLNode::GetNodeType() const
00057 {
00058    
00059 
00060    return (TXMLNode::EXMLElementType) fXMLNode->type;
00061 }
00062 
00063 
00064 const char *TXMLNode::GetNodeName() const
00065 {
00066    
00067 
00068    return (const char *) fXMLNode->name;
00069 }
00070 
00071 
00072 TXMLNode *TXMLNode::GetChildren()
00073 {
00074    
00075 
00076    if (fChildren)
00077       return fChildren;
00078 
00079    if (fXMLNode->children){
00080       fChildren = new TXMLNode(fXMLNode->children, this);
00081       return fChildren;
00082    }
00083    return 0;
00084 }
00085 
00086 
00087 TXMLNode *TXMLNode::GetParent() const
00088 {
00089    
00090 
00091    return fParent;
00092 }
00093 
00094 
00095 const char *TXMLNode::GetContent() const
00096 {
00097    
00098 
00099    if (fXMLNode->content)
00100       return (const char *) fXMLNode->content;
00101    return 0;
00102 }
00103 
00104 
00105 TList *TXMLNode::GetAttributes()
00106 {
00107    
00108    
00109 
00110    if (fAttrList)
00111       return fAttrList;
00112 
00113    if (!HasAttributes())
00114       return 0;
00115 
00116    fAttrList = new TList();
00117    xmlAttr *attr_node = fXMLNode->properties;
00118    for (; attr_node; attr_node = attr_node->next) {
00119       fAttrList->Add(new TXMLAttr((const char *) attr_node->name,
00120                                   (const char *) attr_node->children->content));
00121    }
00122 
00123    return fAttrList;
00124 }
00125 
00126 
00127 TXMLNode *TXMLNode::GetNextNode()
00128 {
00129    
00130    
00131 
00132    if (fNextNode)
00133       return fNextNode;
00134 
00135    if (fXMLNode->next) {
00136       fNextNode = new TXMLNode(fXMLNode->next, fParent, this);
00137       return fNextNode;
00138    }
00139    return 0;
00140 }
00141 
00142 
00143 TXMLNode *TXMLNode::GetPreviousNode() const
00144 {
00145    
00146    
00147 
00148    return fPreviousNode;
00149 }
00150 
00151 
00152 const char *TXMLNode::GetText() const
00153 {
00154    
00155 
00156    if (GetNodeType() == kXMLElementNode && HasChildren()) {
00157       if (fXMLNode->children->type == XML_TEXT_NODE)
00158          return (const char *) fXMLNode->children->content;
00159    }
00160    return 0;
00161 }
00162 
00163 
00164 Bool_t TXMLNode::HasChildren() const
00165 {
00166    
00167 
00168    return fXMLNode->children ? kTRUE : kFALSE;
00169 }
00170 
00171 
00172 Bool_t TXMLNode::HasNextNode() const
00173 {
00174    
00175 
00176    return fXMLNode->next ? kTRUE : kFALSE;
00177 }
00178 
00179 
00180 Bool_t TXMLNode::HasParent() const
00181 {
00182    
00183 
00184    return fXMLNode->parent ? kTRUE : kFALSE;
00185 }
00186 
00187 
00188 Bool_t TXMLNode::HasPreviousNode() const
00189 {
00190    
00191 
00192    return fXMLNode->prev ? kTRUE : kFALSE;
00193 }
00194 
00195 
00196 Bool_t TXMLNode::HasAttributes() const
00197 {
00198    
00199 
00200    return fXMLNode->properties ? kTRUE : kFALSE;
00201 }
00202 
00203 
00204 const char *TXMLNode::GetNamespaceHref() const
00205 {
00206    
00207 
00208    if (fXMLNode->ns) {
00209       return (const char *) fXMLNode->ns->href;
00210    }
00211    return 0;
00212 }
00213 
00214 
00215 const char *TXMLNode::GetNamespacePrefix() const
00216 {
00217    
00218 
00219    if (fXMLNode->ns) {
00220       return (const char *) fXMLNode->ns->prefix;
00221    }
00222    return 0;
00223 }