using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
public void Main(string[] args)
String xmlMsg = @"<MessageReceiptMessage xmlns='urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:MessageReceiptMessage-4.0' xmlns:ansi-nist='http://niem.gov/niem/ansi-nist/2.0' xmlns:j='http://niem.gov/niem/domains/jxdm/4.0' xmlns:nc='http://niem.gov/niem/niem-core/2.0' xmlns:ecf='urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CommonTypes-4.0'>
<nc:DocumentIdentification>
<nc:IdentificationID>91eb45e7-0d1c-4a4e-916f-063b62f79e23</nc:IdentificationID>
<nc:IdentificationCategoryText>CASEID</nc:IdentificationCategoryText>
</nc:DocumentIdentification>
<nc:DocumentIdentification>
<nc:IdentificationID>159647</nc:IdentificationID>
<nc:IdentificationCategoryText>ENVELOPEID</nc:IdentificationCategoryText>
</nc:DocumentIdentification>
<nc:DocumentIdentification>
<nc:IdentificationID>c2b97968-bdcc-4cd1-99b9-841907f215e1</nc:IdentificationID>
<nc:IdentificationCategoryText>FILINGID</nc:IdentificationCategoryText>
</nc:DocumentIdentification>
<nc:DocumentIdentification>
<nc:IdentificationID>2f431cff-8805-409f-8c43-36e60e9b7eb9</nc:IdentificationID>
<nc:IdentificationCategoryText>FILINGID</nc:IdentificationCategoryText>
</nc:DocumentIdentification>
<nc:DocumentIdentification>
<nc:IdentificationID>7aa7ddfc-7063-4f09-9b3e-f8c05310b49b</nc:IdentificationID>
<nc:IdentificationCategoryText>FILINGID</nc:IdentificationCategoryText>
</nc:DocumentIdentification>
<nc:DocumentIdentification>
<nc:IdentificationID>29083ee1-6e60-4b31-b240-c3076cd52544</nc:IdentificationID>
<nc:IdentificationCategoryText>FILINGID</nc:IdentificationCategoryText>
</nc:DocumentIdentification>
<nc:DocumentReceivedDate>
<nc:DateTime>2020-05-04T18:29:42.0Z</nc:DateTime>
</nc:DocumentReceivedDate>
<ecf:SendingMDELocationID>
<nc:IdentificationID>urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:WebServicesMessaging-2.0</nc:IdentificationID>
</ecf:SendingMDELocationID>
<ecf:SendingMDEProfileCode />
<nc:OrganizationIdentification>
<nc:IdentificationID>fresno:cr</nc:IdentificationID>
</nc:OrganizationIdentification>
<ecf:ErrorCode>0</ecf:ErrorCode>
<ecf:ErrorText>No Error</ecf:ErrorText>
<ecf:ErrorCode>28</ecf:ErrorCode>
<ecf:ErrorText>CaseTrackingID '3518921' not found.</ecf:ErrorText>
<ecf:ErrorCode>92</ecf:ErrorCode>
<ecf:ErrorText>\Invalid CaseTrackingID.</ecf:ErrorText>
</MessageReceiptMessage>";
EFM_SubmitResponse responseObj = null;
XElement doc = XElement.Parse(xmlMsg);
XNamespace ncNamespace = "http://niem.gov/niem/niem-core/2.0";
XNamespace ecfNamespace = "urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CommonTypes-4.0";
XNamespace jNamespace = "http://niem.gov/niem/domains/jxdm/4.0";
responseObj = (from el in doc.DescendantsAndSelf()
select new EFM_SubmitResponse
_caseId = el?.Elements(ncNamespace + "DocumentIdentification")?.Where(x => (string)x?.Element(ncNamespace + "IdentificationCategoryText") == "CASEID")?.
Select(x => (string)x?.Element(ncNamespace + "IdentificationID"))?.FirstOrDefault() ?? "",
_envelopeId = el?.Elements(ncNamespace + "DocumentIdentification")?.Where(x => (string)x?.Element(ncNamespace + "IdentificationCategoryText") == "ENVELOPEID")?.
Select(x => (string)x?.Element(ncNamespace + "IdentificationID"))?.FirstOrDefault() ?? "",
_organizationId = el?.Element(jNamespace + "CaseCourt")?.Element(ncNamespace + "OrganizationIdentification")?.Element(ncNamespace + "IdentificationID")?.Value ?? "",
_statusErrorList = el?.Elements(ecfNamespace + "Error")
.Select(er => new SubmitResponseError
_statusCode = er?.Elements()?.Where(e => (string)e?.Name?.LocalName?.ToLower() == "errorcode")?.First()?.Value ?? "",
_statusText = er?.Elements()?.Where(e => (string)e?.Name?.LocalName?.ToLower() == "errortext")?.First()?.Value ?? ""
String sResponseCsvErrs= String.Empty;
if ( responseObj._statusErrorList != null )
foreach (var error in responseObj._statusErrorList)
Regex regex = new Regex(@"[\\]+");
error._statusText = regex.Replace(error._statusText, "");
sResponseCsvErrs += error._statusCode + ":" + error._statusText;
if( ++x < responseObj._statusErrorList.Count() )
sResponseCsvErrs += ", ";
if(responseObj != null ) {
Console.WriteLine("EnvelopeID= " + responseObj._envelopeId);
Console.WriteLine("CaseID= " + responseObj._caseId);
Console.WriteLine("ErrorStatus= " + responseObj.GetCSVErrorList());
Console.WriteLine("OrgId= " + responseObj._organizationId);
public XElement _xResponseXml { get; set; }
public String _caseId { get; set; }
public String _envelopeId { get; set; }
public String _organizationId { get; set; }
public List<SubmitResponseError> _statusErrorList { get; set; }
public String _exception { get; set; }
public EFM_SubmitResponse()
_statusErrorList = new List<SubmitResponseError>();
SubmitResponseError _statusError = new SubmitResponseError
_statusErrorList.Add(_statusError);
public String GetCSVErrorList()
String sErrorCSVList = "";
foreach (var error in _statusErrorList)
Regex regex = new Regex(@"[\\]+");
error._statusText = regex.Replace(error._statusText, "");
sErrorCSVList += error._statusCode + ":" + error._statusText;
if (++x < _statusErrorList.Count())
public class SubmitResponseError
public String _statusCode { get; set; }
public String _statusText { get; set; }