Planeshift

psxmlparser.h

Go to the documentation of this file.
00001 /*
00002  * xmlparser.h
00003  *
00004  * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 #ifndef PS_XML_PARSER_H
00020 #define PS_XML_PARSER_H
00021 
00022 #include "util/psstring.h"
00023 #include <csutil/xmltiny.h>
00024 #include <csutil/objreg.h>
00025 #include <iutil/vfs.h>
00026 #include "util/log.h"
00027 
00035 csPtr<iDocument> ParseFile(iObjectRegistry* object_reg, const csString & name);
00036 
00040 csPtr<iDocument> ParseString(const csString & str, bool notify = true);
00041 
00045 csPtr<iDocumentNode> ParseStringGetNode(const csString & str, const csString & topNodeName, bool notify = true);
00046 
00050 csString EscpXML(const char * str);
00051 
00057 csString GetNodeXML(iDocumentNode* node, bool childrenOnly = false);
00058 
00066 void CopyXMLNode(iDocumentNode* source, iDocumentNode* target, int mode);
00067 
00068 class psXMLTag;
00069 
00070 class psXMLString : public psString
00071 {
00072 public:
00073     psXMLString() { };
00074     psXMLString(const char *str) : psString(str) { };
00075     int FindTag( const char* tagName, int start=0 );
00076     size_t FindNextTag( size_t start );
00077     size_t GetTag( int start, psXMLTag& tag );
00078     size_t GetTagSection( int start, const char* tagName, psXMLString& tagSection);
00079     
00089     size_t GetWithinTagSection( int start, const char* tagName, psXMLString& tagSection);
00090 
00100     size_t GetWithinTagSection( int start, const char* tagName, csString& value);
00101     
00102     size_t GetWithinTagSection( int start, const char* tagName, int& value);
00103     size_t GetWithinTagSection( int start, const char* tagName, double& value);
00104 
00105     void operator=(const char* str)
00106     {
00107         csString::operator=(str);
00108     }
00109 protected:
00110     size_t FindMatchingEndTag(int iStart, const char *tagName);
00111 };
00112 
00113 
00114 //-------------------------------------------------------------------
00115 //
00116 class psXMLTag : public psString
00117 {
00118 public: 
00119     psXMLTag() {}
00120     psXMLTag(psXMLString& str, int where)
00121     {
00122         if (where<0)
00123             Replace("");
00124         else
00125             str.GetTag( where, *this );
00126     }
00127 
00128     void GetTagParm(const char* param, csString& value);
00129     void GetTagParm(const char* param, int& value);
00130     void GetTagParm(const char* param, double& value);
00131     void GetTagParm(const char* param, float& value);
00132 
00133     void GetTagName(psString& name);
00134 }; 
00135 
00138 #endif