_tests/fsXmlDoc/main.cpp

00001 
00002 //---------------------------------------------------------------------------
00003 #include <fs/ut/fsXmlDoc.h>
00004 
00005 #include <cstdio> // printf
00006 #include <cassert>
00007 //---------------------------------------------------------------------------
00008 int main()
00009 {
00010     fs::ut::XmlDoc_t Doc("test.xml");
00011     assert(Doc.IsValid() && "Couldn't load the XML document!"); 
00012         
00013     const char *pszFoldNm = 0;
00014     if(Doc.Query("folder/@name", pszFoldNm))
00015         ::printf("name of the first folder : '%s'\n", pszFoldNm);
00016          
00017     int nFiles = 0;
00018     if(Doc.Query("folder/#file", nFiles))
00019         ::printf("number of files in the first folder : %d\n", nFiles);
00020         
00021     const char *pszFile1Nm = 0;
00022     if(Doc.Query("folder/file/@name", pszFile1Nm))
00023         ::printf("name of the first file : '%s'\n", pszFile1Nm);
00024         
00025     const char *pszFile2Ct = 0;
00026     if(Doc.Query("folder/file^1", pszFile2Ct))
00027         ::printf("content of the second file : '%s'\n", pszFile2Ct);
00028         
00029     int nFile2Sz = 0;
00030     if(Doc.Query("folder/file^1/@size", nFile2Sz))
00031         ::printf("size of the second file : %d\n", nFile2Sz);
00032     
00033     int nFile2Tags = 0;
00034     if(Doc.Query("folder/file^1/#tag", nFile2Tags))
00035         ::printf("number of tags for the second file : %d\n", nFile2Tags);
00036 
00037     return 0;
00038 }
00039 //---------------------------------------------------------------------------
00040 // name of the first folder : 'myfolder'
00041 // number of files in the first folder : 2
00042 // name of the first file : 'myfile1'
00043 // content of the second file : 'some file2 data'
00044 // size of the second file : 555
00045 // number of tags for the second file : 2
00046 //---------------------------------------------------------------------------
00047 //<?xml version="1.0" encoding="UTF-8"?>
00048 //    <folder name="myfolder">
00049 //        <file name="myfile1"/>
00050 //        <file name="myfile2" size="555">
00051 //            some file2 data
00052 //            <tag />
00053 //            <tag />
00054 //        </file>
00055 //</folder>
00056 //---------------------------------------------------------------------------

FipS' Code (Thu Feb 15 22:43:35 2007) - (c) Filip STOKLAS (FipS) - [ www ] [ Guest Book ]