00001 00002 // 00003 // XML storage C++ classes version 1.2 00004 // 00005 // Copyright (c) 2005 Martin Fuchs <martin-fuchs@gmx.net> 00006 // 00007 00008 /// \file xmltest.cpp 00009 /// XMLStorage test program 00010 00011 00012 /* 00013 00014 All rights reserved. 00015 00016 Redistribution and use in source and binary forms, with or without 00017 modification, are permitted provided that the following conditions are met: 00018 00019 * Redistributions of source code must retain the above copyright 00020 notice, this list of conditions and the following disclaimer. 00021 * Redistributions in binary form must reproduce the above copyright 00022 notice, this list of conditions and the following disclaimer in 00023 the documentation and/or other materials provided with the 00024 distribution. 00025 00026 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00027 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00029 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00030 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00031 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00032 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00033 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00034 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00035 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00036 POSSIBILITY OF SUCH DAMAGE. 00037 00038 */ 00039 00040 //#define XS_USE_EXPAT 00041 00042 //#define XML_STATIC 00043 #include <xmlstorage.h> 00044 using namespace XMLStorage; 00045 00046 #include <iostream> 00047 using namespace std; 00048 00049 00050 bool xml_test() //@@ 00051 { 00052 XMLDoc doc; 00053 bool ret; 00054 00055 //ret = doc.read_file("poem.xml"); 00056 //ret = doc.read_file("machines.xml"); 00057 ret = doc.read_file("packets.xml"); 00058 00059 if (!ret) { 00060 std::cerr << doc._errors.str() << std::endl; 00061 return false; 00062 } 00063 00064 doc.write_file("out_plain.xml", FORMAT_PLAIN); 00065 doc.write_file("out_smart.xml", FORMAT_SMART); 00066 doc.write_file("out_original.xml", FORMAT_ORIGINAL); 00067 doc.write_file("out_pretty.xml", FORMAT_PRETTY); 00068 00069 XMLPos pos(&doc); 00070 00071 // if (pos.go("get_packets/packet")) 00072 // if (pos.go("/get_packets/packet")) 00073 // if (pos.go("/get_packets/packet[5]")) 00074 if (pos.go("/get_packets/packet[@db_id=\"7628\"]")) 00075 // if (pos.go("get_machines/machine[@wsid=\"client2\"]")) 00076 { 00077 cout << "db_id = " << XMLInt(pos, "db_id") << endl; 00078 cout << "name = " << XMLString(pos, "name").c_str() << endl; 00079 cout << "short_name = " << XMLString(pos, "short_name").c_str() << endl; 00080 00081 pos.back(); 00082 } 00083 00084 // test of special characters 00085 XMLDoc d; 00086 XMLPos p(&d); 00087 00088 p.create("n1"); 00089 char s[6] = "12345"; 00090 s[2] = 0x15; 00091 p->set_content(s); 00092 p.back(); 00093 00094 d.write_file("testfile.xml"); 00095 00096 return true; 00097 } 00098 00099 00100 int main() 00101 { 00102 return xml_test()? EXIT_SUCCESS: EXIT_FAILURE; 00103 }