-2

This is my Xml File:-

<commit><subject><![CDATA[Fixed:Bu| Integer Fields Not Saving with >10 digits [ 3f19d010-c472-4ae6-9d29-b727707fe867 ]]]></subject></commit>
<commit><subject><![CDATA[Merge branch 'iq17' of github.iqsmartapp.com:DEV/EnterpriseDesktop into iq17]]></subject></commit><commit><subject><![CDATA[Fixed:Bug-5 | Regression - [Desktop - Action Menu] - Item Print option do not download the PDF file instead displaying the blank screen in the next window. [ def7b8cb-6819-4380-9a57-5af635f9b70b ]]]></subject></commit>
Rao
  • 20,781
  • 11
  • 57
  • 77

1 Answers1

0

Try something like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Text.RegularExpressions;

namespace ConsoleApplication34
{
    class Program
    {
        static void Main(string[] args)
        {
            string xml =
                "<commit><subject><![CDATA[Fixed:Bu| Integer Fields Not Saving with >10 digits [ 3f19d010-c472-4ae6-9d29-b727707fe867 ]]]></subject></commit>" +
                "<commit><subject><![CDATA[Merge branch 'iq17' of github.iqsmartapp.com:DEV/EnterpriseDesktop into iq17]]></subject></commit><commit><subject><![CDATA[Fixed:Bug-5 | Regression - [Desktop - Action Menu] - Item Print option do not download the PDF file instead displaying the blank screen in the next window. [ def7b8cb-6819-4380-9a57-5af635f9b70b ]]]></subject></commit>";

            xml = "<Root>" + xml + "</Root>";

            StringReader sReader = new StringReader(xml);
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.CheckCharacters = false;
            XmlReader reader = XmlReader.Create(sReader);

            XDocument  elements = XDocument.Load(reader); 
            List<string> subjects = elements.Descendants("subject").Select(x => (string)x).ToList();


            List<string> guids = subjects.Select(x => Regex.Match(x, @"(?'guid'([a-z0-9]+-){4}[a-z0-9]+)").Groups["guid"].Value.Trim()).Where(x => x.Length > 0).ToList(); 

         } 


    }


}

If you have multiple guids in each CDATA then use this

List<string> guids = subjects.Select(x => Regex.Matches(x, @"(?'guid'([a-z0-9]+-){4}[a-z0-9]+)").Cast<Match>()
                .Select(y => y.Groups["guid"].Value.Trim()).Where(y => y.Length > 0)).SelectMany(x => x).ToList(); 

To check for Fixed

List<string> guids = subjects.Where(x => x.Contains("Fixed:Bu")).Select(x => Regex.Matches(x, @"(?'guid'([a-z0-9]+-){4}[a-z0-9]+)").Cast<Match>()
                .Select(y => y.Groups["guid"].Value.Trim()).Where(y => y.Length > 0)).SelectMany(x => x).ToList(); 
jdweng
  • 33,250
  • 2
  • 15
  • 20
  • Thanks jdweng. I tried your solution it worked. Now say suppose instead of only two lines of xml i have a file with around 20 lines similar to this. Now for each cdata i have a message but for some message contains Fixed. For this fixed ones, i want the respective regex to be stored in GUID. – Debojyoti Pal Jan 06 '17 at 11:16
  • If you have more than one guid in a tag then simply change Match to Match Collection. I Updated code. – jdweng Jan 06 '17 at 11:39