title: How to process the XML using XmlLite returned by the casablanca (PPL) http_client?
body: <p>I want to make request to the web service, get the XML content, and parse it to get specific values returned by the service.</p>
  
  <p>The code is to be written in native C++11 (MS Visual Studio 2013). The <a href="https://git01.codeplex.com/casablanca" rel="nofollow">Cassablanca</a> PPL library was chosen. For XML parsing, the XmlLite was chosen.</p>
  
  <p>I am used to C++ programming; however, the async-task programming from the PPL library--the approach--is new to me. I know what the asynchronous programming is, and I know the principles of parallel programming. However, I am not used to using the continuations (<code>.then(...)</code>), and I am only slowly wrapping my head around the concept.</p>
  
  <p>So far, I have modified the examples to get the XML result and write it into the text file:</p>
  
  <pre><code>// Open a stream to the file to write the HTTP response body into.
  auto fileBuffer = std::make_shared&lt;concurrency::streams::streambuf&lt;uint8_t&gt;&gt;();
  file_buffer&lt;uint8_t&gt;::open(L"test.xml", std::ios::out)
      .then([=](concurrency::streams::streambuf&lt;uint8_t&gt; outFile) -&gt; pplx::task &lt; http_response &gt;
  {
      *fileBuffer = outFile;
  
      // Create an HTTP request.
      // Encode the URI query since it could contain special characters like spaces.
      // Create http_client to send the request.
      http_client client(L"http://api4.mapy.cz/");
  
      // Build request URI and start the request.
      uri_builder builder(L"/geocode");
      builder.append_query(L"query", address);
  
      return client.request(methods::GET, builder.to_string());
  })
  
      // Write the response body into the file buffer.
      .then([=](http_response response) -&gt; pplx::task&lt;size_t&gt;
  {
      printf("Response status code %u returned.\n", response.status_code());
  
      return response.body().read_to_end(*fileBuffer);
  })
  
      // Close the file buffer.
      .then([=](size_t)
  {
      return fileBuffer-&gt;close();
  })
  
      // Wait for the entire response body to be written into the file.
      .wait();
  </code></pre>
  
  <p>Now, I need to understand how to modify the code to get the result that could be consumed XmlLite (Microsoft implementation that comes as <code>xmllite.h</code>, <code>xmllite.lib</code>, and <code>xmllite.dll</code>. I know what pull parsers are. But again, I am very new to the library. I am still a bit lost in PPL related streams and other classes. I do not know how to use them correctly. Any explanation is higly welcome.</p>
  
  <p>The cassablanca people say they use the XmlLite with the Cassablanca to process the results, but I did not find any example. Can you point me to some? Thanks.</p>
  
  <p><strong>Update (4th June 2014):</strong> The above code is actually wrapped as a function like that (<code>wxString</code> comes from wxWidgets, but one can easily replace it by <code>std::string</code> or <code>std::wstring</code>):</p>
  
  <pre><code>std::pair&lt;double, double&gt; getGeoCoordinatesFor(const wxString &amp; address)
  {
      ...the above code...
      ...here should be the XML parsing code...
      return {longitude, latitude};
  }
  </code></pre>
  
  <p>The goal actually is instead of writing the stream to the <code>test.xml</code> file to feed the XmlLite parser. The XML is rather small and it contains one or more (if the address is ambiguous) item elements with the x and y attributes that I want to extract -- like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;result&gt;
      &lt;point query="Vítězství 27, Olomouc"&gt;
          &lt;item
                  x="17.334045"
                  y="49.619723"
                  id="9025034"
                  source="addr"
                  title="Vítězství 293/27, Olomouc, okres Olomouc, Česká republika"
          /&gt;
          &lt;item
                  x="17.333067"
                  y="49.61618"
                  id="9024797"
                  source="addr"
                  title="Vítězství 27/1, Olomouc, okres Olomouc, Česká republika"
          /&gt;
      &lt;/point&gt;
  &lt;/result&gt;
  </code></pre>
  
  <p>I do not need that <code>test.xml</code> file. How to get the stream and how to redirect it to the XmlLite parser?</p>