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

XmlSerializer.h

Go to the documentation of this file.
00001 /* Copyright (c) 2005,2007 Vivek Krishna
00002  *  Based on kxml2 by Stefan Haustein, Oberhausen, Rhld., Germany
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy
00004  * of this software and associated documentation files (the "Software"), to deal
00005  * in the Software without restriction, including without limitation the rights
00006  * to use, copy, modify, merge, publish, distribute, sublicense, and/or
00007  * sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The  above copyright notice and this permission notice shall be included in
00011  * all copies or substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00014  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00015  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00016  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00017  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00018  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00019  * IN THE SOFTWARE. */
00020  
00021 #ifndef _XMLSERIALIZERH
00022 #define _XMLSERIALIZERH
00023 
00024 #include <map>
00025 #include <iostream>
00026 #include <sstream>
00027 #include <string>
00028 #include <vector>
00029 
00030 
00031 
00032 class XmlSerializer {
00033  
00034  public:
00035   XmlSerializer(std::ostream &os, std::string encoding="utf");
00036   XmlSerializer(std::string encoding="utf");//standard output
00037   ~XmlSerializer(void);
00038   void docdecl(std::string dd);
00039   void startDocument(std::string encoding,
00040                      bool standalone);
00041   XmlSerializer& startTag(std::string nsp, std::string name);
00042   XmlSerializer& attribute(std::string nsp,
00043                            std::string name,
00044                            std::string value);
00045   XmlSerializer& endTag(std::string nsp, std::string name);
00046   void endDocument();
00047   void entityRef(std::string name);
00048   bool getFeature(std::string name);
00049   std::string getPrefix(std::string nsp, bool create);
00050   std::string getPrefix(std::string nsp,
00051                         bool includeDefault,
00052                         bool create);
00053 
00054   void ignorableWhitespace(std::string s);
00055   void setFeature(std::string name, bool value);
00056   void setPrefix(std::string prefix, std::string nsp);
00057 
00058   void flush();
00059   std::string getNamespace();
00060   std::string getName();
00061   int getDepth();
00062   XmlSerializer& text(std::string txt);
00063   XmlSerializer& text(std::string txt, int start, int len);
00064   void cdsect(std::string data);
00065   void comment(std::string comment);
00066   void processingInstruction(std::string pi);
00067 
00068   
00069  private:
00070   std::ostream& writer;
00071   bool pending;
00072   int auto_;
00073   int depth;
00074   std::string encoding;
00075   std::vector<std::string> elementStack,nspStack;
00076   //nsp/prefix/name
00077   std::vector<int> nspCounts;
00078   //prefix/nsp; both empty are ""
00079   std::vector<bool> indent;
00080   bool unicode;
00081   void check(bool close);
00082   void writeEscaped(std::string s, int quot);
00083   void exception (std::string desc);
00084   void init();
00085 };
00086 
00087 #endif

Generated on Sun Oct 16 10:11:52 2005 for wsdlpull by  doxygen 1.3.9.1