https://stackoverflow.com/questions/66739322/i-am-having-trouble-moving-data-from-an-xml-file-into-an-array-with-cdata-node-t

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Data;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
using System.Reflection;

using NUnit.Framework; //NUnit.Framework.AssertionException

//https://stackoverflow.com/questions/66739322/i-am-having-trouble-moving-data-from-an-xml-file-into-an-array-with-cdata-node-t

    public class TestClass
    {
        public static void Test()
        {
			var FilePath = @"Question66739322.xml";
			try
			{
				File.WriteAllText(FilePath, GetXml());

				var ns = ""; // Replace with @"http://intelliquip.com/integrationS..." can't see the full namespace from the XML image.
				var list = new List<Tuple<string, string>>(); // List of (quoteNumber, orderNumber) values.
				var xmlReader = XmlReader.Create(FilePath);
				while (xmlReader.ReadToFollowing("quoteNumber", ns))
				{
					string quoteNumber = null;
					string orderNumber = null;
					using (var inner = xmlReader.ReadSubtree())
					{
						// We need to skip the insignificant whitespace around the CDATA nodes which ReadElementContentAsString() will not do.
						while (inner.Read())
						{
							switch (xmlReader.NodeType)
							{
								case XmlNodeType.Text:
								case XmlNodeType.CDATA:
									quoteNumber += inner.Value;
									break;
							}
						}
						// After ReadSubtree() the reader is positioned on the </quoteNumber> element end.
					}
					// If the next orderNumber node is nmissing, ReadToFollowing() will read all the way past the next quoteNumber node.  
					// Use ReadToNextSibling() instead.
					if (xmlReader.ReadToNextSibling("orderNumber", ns))
					{
						using (var inner = xmlReader.ReadSubtree())
						{
							while (inner.Read())
							{
								switch (xmlReader.NodeType)
								{
									case XmlNodeType.Text:
									case XmlNodeType.CDATA:
										orderNumber += inner.Value;
										break;
								}
							}
						}
					}

					if (quoteNumber != null && orderNumber != null)
						list.Add(Tuple.Create(quoteNumber, orderNumber)); 
					else
					{
						// Add error handling here
					}
				}

				Console.WriteLine("Deserialized list:");
				Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(list, Newtonsoft.Json.Formatting.Indented));
			}
			finally
			{
				File.Delete(FilePath);
			}
        }
		
		static string GetXml() => @"<foo>
<bar>
<quoteNumber>
<![CDATA[ John Test 123]]>
</quoteNumber>
<orderNumber>
<![CDATA[ 1352738]]> 
</orderNumber>
</bar>
</foo>
";
    }

	public class Program
	{
		public static void Main()
		{
			Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
			Console.WriteLine();

			try
			{
				TestClass.Test();
			}
			catch (Exception ex)
			{
				Console.WriteLine("Failed with unhandled exception: ");
				Console.WriteLine(ex);
				throw;
			}
		}
		
		public static string GetNetCoreVersion()
		{
			//https://techblog.dorogin.com/how-to-detect-net-core-version-in-runtime-ecd65ad695be
			//
			var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
			var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
			int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
			if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
				return assemblyPath[netCoreAppIndex + 1];
			return null;
		}
	}
;