00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025
00026 int CXMLNode::GetType() const
00027 {
00028 return m_nNode;
00029 }
00030
00031 CXMLNode* CXMLNode::AsNode() const
00032 {
00033 return (CXMLNode*)this;
00034 }
00035
00036 CXMLElement* CXMLNode::AsElement() const
00037 {
00038 return ( m_nNode == xmlElement ) ? (CXMLElement*)this : NULL;
00039 }
00040
00041 CXMLAttribute* CXMLNode::AsAttribute() const
00042 {
00043 return ( m_nNode == xmlAttribute ) ? (CXMLAttribute*)this : NULL;
00044 }
00045
00047
00048
00049 CXMLElement* CXMLNode::GetParent() const
00050 {
00051 return m_pParent;
00052 }
00053
00054 void CXMLNode::Delete()
00055 {
00056 if ( this == NULL ) return;
00057
00058 if ( m_pParent != NULL )
00059 {
00060 if ( m_nNode == xmlElement ) m_pParent->RemoveElement( (CXMLElement*)this );
00061 else if ( m_nNode == xmlAttribute ) m_pParent->RemoveAttribute( (CXMLAttribute*)this );
00062 }
00063
00064 delete this;
00065 }
00066
00068
00069
00070 CString CXMLNode::GetName() const
00071 {
00072 return m_sName;
00073 }
00074
00075 void CXMLNode::SetName(LPCTSTR pszValue)
00076 {
00077 m_sName = pszValue;
00078 }
00079
00080 BOOL CXMLNode::IsNamed(LPCTSTR pszName) const
00081 {
00082 if ( this == NULL ) return FALSE;
00083 return m_sName.CompareNoCase( pszName ) == 0;
00084 }
00085
00087
00088
00089 CString CXMLNode::GetValue() const
00090 {
00091 return m_sValue;
00092 }
00093
00094 void CXMLNode::SetValue(LPCTSTR pszValue)
00095 {
00096 m_sValue = pszValue;
00097 }
00098
00100
00101
00102 CXMLElement* CXMLElement::Detach()
00103 {
00104 if ( m_pParent ) m_pParent->RemoveElement( this );
00105 m_pParent = NULL;
00106 return this;
00107 }
00108
00110
00111
00112 CXMLElement* CXMLElement::AddElement(LPCTSTR pszName)
00113 {
00114 CXMLElement* pElement = new CXMLElement( this, pszName );
00115 m_pElements.AddTail( pElement );
00116 return pElement;
00117 }
00118
00119 CXMLElement* CXMLElement::AddElement(CXMLElement* pElement)
00120 {
00121 if ( pElement->m_pParent ) return NULL;
00122 m_pElements.AddTail( pElement );
00123 pElement->m_pParent = this;
00124 return pElement;
00125 }
00126
00127 int CXMLElement::GetElementCount() const
00128 {
00129 return (int)m_pElements.GetCount();
00130 }
00131
00132 CXMLElement* CXMLElement::GetFirstElement() const
00133 {
00134 if ( this == NULL ) return NULL;
00135 return m_pElements.GetCount() ? (CXMLElement*)m_pElements.GetHead() : NULL;
00136 }
00137
00138 POSITION CXMLElement::GetElementIterator() const
00139 {
00140 return m_pElements.GetHeadPosition();
00141 }
00142
00143 CXMLElement* CXMLElement::GetNextElement(POSITION& pos) const
00144 {
00145 return (CXMLElement*)m_pElements.GetNext( pos );
00146 }
00147
00148 CXMLElement* CXMLElement::GetElementByName(LPCTSTR pszName) const
00149 {
00150 for ( POSITION pos = GetElementIterator() ; pos ; )
00151 {
00152 CXMLElement* pElement = GetNextElement( pos );
00153 if ( pElement->GetName().CompareNoCase( pszName ) == 0 ) return pElement;
00154 }
00155 return NULL;
00156 }
00157
00158 CXMLElement* CXMLElement::GetElementByName(LPCTSTR pszName, BOOL bCreate)
00159 {
00160 for ( POSITION pos = GetElementIterator() ; pos ; )
00161 {
00162 CXMLElement* pElement = GetNextElement( pos );
00163 if ( pElement->GetName().CompareNoCase( pszName ) == 0 ) return pElement;
00164 }
00165
00166 return bCreate ? AddElement( pszName ) : NULL;
00167 }
00168
00169 void CXMLElement::RemoveElement(CXMLElement* pElement)
00170 {
00171 POSITION pos = m_pElements.Find( pElement );
00172 if ( pos ) m_pElements.RemoveAt( pos );
00173 }
00174
00176
00177
00178 CXMLAttribute* CXMLElement::AddAttribute(LPCTSTR pszName, LPCTSTR pszValue)
00179 {
00180 CXMLAttribute* pAttribute = GetAttribute( pszName );
00181
00182 if ( ! pAttribute )
00183 {
00184 pAttribute = new CXMLAttribute( this, pszName );
00185 CString strName( pszName );
00186 strName.MakeLower();
00187 m_pAttributes.SetAt( strName, pAttribute );
00188 }
00189
00190 if ( pszValue ) pAttribute->SetValue( pszValue );
00191
00192 return pAttribute;
00193 }
00194
00195 CXMLAttribute* CXMLElement::AddAttribute(CXMLAttribute* pAttribute)
00196 {
00197 if ( pAttribute->m_pParent ) return NULL;
00198 CString strName( pAttribute->m_sName );
00199 strName.MakeLower();
00200 m_pAttributes.SetAt( pAttribute->m_sName, pAttribute );
00201 pAttribute->m_pParent = this;
00202 return pAttribute;
00203 }
00204
00205 int CXMLElement::GetAttributeCount() const
00206 {
00207 return (int)m_pAttributes.GetCount();
00208 }
00209
00210 POSITION CXMLElement::GetAttributeIterator() const
00211 {
00212 return m_pAttributes.GetStartPosition();
00213 }
00214
00215 CXMLAttribute* CXMLElement::GetNextAttribute(POSITION& pos) const
00216 {
00217 CXMLAttribute* pAttribute = NULL;
00218 CString strName;
00219 m_pAttributes.GetNextAssoc( pos, strName, XMLVOID(pAttribute) );
00220 return pAttribute;
00221 }
00222
00223 CXMLAttribute* CXMLElement::GetAttribute(LPCTSTR pszName) const
00224 {
00225 CXMLAttribute* pAttribute = NULL;
00226 CString strName( pszName );
00227 strName.MakeLower();
00228 return m_pAttributes.Lookup( strName, XMLVOID(pAttribute) ) ? pAttribute : NULL;
00229 }
00230
00231 CString CXMLElement::GetAttributeValue(LPCTSTR pszName, LPCTSTR pszDefault) const
00232 {
00233 CXMLAttribute* pAttribute = GetAttribute( pszName );
00234 CString strResult;
00235 if ( pAttribute ) strResult = pAttribute->m_sValue;
00236 else if ( pszDefault ) strResult = pszDefault;
00237 return strResult;
00238 }
00239
00240 void CXMLElement::RemoveAttribute(CXMLAttribute* pAttribute)
00241 {
00242 CString strName( pAttribute->m_sName );
00243 strName.MakeLower();
00244 m_pAttributes.RemoveKey( strName );
00245 }
00246
00247 void CXMLElement::DeleteAttribute(LPCTSTR pszName)
00248 {
00249 CXMLAttribute* pAttribute = GetAttribute( pszName );
00250 if ( pAttribute ) pAttribute->Delete();
00251 }