Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

XML.h

Go to the documentation of this file.
00001 //
00002 // XML.h
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #pragma once
00023 
00024 class CXMLNode;
00025 class CXMLElement;
00026 class CXMLAttribute;
00027 
00028 
00029 class CXMLNode
00030 {
00031 // Construction
00032 public:
00033         CXMLNode(CXMLElement* pParent = NULL, LPCTSTR pszName = NULL);
00034         virtual ~CXMLNode();
00035 
00036 // Attributes
00037 protected:
00038         int                             m_nNode;
00039         CXMLElement*    m_pParent;
00040         CString                 m_sName;
00041         CString                 m_sValue;
00042 
00043         enum { xmlNode, xmlElement, xmlAttribute };
00044 
00045 // Operations
00046 public:
00047         inline int                              GetType() const;
00048         inline CXMLNode*                AsNode() const;
00049         inline CXMLElement*             AsElement() const;
00050         inline CXMLAttribute*   AsAttribute() const;
00051 public:
00052         inline CXMLElement*     GetParent() const;
00053         inline void                     Delete();
00054 public:
00055         inline CString          GetName() const;
00056         inline void                     SetName(LPCTSTR pszValue);
00057         inline BOOL                     IsNamed(LPCTSTR pszName) const;
00058         inline CString          GetValue() const;
00059         inline void                     SetValue(LPCTSTR pszValue);
00060 protected:
00061         static BOOL             ParseMatch(LPCTSTR& pszXML, LPCTSTR pszToken);
00062         static BOOL             ParseIdentifier(LPCTSTR& pszXML, CString& strIdentifier);
00063 #ifdef _AFX
00064         void                    Serialize(CArchive& ar);
00065 #endif
00066 public:
00067         static CString  StringToValue(LPCTSTR& pszXML, int nLength);
00068         static void             ValueToString(LPCTSTR pszValue, CString& strXML);
00069         static void             UniformString(CString& str);
00070 
00071         friend class CXMLElement;
00072         friend class CQuerySearch;
00073 
00074         friend class CXMLCOM;
00075 
00076 };
00077 
00078 
00079 class CXMLElement : public CXMLNode
00080 {
00081 // Construction
00082 public:
00083         CXMLElement(CXMLElement* pParent = NULL, LPCTSTR pszName = NULL);
00084         virtual ~CXMLElement();
00085 
00086 // Attributes
00087 protected:
00088 #ifdef _AFX
00089         CPtrList m_pElements;
00090         CMapStringToPtr m_pAttributes;
00091 #else
00092         CAtlList<CXMLElement*> m_pElements;
00093         CAtlMap<CString, CXMLAttribute*, CStringElementTraits<CString> > m_pAttributes;
00094 #endif
00095 
00096 // Operations
00097 public:
00098         CXMLElement*                    Clone(CXMLElement* pParent = NULL);
00099         inline CXMLElement*             Detach();
00100 public:
00101         inline CXMLElement*             AddElement(LPCTSTR pszName);
00102         inline CXMLElement*             AddElement(CXMLElement* pElement);
00103         inline int                              GetElementCount() const;
00104         inline CXMLElement*             GetFirstElement() const;
00105         inline POSITION                 GetElementIterator() const;
00106         inline CXMLElement*             GetNextElement(POSITION& pos) const;
00107         inline CXMLElement*             GetElementByName(LPCTSTR pszName) const;
00108         inline CXMLElement*             GetElementByName(LPCTSTR pszName, BOOL bCreate);
00109         inline void                             RemoveElement(CXMLElement* pElement);
00110         void                                    DeleteAllElements();
00111 public:
00112         inline CXMLAttribute*   AddAttribute(LPCTSTR pszName, LPCTSTR pszValue = NULL);
00113         inline CXMLAttribute*   AddAttribute(CXMLAttribute* pAttribute);
00114         inline int                              GetAttributeCount() const;
00115         inline POSITION                 GetAttributeIterator() const;
00116         inline CXMLAttribute*   GetNextAttribute(POSITION& pos) const;
00117         inline CXMLAttribute*   GetAttribute(LPCTSTR pszName) const;
00118         inline CString                  GetAttributeValue(LPCTSTR pszName, LPCTSTR pszDefault = NULL) const;
00119         inline void                             RemoveAttribute(CXMLAttribute* pAttribute);
00120         inline void                             DeleteAttribute(LPCTSTR pszName);
00121         void                                    DeleteAllAttributes();
00122 public:
00123         CString                 ToString(BOOL bHeader = FALSE, BOOL bNewline = FALSE);
00124         void                    ToString(CString& strXML, BOOL bNewline = FALSE);
00125         BOOL                    ParseString(LPCTSTR& strXML);
00126         BOOL                    Equals(CXMLElement* pXML) const;
00127         CString                 GetRecursiveWords();
00128         void                    AddRecursiveWords(CString& strWords);
00129 #ifdef _AFX
00130         void                    Serialize(CArchive& ar);
00131 #endif
00132 
00133         static CXMLElement* FromString(LPCTSTR pszXML, BOOL bHeader = FALSE);
00134         static CXMLElement* FromBytes(BYTE* pByte, DWORD nByte, BOOL bHeader = FALSE);
00135         static CXMLElement* FromFile(LPCTSTR pszPath, BOOL bHeader = FALSE);
00136         static CXMLElement* FromFile(HANDLE hFile, BOOL bHeader = FALSE);
00137 
00138 };
00139 
00140 
00141 class CXMLAttribute : public CXMLNode
00142 {
00143 // Construction
00144 public:
00145         CXMLAttribute(CXMLElement* pParent, LPCTSTR pszName = NULL);
00146         virtual ~CXMLAttribute();
00147 
00148 // Attributes
00149 public:
00150         static LPCTSTR  xmlnsSchema;
00151         static LPCTSTR  xmlnsInstance;
00152         static LPCTSTR  schemaName;
00153 
00154 // Operations
00155 public:
00156         CXMLAttribute*  Clone(CXMLElement* pParent = NULL);
00157         void                    ToString(CString& strXML);
00158         BOOL                    ParseString(LPCTSTR& strXML);
00159         BOOL                    Equals(CXMLAttribute* pXML) const;
00160 #ifdef _AFX
00161         void                    Serialize(CArchive& ar);
00162 #endif
00163 
00164 };
00165 
00166 #ifdef _AFX
00167 #define XMLVOID(x)      (void*&)(x)
00168 #else
00169 #define XMLVOID(x)      (x)
00170 #endif
00171 
00172 #include "XML.inl"

Generated on Thu Dec 15 10:39:54 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2