<!-- This comment will put IE 6, 7 and 8 in quirks mode --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>wsdlpull: /builddir/build/BUILD/wsdlpull-1.23/src/tools/schema.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="search/search.css" rel="stylesheet" type="text/css"/> <script type="text/javaScript" src="search/search.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body onload='searchBox.OnSelectItem(0);'> <!-- Generated by Doxygen 1.6.2-20100208 --> <script type="text/javascript"><!-- var searchBox = new SearchBox("searchBox", "search",false,'Search'); --></script> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> <li> <div id="MSearchBox" class="MSearchBoxInactive"> <img id="MSearchSelect" src="search/search.png" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" alt=""/> <input type="text" id="MSearchField" value="Search" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" onblur="searchBox.OnSearchFieldFocus(false)" onkeyup="searchBox.OnSearchFieldChange(event)"/> <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> </div> </li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_02f058d422e7266632662d1436e7c90d.html">src</a> » <a class="el" href="dir_9b08d5e3aa99b485234174b0ef99d02e.html">tools</a> </div> </div> <div class="contents"> <h1>schema.cpp</h1><a href="schema_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* </span> <a name="l00002"></a>00002 <span class="comment"> * wsdlpull - A C++ parser for WSDL (Web services description language)</span> <a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2005-2007 Vivek Krishna</span> <a name="l00004"></a>00004 <span class="comment"> *</span> <a name="l00005"></a>00005 <span class="comment"> * This library is free software; you can redistribute it and/or</span> <a name="l00006"></a>00006 <span class="comment"> * modify it under the terms of the GNU Library General Public</span> <a name="l00007"></a>00007 <span class="comment"> * License as published by the Free Software Foundation; either</span> <a name="l00008"></a>00008 <span class="comment"> * version 2 of the License, or (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment"> *</span> <a name="l00010"></a>00010 <span class="comment"> * This library is distributed in the hope that it will be useful,</span> <a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00013"></a>00013 <span class="comment"> * Library General Public License for more details.</span> <a name="l00014"></a>00014 <span class="comment"> *</span> <a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the GNU Library General Public</span> <a name="l00016"></a>00016 <span class="comment"> * License along with this library; if not, write to the Free</span> <a name="l00017"></a>00017 <span class="comment"> * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</span> <a name="l00018"></a>00018 <span class="comment"> */</span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="comment">//This file parses a sample schema document and validates/generates an instance</span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#include <iostream></span> <a name="l00023"></a>00023 <span class="preprocessor">#include <fstream></span> <a name="l00024"></a>00024 <span class="preprocessor">#include <string></span> <a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="XmlPullParser_8h.html">xmlpull/XmlPullParser.h</a>"</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="XmlPullParserException_8h.html">xmlpull/XmlPullParserException.h</a>"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="SchemaParser_8h.html">schemaparser/SchemaParser.h</a>"</span> <a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="SchemaValidator_8h.html">schemaparser/SchemaValidator.h</a>"</span> <a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="TypeContainer_8h.html">schemaparser/TypeContainer.h</a>"</span> <a name="l00030"></a>00030 <span class="preprocessor">#include "<a class="code" href="SchemaParserException_8h.html">schemaparser/SchemaParserException.h</a>"</span> <a name="l00031"></a>00031 <span class="keyword">using namespace </span>std; <a name="l00032"></a>00032 <span class="keyword">using namespace </span>Schema; <a name="l00033"></a>00033 <a name="l00034"></a>00034 <span class="keywordtype">void</span> <a name="l00035"></a><a class="code" href="schema_8cpp.html#ae8605e2b78cd4a81b6c6b5c30cb7366a">00035</a> <a class="code" href="schema_8cpp.html#ae8605e2b78cd4a81b6c6b5c30cb7366a">usage</a>(<span class="keywordtype">void</span>) <a name="l00036"></a>00036 { <a name="l00037"></a>00037 cout << <span class="stringliteral">"Usage: schema [options] <schema_file_name> [-i schema instance file name]"</span><<endl; <a name="l00038"></a>00038 cout << <span class="stringliteral">"Example:schema po.xsd -i po.xsi"</span><<endl; <a name="l00039"></a>00039 cout << <span class="stringliteral">"Example:schema first-building-blocks.xsd -i first.xml "</span><<endl; <a name="l00040"></a>00040 std::cout<<<span class="stringliteral">"Options"</span><<std::endl; <a name="l00041"></a>00041 std::cout<<<span class="stringliteral">" -x host[:port] Use HTTP proxy on given port"</span><<std::endl; <a name="l00042"></a>00042 std::cout<<<span class="stringliteral">" -U user[:password] Specify Proxy authentication"</span><<std::endl; <a name="l00043"></a>00043 std::cout<<<span class="stringliteral">" -g generate an xml instance for a top level element in the schema"</span><<std::endl; <a name="l00044"></a>00044 std::cout<<<span class="stringliteral">" -v Verbose mode"</span><<std::endl; <a name="l00045"></a>00045 cout << endl; <a name="l00046"></a>00046 } <a name="l00047"></a>00047 <a name="l00048"></a>00048 <span class="keywordtype">int</span> <a name="l00049"></a><a class="code" href="schema_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97">00049</a> <a class="code" href="schema_8cpp.html#a0ddf1224851353fc92bfbff6f499fa97">main</a> (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[]) <a name="l00050"></a>00050 { <a name="l00051"></a>00051 ifstream schfs; <a name="l00052"></a>00052 ifstream insfs; <a name="l00053"></a>00053 <a class="code" href="classSchema_1_1SchemaParser.html">SchemaParser</a> * sp=0; <a name="l00054"></a>00054 <span class="keywordtype">bool</span> brkloop =<span class="keyword">false</span>; <a name="l00055"></a>00055 <span class="keywordtype">bool</span> accept_password =<span class="keyword">false</span>; <a name="l00056"></a>00056 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> lvl = 0; <a name="l00057"></a>00057 <span class="keywordtype">bool</span> genInstance = <span class="keyword">false</span>,validate=<span class="keyword">false</span>; <a name="l00058"></a>00058 <span class="keywordtype">int</span> i =1; <a name="l00059"></a>00059 <span class="keywordflow">for</span> (;i<argc && !brkloop;){ <a name="l00060"></a>00060 <span class="keywordflow">switch</span>(argv[i][0]){ <a name="l00061"></a>00061 <span class="keywordflow">case</span> <span class="charliteral">'-'</span>:<span class="comment">//option</span> <a name="l00062"></a>00062 { <a name="l00063"></a>00063 std::string opt(argv[i]+1); <a name="l00064"></a>00064 <span class="keywordflow">if</span> (opt==<span class="stringliteral">"v"</span>){ <a name="l00065"></a>00065 lvl = 2; <a name="l00066"></a>00066 i++; <a name="l00067"></a>00067 } <a name="l00068"></a>00068 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (opt == <span class="stringliteral">"g"</span>){ <a name="l00069"></a>00069 <a name="l00070"></a>00070 genInstance = <span class="keyword">true</span>; <a name="l00071"></a>00071 i++; <a name="l00072"></a>00072 } <a name="l00073"></a>00073 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (opt == <span class="stringliteral">"v"</span>) { <a name="l00074"></a>00074 validate=<span class="keyword">true</span>; <a name="l00075"></a>00075 i++; <a name="l00076"></a>00076 } <a name="l00077"></a>00077 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (opt == <span class="stringliteral">"x"</span>){ <a name="l00078"></a>00078 opt = argv[i+1]; <a name="l00079"></a>00079 <span class="keywordtype">size_t</span> pos=opt.find(<span class="charliteral">':'</span>); <a name="l00080"></a>00080 <a class="code" href="namespaceXmlUtils.html#aac778a12893c4ea49ccccc2cbd1d4f87">XmlUtils::setProxyHost</a> (opt); <a name="l00081"></a>00081 <span class="keywordflow">if</span>(pos==std::string::npos){ <a name="l00082"></a>00082 <a name="l00083"></a>00083 <a class="code" href="namespaceXmlUtils.html#aac778a12893c4ea49ccccc2cbd1d4f87">XmlUtils::setProxyHost</a> (<a class="code" href="namespaceXmlUtils.html#a182783e6a4045ea122bd08e564b15c74">XmlUtils::getProxyHost</a> () + <span class="stringliteral">":80"</span>); <a name="l00084"></a>00084 } <a name="l00085"></a>00085 <a class="code" href="namespaceXmlUtils.html#a6229485431678d0122c6cc86d4c438c2">XmlUtils::setProxy</a> (<span class="keyword">true</span>); <a name="l00086"></a>00086 i+=2; <a name="l00087"></a>00087 } <a name="l00088"></a>00088 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (opt == <span class="stringliteral">"U"</span>){ <a name="l00089"></a>00089 opt = argv[i+1]; <a name="l00090"></a>00090 <span class="keywordtype">size_t</span> pos=opt.find(<span class="charliteral">':'</span>); <a name="l00091"></a>00091 <a class="code" href="namespaceXmlUtils.html#a7b37e31bd9868413ed7490e7e9bd46fd">XmlUtils::setProxyUser</a> (opt.substr(0,pos)); <a name="l00092"></a>00092 <span class="keywordflow">if</span>(pos!=std::string::npos) <a name="l00093"></a>00093 <a class="code" href="namespaceXmlUtils.html#a44575735ad84bbe13d2b36f19481e0a8">XmlUtils::setProxyPass</a> (opt.substr(pos+1)); <a name="l00094"></a>00094 <span class="keywordflow">else</span> <a name="l00095"></a>00095 accept_password = <span class="keyword">true</span>; <a name="l00096"></a>00096 i+=2; <a name="l00097"></a>00097 <a class="code" href="namespaceXmlUtils.html#a6229485431678d0122c6cc86d4c438c2">XmlUtils::setProxy</a> (<span class="keyword">true</span>); <a name="l00098"></a>00098 } <a name="l00099"></a>00099 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (opt ==<span class="stringliteral">"h"</span>){ <a name="l00100"></a>00100 <a class="code" href="schema_8cpp.html#ae8605e2b78cd4a81b6c6b5c30cb7366a">usage</a>(); <a name="l00101"></a>00101 <span class="keywordflow">return</span> 0; <a name="l00102"></a>00102 } <a name="l00103"></a>00103 <span class="keywordflow">else</span>{ <a name="l00104"></a>00104 std::cerr<<<span class="stringliteral">"Unknown option "</span><<argv[i]<<std::endl; <a name="l00105"></a>00105 <a class="code" href="schema_8cpp.html#ae8605e2b78cd4a81b6c6b5c30cb7366a">usage</a>(); <a name="l00106"></a>00106 <span class="keywordflow">return</span> 2; <a name="l00107"></a>00107 } <a name="l00108"></a>00108 <span class="keywordflow">break</span>; <a name="l00109"></a>00109 } <a name="l00110"></a>00110 <span class="keywordflow">default</span>: <a name="l00111"></a>00111 brkloop = <span class="keyword">true</span>; <a name="l00112"></a>00112 <span class="comment">//end of options</span> <a name="l00113"></a>00113 <span class="keywordflow">break</span>; <a name="l00114"></a>00114 } <a name="l00115"></a>00115 } <a name="l00116"></a>00116 <a name="l00117"></a>00117 <span class="keywordflow">if</span> (<a class="code" href="namespaceXmlUtils.html#a1725a578f019155cc8be8040488bfe54">XmlUtils::getProxy</a> () && accept_password){ <a name="l00118"></a>00118 <a name="l00119"></a>00119 <a class="code" href="namespaceXmlUtils.html#a44575735ad84bbe13d2b36f19481e0a8">XmlUtils::setProxyPass</a> (<a class="code" href="namespaceXmlUtils.html#a58f6a2b2eb995fc0fc00f12167bd55d9">XmlUtils::acceptSecretKey</a>(<span class="stringliteral">"Proxy Password"</span>)); <a name="l00120"></a>00120 std::cout<<endl; <a name="l00121"></a>00121 } <a name="l00122"></a>00122 <a name="l00123"></a>00123 <span class="keywordflow">if</span> (i < argc){ <a name="l00124"></a>00124 <a name="l00125"></a>00125 sp = <span class="keyword">new</span> <a class="code" href="classSchema_1_1SchemaParser.html">SchemaParser</a> (argv[i]); <a name="l00126"></a>00126 i++; <a name="l00127"></a>00127 } <a name="l00128"></a>00128 <span class="keywordflow">else</span> <a name="l00129"></a>00129 { <a name="l00130"></a>00130 <a class="code" href="schema_8cpp.html#ae8605e2b78cd4a81b6c6b5c30cb7366a">usage</a>(); <a name="l00131"></a>00131 <span class="keywordflow">return</span> 2; <a name="l00132"></a>00132 } <a name="l00133"></a>00133 <a name="l00134"></a>00134 <span class="keywordflow">try</span>{ <a name="l00135"></a>00135 <a name="l00136"></a>00136 <span class="keywordflow">if</span> (!sp) <a name="l00137"></a>00137 <span class="keywordflow">return</span> 1; <a name="l00138"></a>00138 sp-><a class="code" href="classSchema_1_1SchemaParser.html#a1531ba77bcf32659cd36e684d59b595e">setWarningLevel</a>(lvl); <a name="l00139"></a>00139 <span class="keywordflow">if</span> (sp-><a class="code" href="classSchema_1_1SchemaParser.html#a6f1dddf50bcb4dec24df5334971400c0">parseSchemaTag</a> ()) <a name="l00140"></a>00140 { <a name="l00141"></a>00141 <span class="keywordflow">if</span> (lvl >=2) <a name="l00142"></a>00142 cout << <span class="stringliteral">"Successfully parsed schema "</span> <<sp-><a class="code" href="classSchema_1_1SchemaParser.html#a64e1a1534e45266a717fd1c52cbb337c">getNamespace</a>() << endl; <a name="l00143"></a>00143 <span class="comment">//sp->print (cout);</span> <a name="l00144"></a>00144 } <a name="l00145"></a>00145 <span class="keywordflow">else</span> { <a name="l00146"></a>00146 <a name="l00147"></a>00147 std::cerr<<<span class="stringliteral">"Could not successfully parse "</span><<argv[i-1]<<std::endl; <a name="l00148"></a>00148 std::cerr<<<span class="stringliteral">"Run the command with -v option for more details"</span><<std::endl; <a name="l00149"></a>00149 <span class="keywordflow">return</span> 1; <a name="l00150"></a>00150 } <a name="l00151"></a>00151 <a name="l00152"></a>00152 <span class="keywordflow">if</span> (genInstance ) { <a name="l00153"></a>00153 <a name="l00154"></a>00154 std::string elemName; <a name="l00155"></a>00155 <a name="l00156"></a>00156 <a class="code" href="classSchema_1_1Element.html">Schema::Element</a> element; <a name="l00157"></a>00157 <span class="keyword">const</span> <a class="code" href="classSchema_1_1SchemaParser.html#aa0507b6296ea5ee7b6db52fc2f18fdfb">Schema::SchemaParser::ElementList</a> & el = sp-><a class="code" href="classSchema_1_1SchemaParser.html#ad10c155ac19fb7bb0e0317514ab6ce39">getElements</a>(); <a name="l00158"></a>00158 <span class="comment">//the global element for which to generate the instance</span> <a name="l00159"></a>00159 <span class="keywordflow">if</span> (i <=argc && argv[i]){ <a name="l00160"></a>00160 <span class="keywordtype">bool</span> found = <span class="keyword">false</span>; <a name="l00161"></a>00161 elemName = std::string(argv[i]); <a name="l00162"></a>00162 <a name="l00163"></a>00163 <span class="keywordflow">for</span> ( Schema::SchemaParser::ElementList::const_iterator eli= el.begin(); <a name="l00164"></a>00164 eli!=el.end() && !found; <a name="l00165"></a>00165 eli++) <a name="l00166"></a>00166 { <a name="l00167"></a>00167 <span class="keywordflow">if</span> (eli->getName() == elemName){ <a name="l00168"></a>00168 found = <span class="keyword">true</span>; <a name="l00169"></a>00169 element = *eli; <a name="l00170"></a>00170 <a name="l00171"></a>00171 <a name="l00172"></a>00172 } <a name="l00173"></a>00173 } <a name="l00174"></a>00174 <span class="keywordflow">if</span> (!found) { <a name="l00175"></a>00175 <a name="l00176"></a>00176 std::cerr<<<span class="stringliteral">"element '"</span><<elemName<<<span class="stringliteral">"' not found in the schema.Try 'schema -g "</span><<argv[2]<<<span class="stringliteral">"' to see the list of elements in the schema"</span><<std::endl; <a name="l00177"></a>00177 <span class="keywordflow">return</span> 1; <a name="l00178"></a>00178 } <a name="l00179"></a>00179 } <a name="l00180"></a>00180 <span class="keywordflow">else</span> { <a name="l00181"></a>00181 <span class="keywordtype">int</span> n = 0; <a name="l00182"></a>00182 <span class="keywordflow">for</span> ( Schema::SchemaParser::ElementList::const_iterator eli= el.begin(); <a name="l00183"></a>00183 eli!=el.end(); <a name="l00184"></a>00184 eli++,n++) <a name="l00185"></a>00185 { <a name="l00186"></a>00186 <span class="keywordflow">if</span> (n !=0) <a name="l00187"></a>00187 std::cout<<n<<<span class="stringliteral">"."</span><<eli-><a class="code" href="classSchema_1_1Element.html#a7d60f62e4e0b17c1fb5d6729f813b0f7">getName</a>()<<std::endl; <a name="l00188"></a>00188 } <a name="l00189"></a>00189 <span class="keywordflow">if</span> (n<= 1){ <a name="l00190"></a>00190 std::cout<<<span class="stringliteral">"No top level elements to generate instance.. exiting"</span><<std::endl; <a name="l00191"></a>00191 <span class="keywordflow">return</span> 0; <a name="l00192"></a>00192 } <a name="l00193"></a>00193 std::cout<<<span class="stringliteral">"Which element should I generate an instance for [1.."</span><<n-1<<<span class="stringliteral">"]?"</span>; <a name="l00194"></a>00194 std::cin>>n; <a name="l00195"></a>00195 <a name="l00196"></a>00196 n++; <span class="comment">// locate the element in the list (first element bydefault is <schema> so skip it</span> <a name="l00197"></a>00197 <span class="keywordflow">for</span> ( Schema::SchemaParser::ElementList::const_iterator eli1= el.begin(); <a name="l00198"></a>00198 eli1!=el.end() && n ; <a name="l00199"></a>00199 eli1++,n--) element = *eli1; <a name="l00200"></a>00200 } <a name="l00201"></a>00201 <a name="l00202"></a>00202 <a class="code" href="classSchema_1_1SchemaValidator.html">SchemaValidator</a> * sv = <span class="keyword">new</span> <a class="code" href="classSchema_1_1SchemaValidator.html">SchemaValidator</a>(sp); <a name="l00203"></a>00203 <span class="keywordflow">return</span> sv-><a class="code" href="classSchema_1_1SchemaValidator.html#a26d9d6cd0c4d9065b769b4cc85da7ede">instance</a>(element.<a class="code" href="classSchema_1_1Element.html#a7d60f62e4e0b17c1fb5d6729f813b0f7">getName</a>(),(<a class="code" href="namespaceSchema.html#acbe1398d097409fb3c2f948fa876711d">Schema::Type</a>)element.<a class="code" href="classSchema_1_1Element.html#a5a3acbc55a5739e80b1f2855b62e94f9">getType</a>()); <a name="l00204"></a>00204 } <a name="l00205"></a>00205 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (i <argc ) <a name="l00206"></a>00206 { <a name="l00207"></a>00207 std::string xmlDoc; <a name="l00208"></a>00208 <a class="code" href="namespaceXmlUtils.html#a49cb0c0850b4a22b1fe0d5efd7553b01">XmlUtils::fetchUri</a>(argv[i+1],xmlDoc); <a name="l00209"></a>00209 insfs.open (xmlDoc.c_str()); <span class="comment">//open the schema instance file</span> <a name="l00210"></a>00210 <span class="keywordflow">if</span> (insfs.fail ()) <a name="l00211"></a>00211 { <a name="l00212"></a>00212 cerr << <span class="stringliteral">"An Error occrred while opening "</span> << argv[i+1] << endl; <a name="l00213"></a>00213 <span class="keywordflow">return</span> 1; <a name="l00214"></a>00214 } <a name="l00215"></a>00215 i++; <a name="l00216"></a>00216 <a class="code" href="classXmlPullParser.html">XmlPullParser</a> * xpp = <span class="keyword">new</span> <a class="code" href="classXmlPullParser.html">XmlPullParser</a> (insfs); <a name="l00217"></a>00217 xpp-><a class="code" href="classXmlPullParser.html#afd20dea242da6a493321050f24230b54">setFeature</a> (<a class="code" href="XmlPullParser_8h.html#ada32f6169a51300722b9b7dd38fa4032">FEATURE_PROCESS_NAMESPACES</a>, <span class="keyword">true</span>); <a name="l00218"></a>00218 xpp-><a class="code" href="classXmlPullParser.html#a7b14708ef982d48b41009380146f523a">require</a> (<a class="code" href="classXmlPullParser.html#ad5db81dea47b59d1aab8e24ca78baf45a9a40df5e7fdb1a29f88425ef3eb8c1fa">XmlPullParser::START_DOCUMENT</a>, <span class="stringliteral">""</span>, <span class="stringliteral">""</span>); <a name="l00219"></a>00219 <a class="code" href="classSchema_1_1SchemaValidator.html">SchemaValidator</a> * sv= <span class="keyword">new</span> <a class="code" href="classSchema_1_1SchemaValidator.html">SchemaValidator</a>(sp); <a name="l00220"></a>00220 <span class="keywordflow">while</span> (xpp-><a class="code" href="classXmlPullParser.html#a707466b0d0f10ead2266a750ad84278f">getEventType</a> () != xpp-><a class="code" href="classXmlPullParser.html#ad5db81dea47b59d1aab8e24ca78baf45a7857338db3efb0bcd468b06fe346076f">END_DOCUMENT</a>) <a name="l00221"></a>00221 { <a name="l00222"></a>00222 xpp-><a class="code" href="classXmlPullParser.html#a12e19fdc259b06078316b861cfaac791">nextTag</a> (); <a name="l00223"></a>00223 <span class="keywordflow">if</span> (xpp-><a class="code" href="classXmlPullParser.html#a707466b0d0f10ead2266a750ad84278f">getEventType</a> () == xpp-><a class="code" href="classXmlPullParser.html#ad5db81dea47b59d1aab8e24ca78baf45a7857338db3efb0bcd468b06fe346076f">END_DOCUMENT</a>) <a name="l00224"></a>00224 <span class="keywordflow">break</span>; <a name="l00225"></a>00225 <a class="code" href="classQname.html">Qname</a> elemName (xpp-><a class="code" href="classXmlPullParser.html#a861f8c8b5b08ab96fb7c33756f7cc94d">getName</a> ()); <a name="l00226"></a>00226 elemName.setNamespace(xpp-><a class="code" href="classXmlPullParser.html#ab64f42eff37c0c049024c8267f0732e8">getNamespace</a>()); <a name="l00227"></a>00227 <span class="keyword">const</span> <a class="code" href="classSchema_1_1Element.html">Element</a> * e = sp-><a class="code" href="classSchema_1_1SchemaParser.html#aa11d8f9bf85870304ab35e387fd486b1">getElement</a> (elemName); <a name="l00228"></a>00228 <span class="keywordflow">if</span>(e){ <a name="l00229"></a>00229 <span class="keywordtype">int</span> typeId = e-><a class="code" href="classSchema_1_1Element.html#a5a3acbc55a5739e80b1f2855b62e94f9">getType</a> () ; <a name="l00230"></a>00230 <span class="comment">//for each element in the instance doc we call the</span> <a name="l00231"></a>00231 <span class="comment">//validator with the parser instance of the instance file</span> <a name="l00232"></a>00232 <span class="comment">// and the element's type identifier</span> <a name="l00233"></a>00233 <a class="code" href="classSchema_1_1TypeContainer.html">TypeContainer</a> * t = sv-><a class="code" href="classSchema_1_1SchemaValidator.html#a408b10148dfbcc921dabf7893e11ae36">validate</a> (xpp, typeId); <a name="l00234"></a>00234 <a name="l00235"></a>00235 cout << <span class="stringliteral">"{"</span><<elemName.getNamespace () << <span class="stringliteral">"}"</span> << elemName. <a name="l00236"></a>00236 getLocalName ()<<std::endl; <a name="l00237"></a>00237 <span class="comment">//once validated the element instance is stored</span> <a name="l00238"></a>00238 <span class="comment">//in the type container from which values can be</span> <a name="l00239"></a>00239 <span class="comment">//obtained or just printed</span> <a name="l00240"></a>00240 t-><a class="code" href="classSchema_1_1TypeContainer.html#a365b251684cf3602ff24219e91c9b1bf">print</a>(cout); <a name="l00241"></a>00241 std::cout<<std::endl; <a name="l00242"></a>00242 <span class="keyword">delete</span> t; <a name="l00243"></a>00243 } <a name="l00244"></a>00244 <span class="keywordflow">else</span>{ <a name="l00245"></a>00245 <a name="l00246"></a>00246 <a class="code" href="classQname.html">Qname</a> typ(xpp-><a class="code" href="classXmlPullParser.html#abcadde67a15be58a4eac0b4592b2e645">getAttributeValue</a>(<a class="code" href="namespaceSchema.html#ad487ba72816770eabe894f1c6c43706b">Schema::SchemaInstaceUri</a>, <span class="stringliteral">"type"</span>)); <a name="l00247"></a>00247 typ.setNamespace(xpp-><a class="code" href="classXmlPullParser.html#ab64f42eff37c0c049024c8267f0732e8">getNamespace</a>(typ.getPrefix())); <a name="l00248"></a>00248 <a name="l00249"></a>00249 <span class="keywordflow">if</span> (typ.getNamespace() == sp-><a class="code" href="classSchema_1_1SchemaParser.html#a64e1a1534e45266a717fd1c52cbb337c">getNamespace</a>() || <a name="l00250"></a>00250 typ.getNamespace().empty()) { <a name="l00251"></a>00251 <span class="keywordtype">int</span> typeId = sp-><a class="code" href="classSchema_1_1SchemaParser.html#ad8f407de76f38f1fa24c844faf9ca611">getTypeId</a>(typ); <a name="l00252"></a>00252 <a name="l00253"></a>00253 <a class="code" href="classSchema_1_1TypeContainer.html">TypeContainer</a> * t = sv-><a class="code" href="classSchema_1_1SchemaValidator.html#a408b10148dfbcc921dabf7893e11ae36">validate</a> (xpp, typeId); <a name="l00254"></a>00254 <a name="l00255"></a>00255 cout << <span class="stringliteral">"{"</span><<elemName.getNamespace () << <span class="stringliteral">"}"</span> << elemName. <a name="l00256"></a>00256 getLocalName ()<<std::endl; <a name="l00257"></a>00257 <span class="comment">//once validated the element instance is stored</span> <a name="l00258"></a>00258 <span class="comment">//in the type container from which values can be</span> <a name="l00259"></a>00259 <span class="comment">//obtained or just printed</span> <a name="l00260"></a>00260 t-><a class="code" href="classSchema_1_1TypeContainer.html#a365b251684cf3602ff24219e91c9b1bf">print</a>(cout); <a name="l00261"></a>00261 std::cout<<std::endl; <a name="l00262"></a>00262 <span class="keyword">delete</span> t; <a name="l00263"></a>00263 <a name="l00264"></a>00264 } <a name="l00265"></a>00265 <span class="keywordflow">else</span> { <a name="l00266"></a>00266 std::cerr<<<span class="stringliteral">"Unknown element {"</span><<elemName.getNamespace()<<<span class="stringliteral">"}"</span><<elemName.getLocalName()<<std::endl; <a name="l00267"></a>00267 } <a name="l00268"></a>00268 } <a name="l00269"></a>00269 <a name="l00270"></a>00270 } <a name="l00271"></a>00271 } <a name="l00272"></a>00272 <span class="keyword">delete</span> sp; <a name="l00273"></a>00273 <span class="keywordflow">return</span> 0; <a name="l00274"></a>00274 } <a name="l00275"></a>00275 <a name="l00276"></a>00276 <a name="l00277"></a>00277 <span class="keywordflow">catch</span> (<a class="code" href="classSchema_1_1SchemaParserException.html">SchemaParserException</a> spe) <a name="l00278"></a>00278 { <a name="l00279"></a>00279 cerr<<<span class="stringliteral">"An Exception occurred ...@"</span><<spe.<a class="code" href="classSchema_1_1SchemaParserException.html#a962a143b653375a0149bfcd2e373d7e7">line</a> <a name="l00280"></a>00280 <<<span class="stringliteral">":"</span><<spe.<a class="code" href="classSchema_1_1SchemaParserException.html#acba399209c103bd6fda937a6e0e4dff8">col</a><<endl; <a name="l00281"></a>00281 <a name="l00282"></a>00282 cerr<<spe.<a class="code" href="classSchema_1_1SchemaParserException.html#abad96177c969c678702645a9a792fe34">description</a><<endl; <a name="l00283"></a>00283 } <a name="l00284"></a>00284 <span class="keywordflow">catch</span> (<a class="code" href="classXmlPullParserException.html">XmlPullParserException</a> xpe) <a name="l00285"></a>00285 { <a name="l00286"></a>00286 cerr<<<span class="stringliteral">"An Exception occurred ...@"</span><<xpe.<a class="code" href="classXmlPullParserException.html#ab91ff9c9c31ddd56f13c7ebe1176dad4">line</a> <a name="l00287"></a>00287 <<<span class="stringliteral">":"</span><<xpe.<a class="code" href="classXmlPullParserException.html#ad31a87cfe1fb235c47ce203c868f9063">col</a><<endl; <a name="l00288"></a>00288 <a name="l00289"></a>00289 cerr<<xpe.<a class="code" href="classXmlPullParserException.html#a5e678f53a8e21e41646f669897bf901c">description</a><<endl; <a name="l00290"></a>00290 } <a name="l00291"></a>00291 <span class="keywordflow">return</span> 1; <a name="l00292"></a>00292 } </pre></div></div> <!--- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Defines</a></div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> <hr class="footer"/><address style="text-align: right;"><small>Generated by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.2-20100208 </small></address> </body> </html>