Planeshift
psxmlparser.h
Go to the documentation of this file.
1 /*
2  * xmlparser.h
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 #ifndef PS_XML_PARSER_H
20 #define PS_XML_PARSER_H
21 
22 #include "util/psstring.h"
23 #include <csutil/xmltiny.h>
24 #include <csutil/objreg.h>
25 #include <iutil/vfs.h>
26 #include "util/log.h"
27 
35 csPtr<iDocument> ParseFile(iObjectRegistry* object_reg, const csString & name);
36 
40 csPtr<iDocument> ParseString(const csString & str, bool notify = true);
41 
45 csPtr<iDocumentNode> ParseStringGetNode(const csString & str, const csString & topNodeName, bool notify = true);
46 
50 csString EscpXML(const char * str);
51 
57 csString GetNodeXML(iDocumentNode* node, bool childrenOnly = false);
58 
66 void CopyXMLNode(iDocumentNode* source, iDocumentNode* target, int mode);
67 
68 class psXMLTag;
69 
70 class psXMLString : public psString
71 {
72 public:
73  psXMLString() { };
74  psXMLString(const char *str) : psString(str) { };
75  int FindTag( const char* tagName, int start=0 );
76  size_t FindNextTag( size_t start );
77  size_t GetTag( int start, psXMLTag& tag );
78  size_t GetTagSection( int start, const char* tagName, psXMLString& tagSection);
79 
89  size_t GetWithinTagSection( int start, const char* tagName, psXMLString& tagSection);
90 
100  size_t GetWithinTagSection( int start, const char* tagName, csString& value);
101 
102  size_t GetWithinTagSection( int start, const char* tagName, int& value);
103  size_t GetWithinTagSection( int start, const char* tagName, double& value);
104 
105  void operator=(const char* str)
106  {
107  csString::operator=(str);
108  }
109 protected:
110  size_t FindMatchingEndTag(int iStart, const char *tagName);
111 };
112 
113 
114 //-------------------------------------------------------------------
115 //
116 class psXMLTag : public psString
117 {
118 public:
119  psXMLTag() {}
120  psXMLTag(psXMLString& str, int where)
121  {
122  if (where<0)
123  Replace("");
124  else
125  str.GetTag( where, *this );
126  }
127 
128  void GetTagParm(const char* param, csString& value);
129  void GetTagParm(const char* param, int& value);
130  void GetTagParm(const char* param, double& value);
131  void GetTagParm(const char* param, float& value);
132 
133  void GetTagName(psString& name);
134 };
135 
138 #endif
csPtr< iDocument > ParseFile(iObjectRegistry *object_reg, const csString &name)
Loads and parses a XML file, then returns its parsed XML document.
void operator=(const char *str)
Definition: psxmlparser.h:105
size_t FindNextTag(size_t start)
size_t GetTagSection(int start, const char *tagName, psXMLString &tagSection)
int FindTag(const char *tagName, int start=0)
size_t GetWithinTagSection(int start, const char *tagName, psXMLString &tagSection)
GetWithinTagSection return the psXMLString section text of a tag.
csPtr< iDocumentNode > ParseStringGetNode(const csString &str, const csString &topNodeName, bool notify=true)
Parses a XML string, then returns the top node with name &#39;topNodeName&#39;.
size_t FindMatchingEndTag(int iStart, const char *tagName)
psXMLTag(psXMLString &str, int where)
Definition: psxmlparser.h:120
csString GetNodeXML(iDocumentNode *node, bool childrenOnly=false)
Generates XML representing given node.
csPtr< iDocument > ParseString(const csString &str, bool notify=true)
Parses a XML string, then returns the parsed document.
size_t GetTag(int start, psXMLTag &tag)
csString EscpXML(const char *str)
Escapes special XML characters in &#39;str&#39;.
psXMLString(const char *str)
Definition: psxmlparser.h:74
void CopyXMLNode(iDocumentNode *source, iDocumentNode *target, int mode)
Copies/merges children and attributes of &#39;source&#39; to &#39;target&#39;.