This commit is contained in:
King_DuckZ 2020-02-17 22:19:57 +01:00
parent 1613a190f0
commit b93578226a
2489 changed files with 122200 additions and 118330 deletions

View file

@ -5,23 +5,34 @@
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<a style="float:right;" href="http://sourceforge.net/projects/xqilla"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=152021&amp;type=2" border="0" alt="SourceForge.net Logo" /></a>
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="examples.html">Examples</a></div>
<h1>dom-resolver.cpp</h1>This example shows an example of running multiple queries, using a DOMXPathNSResolver to resolve namespaces.<p>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;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><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<h1>dom-resolver.cpp</h1><p>This example shows an example of running multiple queries, using a DOMXPathNSResolver to resolve namespaces.</p>
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * Copyright (c) 2001-2008</span>
<span class="comment"> * DecisionSoft Limited. All rights reserved.</span>
<span class="comment"> * Copyright (c) 2004-2008</span>
<span class="comment"> * Oracle. All rights reserved.</span>
<span class="comment"> *</span>
<span class="comment"> * Licensed under the Apache License, Version 2.0 (the "License");</span>
<span class="comment"> * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="comment"> * you may not use this file except in compliance with the License.</span>
<span class="comment"> * You may obtain a copy of the License at</span>
<span class="comment"> *</span>
<span class="comment"> * http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="comment"> *</span>
<span class="comment"> * Unless required by applicable law or agreed to in writing, software</span>
<span class="comment"> * distributed under the License is distributed on an "AS IS" BASIS,</span>
<span class="comment"> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="comment"> * See the License for the specific language governing permissions and</span>
<span class="comment"> * limitations under the License.</span>
@ -37,12 +48,12 @@
<span class="preprocessor">#include &lt;<a class="code" href="xqilla-dom3_8hpp.html">xqilla/xqilla-dom3.hpp</a>&gt;</span>
XERCES_CPP_NAMESPACE_USE;
<span class="keyword">using</span> <span class="keyword">namespace </span>std;
<span class="keyword">using namespace </span>std;
<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
{
<span class="keywordflow">if</span>(argc != 2) {
cerr &lt;&lt; <span class="stringliteral">"Data file not specified."</span> &lt;&lt; endl;
cerr &lt;&lt; <span class="stringliteral">&quot;Data file not specified.&quot;</span> &lt;&lt; endl;
<span class="keywordflow">return</span> 1;
}
@ -54,11 +65,11 @@ XERCES_CPP_NAMESPACE_USE;
<span class="comment">// xerces-c as well</span>
<span class="keywordflow">try</span> {
<a name="a6"></a><a class="code" href="classXQillaPlatformUtils.html#e0">XQillaPlatformUtils::initialize</a>();
<a name="a0"></a><a class="code" href="classXQillaPlatformUtils.html#ac769d09556ec43ecb94d1822783ba0b8" title="Perform XQilla initialization.">XQillaPlatformUtils::initialize</a>();
} <span class="keywordflow">catch</span> (<span class="keyword">const</span> XMLException&amp; eXerces) {
cerr &lt;&lt; <span class="stringliteral">"Error during Xerces-C initialisation.\n"</span>
&lt;&lt; <span class="stringliteral">"Xerces exception message: "</span>
cerr &lt;&lt; <span class="stringliteral">&quot;Error during Xerces-C initialisation.\n&quot;</span>
&lt;&lt; <span class="stringliteral">&quot;Xerces exception message: &quot;</span>
&lt;&lt; UTF8(eXerces.getMessage()) &lt;&lt; endl;
<span class="keywordflow">return</span> 1;
}
@ -69,12 +80,12 @@ XERCES_CPP_NAMESPACE_USE;
<span class="comment">// implementation that overrides the standard DOMDocument, the standard </span>
<span class="comment">// DOMWriter and the standard DOMBuilder</span>
DOMImplementation* xqillaImplementation =
DOMImplementationRegistry::getDOMImplementation(X(<span class="stringliteral">"XPath2 3.0"</span>));
DOMImplementationRegistry::getDOMImplementation(X(<span class="stringliteral">&quot;XPath2 3.0&quot;</span>));
<span class="comment">// 3. Obtain a parser and set 'do namespaces', 'use schema' and 'validate' to </span>
<span class="comment">// 3. Obtain a parser and set &apos;do namespaces&apos;, &apos;use schema&apos; and &apos;validate&apos; to </span>
<span class="comment">// true.</span>
<span class="comment">// Create a DOMLSParser object</span>
<a name="_a7"></a><a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMLSParser&gt;</a> parser(xqillaImplementation-&gt;createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0));
<a name="_a1"></a><a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMLSParser&gt;</a> parser(xqillaImplementation-&gt;createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0));
parser-&gt;getDomConfig()-&gt;setParameter(XMLUni::fgDOMNamespaces, <span class="keyword">true</span>);
parser-&gt;getDomConfig()-&gt;setParameter(XMLUni::fgXercesSchema, <span class="keyword">true</span>);
parser-&gt;getDomConfig()-&gt;setParameter(XMLUni::fgDOMValidateIfSchema, <span class="keyword">true</span>);
@ -83,7 +94,7 @@ XERCES_CPP_NAMESPACE_USE;
<span class="comment"></span>
DOMDocument *document = parser-&gt;parseURI(argv[1]);
<span class="keywordflow">if</span>(document == 0) {
cerr &lt;&lt; <span class="stringliteral">"Document not found: "</span> &lt;&lt; argv[1] &lt;&lt; endl;
cerr &lt;&lt; <span class="stringliteral">&quot;Document not found: &quot;</span> &lt;&lt; argv[1] &lt;&lt; endl;
<span class="keywordflow">return</span> 1;
}
@ -94,13 +105,13 @@ XERCES_CPP_NAMESPACE_USE;
<span class="comment">// 1. Create a Namespace Resolver. This holds a map of namespace prefixes </span>
<span class="comment">// to namespace URIs.</span>
<a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMXPathNSResolver&gt;</a> resolver(document-&gt;createNSResolver(document-&gt;getDocumentElement()));
resolver-&gt;addNamespaceBinding(X(<span class="stringliteral">"my"</span>), X(<span class="stringliteral">"http://example.com/myURI"</span>));
resolver-&gt;addNamespaceBinding(X(<span class="stringliteral">&quot;my&quot;</span>), X(<span class="stringliteral">&quot;http://example.com/myURI&quot;</span>));
<span class="comment">// **************** Example 1: max() function ****************** //</span>
{
<span class="comment">// 2. Create a parsed expression</span>
<span class="keyword">const</span> <span class="keywordtype">char</span>* expression = <span class="stringliteral">"max(/Catalogue/Book/Price)"</span>;
<span class="keyword">const</span> <span class="keywordtype">char</span>* expression = <span class="stringliteral">&quot;max(/Catalogue/Book/Price)&quot;</span>;
<a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMXPathExpression&gt;</a> parsedExpression(document-&gt;createExpression(X(expression), resolver));
<span class="comment">// 3. Evaluate the expression. We choose to have a first result, since we</span>
@ -109,14 +120,14 @@ XERCES_CPP_NAMESPACE_USE;
<a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMXPathResult&gt;</a> firstResult(parsedExpression-&gt;evaluate(document-&gt;getDocumentElement(), DOMXPathResult::FIRST_RESULT_TYPE, 0));
<span class="comment">// 4. Work with the result: output it to the screen in this case</span>
cout &lt;&lt; <span class="stringliteral">"The answer for expression '"</span> &lt;&lt; expression &lt;&lt; <span class="stringliteral">"' is: "</span> &lt;&lt; firstResult-&gt;getNumberValue() &lt;&lt; endl;
cout &lt;&lt; <span class="stringliteral">&quot;The answer for expression &apos;&quot;</span> &lt;&lt; expression &lt;&lt; <span class="stringliteral">&quot;&apos; is: &quot;</span> &lt;&lt; firstResult-&gt;getNumberValue() &lt;&lt; endl;
}
<span class="comment">// **************** Example 2: output of nodes ****************** //</span>
{
<span class="comment">// 2. Create a parsed expression</span>
<span class="keyword">const</span> <span class="keywordtype">char</span>* expression2 = <span class="stringliteral">"//Magazine"</span>;
<span class="keyword">const</span> <span class="keywordtype">char</span>* expression2 = <span class="stringliteral">&quot;//Magazine&quot;</span>;
<a class="code" href="classAutoRelease.html">AutoRelease&lt;DOMXPathExpression&gt;</a> parsedExpression(document-&gt;createExpression(X(expression2), resolver));
<span class="comment">// 3. Evaluate the expression. We choose to have an iterator result</span>
@ -130,34 +141,35 @@ XERCES_CPP_NAMESPACE_USE;
StdOutFormatTarget target;
output-&gt;setByteStream(&amp;target);
cout &lt;&lt; <span class="stringliteral">"The answer for expression '"</span> &lt;&lt; expression2 &lt;&lt; <span class="stringliteral">"' is: "</span> &lt;&lt;endl;
cout &lt;&lt; <span class="stringliteral">&quot;The answer for expression &apos;&quot;</span> &lt;&lt; expression2 &lt;&lt; <span class="stringliteral">&quot;&apos; is: &quot;</span> &lt;&lt;endl;
<span class="keywordtype">int</span> i = 0;
<span class="keywordflow">while</span>(iteratorResult-&gt;iterateNext()) {
<span class="keywordflow">if</span>(iteratorResult-&gt;isNode()) {
cout &lt;&lt; <span class="stringliteral">"Node "</span> &lt;&lt; i++ &lt;&lt; <span class="stringliteral">": "</span>&lt;&lt; flush;
cout &lt;&lt; <span class="stringliteral">&quot;Node &quot;</span> &lt;&lt; i++ &lt;&lt; <span class="stringliteral">&quot;: &quot;</span>&lt;&lt; flush;
serializer-&gt;write(iteratorResult-&gt;getNodeValue(), output);
cout &lt;&lt; endl;
} <span class="keywordflow">else</span> {
cerr &lt;&lt; <span class="stringliteral">"Expected a node but received an atomic value!"</span>&lt;&lt; endl;
cerr &lt;&lt; <span class="stringliteral">&quot;Expected a node but received an atomic value!&quot;</span>&lt;&lt; endl;
}
}
}
}
<span class="keywordflow">catch</span>(DOMException &amp;e) {
cerr &lt;&lt; <span class="stringliteral">"DOMException: "</span> &lt;&lt; UTF8(e.getMessage()) &lt;&lt; endl;
cerr &lt;&lt; <span class="stringliteral">&quot;DOMException: &quot;</span> &lt;&lt; UTF8(e.getMessage()) &lt;&lt; endl;
<span class="keywordflow">return</span> 1;
}
<span class="comment">// Terminate //</span>
<span class="comment"></span>
<a name="a8"></a><a class="code" href="classXQillaPlatformUtils.html#e1">XQillaPlatformUtils::terminate</a>();
<a name="a2"></a><a class="code" href="classXQillaPlatformUtils.html#a0bd04a35d4cb26894497c6ff4d8e2105" title="Perform XQilla termination.">XQillaPlatformUtils::terminate</a>();
<span class="keywordflow">return</span> 0;
}
</pre></div> <hr size="1"><address style="align: right;"><small>Generated on Fri Sep 25 06:55:48 2009 for XQilla DOM Level 3 API by&nbsp;
</pre></div> </div>
<hr size="1"/><address style="text-align: right;"><small>Generated on Fri Nov 13 15:00:06 2009 for XQilla DOM Level 3 API by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>