Query Multiple XML Files using XQuery, Get Results in C#

In our previous post, we covered an iteration of the Cloudmersive Convert API which enables querying a single XML file using an XQuery query — so if you’re only looking for a single operation, head there to check it out. Below, we’ll walk through connecting to a similar iteration capable of querying multiple XML files. Check out how to connect using C# code from the Cloudmersive API Console.

The parameters for this API allow for multiple XML input files (up to 10) and require a valid XML XQuery (3.1 or earlier) query expression.

If you’re working in .NET, install the .NET SDK with the below command, and copy the first code snippet:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.4.2using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;

If you’re using .NET Core, use the below instead:

Install-Package Cloudmersive.APIClient.NETCore.DocumentAndDataConvert -Version 2.2.1using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NETCore.DocumentAndDataConvert.Model;

For the last step, copy in the remaining code to complete the API call, and supply your API key & XML files where indicated. For more details around parameters & response models, check out the Cloudmersive API Console page.

namespace Example
{
public class ConvertDataXmlQueryWithXQueryMultiExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new ConvertDataApi();
var inputFile1 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | First input XML file to perform the operation on.
var xQuery = xQuery_example; // string | Valid XML XQuery 3.1 or earlier query expression; multi-line expressions are supported
var inputFile2 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Second input XML file to perform the operation on. (optional)
var inputFile3 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Third input XML file to perform the operation on. (optional)
var inputFile4 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Fourth input XML file to perform the operation on. (optional)
var inputFile5 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Fifth input XML file to perform the operation on. (optional)
var inputFile6 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Sixth input XML file to perform the operation on. (optional)
var inputFile7 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Seventh input XML file to perform the operation on. (optional)
var inputFile8 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Eighth input XML file to perform the operation on. (optional)
var inputFile9 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Ninth input XML file to perform the operation on. (optional)
var inputFile10 = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Tenth input XML file to perform the operation on. (optional)
try
{
// Query multiple XML files using XQuery query, get results
XmlQueryWithXQueryMultiResult result = apiInstance.ConvertDataXmlQueryWithXQueryMulti(inputFile1, xQuery, inputFile2, inputFile3, inputFile4, inputFile5, inputFile6, inputFile7, inputFile8, inputFile9, inputFile10);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ConvertDataApi.ConvertDataXmlQueryWithXQueryMulti: " + e.Message );
}
}
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.