Question

On the below code, I am wanting to know how I would get the sequence ID from the 'ReviewedLeadDocument'/'ReviewedConnectedDocument' section without adding new rows to the data table. As of right now, I have to use a completely different table to store this information which is causing quite the headache. The first sequence listed is being read from 'FilingLeadDocument'/'FilingConnectedDocument'. How would I get to the second "DocumentSequenceID" in the 'Reviewed" section without iterating more rows?

private static IEnumerable<object[]> GetDocumentsData(string folderPath = @"filepath")
{

return Directory.GetFiles(folderPath, "*.xml")
.Select(XDocument.Load)
.SelectMany(file => file.Descendants().Where(e => e.Name.LocalName == "FilingLeadDocument")
.Concat(file.Descendants().Where(e => e.Name.LocalName == "FilingConnectedDocument")
.Concat(file.Descendants().Where(e => e.Name.LocalName == "ReviewedLeadDocument")
.Concat(file.Descendants().Where(e => e.Name.LocalName == "ReviewedConnectedDocument")))))
 .Select(documentNode =>
 {
     try
     {
var receivedDateNode = documentNode.Elements().FirstOrDefault(e => e.Name.LocalName == "DocumentReceivedDate");
var SequenceNode = documentNode.Elements().FirstOrDefault(e => e.Name.LocalName == "DocumentSequenceID");
var descriptionNode = documentNode.Elements().FirstOrDefault(e => e.Name.LocalName == "DocumentDescriptionText");
var metadataNode = documentNode.Elements().FirstOrDefault(e => e.Name.LocalName == "DocumentMetadata");
var registerActionNode = metadataNode.Elements().FirstOrDefault(e => e.Name.LocalName == "RegisterActionDescriptionText");

return new object[]
 {
(string)documentNode.Parent.Parent.Elements().FirstOrDefault(e => e.Name.LocalName == "DocumentIdentification"),
SequenceNode != null ? SequenceNode.Value.Trim() : string.Empty,
(DateTime?)receivedDateNode.Elements().FirstOrDefault(e => e.Name.LocalName == "DateTime"),
descriptionNode != null ? descriptionNode.Value.Trim() : string.Empty,
registerActionNode != null ? registerActionNode.Value.Trim() : string.Empty
 };
     }
     catch (Exception e)
     {
 //Log.error("");
 return new object[] { };
     }
 }).ToArray();
}

XML Snipit to show two locations of Sequence ID: (This is the Filing Connected Document section)

 <FilingConnectedDocument s:id="DOC00010" s:metadata="# Pages=2">
        <nc:DocumentApplicationName>application/pdf</nc:DocumentApplicationName>
        <nc:DocumentDescriptionText s:id="Motions">Motion</nc:DocumentDescriptionText>
        <nc:DocumentFileControlID s:id="FileInputId">111</nc:DocumentFileControlID>
        <nc:DocumentFileControlID s:id="Rule6PublicAnswer">-1</nc:DocumentFileControlID>
        <nc:DocumentFileControlID s:id="Rule6ConfidentialAnswer">-1</nc:DocumentFileControlID>
        <nc:DocumentFileControlID s:id="TypeOfConfidentialDocument">-1</nc:DocumentFileControlID>
        <nc:DocumentPostDate>
          <nc:DateTime>2014-04-09T15:24:06.8579836-04:00</nc:DateTime>
        </nc:DocumentPostDate>
        <nc:DocumentReceivedDate>
          <nc:DateTime>2014-04-09T15:24:05.797-04:00</nc:DateTime>
        </nc:DocumentReceivedDate>
        **<nc:DocumentSequenceID>10</nc:DocumentSequenceID>**
        <ecf:DocumentMetadata>

(This is the Reviewed Connected Document section)

<ecf:ReviewedConnectedDocument s:id="REVIEWEDDOC00003">
    <nc:DocumentFiledDate>
      <nc:DateTime>2014-04-09T00:00:00</nc:DateTime>
    </nc:DocumentFiledDate>
    <nc:DocumentPostDate>
      <nc:DateTime>2014-04-09T15:24:06.857</nc:DateTime>
    </nc:DocumentPostDate>
    <nc:DocumentReceivedDate>
      <nc:DateTime>2014-04-09T15:24:05.797</nc:DateTime>
    </nc:DocumentReceivedDate>
    **<nc:DocumentSequenceID>3</nc:DocumentSequenceID>**
Was it helpful?

Solution

To get the sequence IDs of the first and the second element in your selection, do the following:

var matchingElements = documentNode.Elements().Where(e => e.Name.LocalName == "DocumentSequenceID");

var firstSequenceNode = matchingElements.FirstOrDefault();
var secondSequenceNode = matchingElements.ElementAtOrDefault(1);

I hope that is what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top