Question

I am needing to read out the case number and put it into a datagridview row. The other elements are being selected but I am unable to grab the case number (nc:CaseTrackingID) for every XML in the file path. The other issue I am having is grabbing the nc:DocumentDescriptionText for each Base64Object that exist (this number can range from once to however many documents are being processed). I have included the XML example and the current code being used to read the XML. Any assistance would be greatly appreciated.

XML:

<?xml version="1.0"?>
    <nc:DocumentDescriptionText s:id="ReviewWorkQueueId">XXX</nc:DocumentDescriptionText>
    <nc:DocumentDescriptionText s:id="ReviewWorkQueue">XXXXXXXXXXXXXXX</nc:DocumentDescriptionText>
    <nc:DocumentIdentification>
      <nc:IdentificationID>6283348</nc:IdentificationID>
    </nc:DocumentIdentification>
    <nc:DocumentPostDate>
      <nc:DateTime>2013-10-12T09:38:15.2266606-04:00</nc:DateTime>
    </nc:DocumentPostDate>
    <nc:DocumentSubmitter>
      <ecf:EntityPerson s:id="REVIEWER">
        <nc:PersonName>
          <nc:PersonGivenName>XXXXXXXXXXXXXXX</nc:PersonGivenName>
          <nc:PersonMiddleName>Z</nc:PersonMiddleName>
          <nc:PersonSurName>XXXXXXXXXXXXXXX</nc:PersonSurName>
          <nc:PersonFullName>XXXXXXXXXXXXXXX</nc:PersonFullName>
        </nc:PersonName>
        <nc:PersonOtherIdentification>
          <nc:IdentificationID>XXXXXXXXXXXXXXX</nc:IdentificationID>
          <nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
        </nc:PersonOtherIdentification>
        <nc:PersonOtherIdentification>
          <nc:IdentificationID>XXXXXXXXXXXXXXX</nc:IdentificationID>
          <nc:IdentificationCategoryText>FLEPORTAL_LOGONNAME</nc:IdentificationCategoryText>
        </nc:PersonOtherIdentification>
        <ecf:PersonAugmentation>
          <nc:ContactInformation>
            <nc:ContactEmailID>XXXXXXXXXXXXXXX</nc:ContactEmailID>
          </nc:ContactInformation>
        </ecf:PersonAugmentation>
      </ecf:EntityPerson>
    </nc:DocumentSubmitter>
    <ecf:SendingMDELocationID>
      <nc:IdentificationID>Filing Review MDE</nc:IdentificationID>
    </ecf:SendingMDELocationID>
    <ecf:SendingMDEProfileCode>urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:WebServicesMessaging-2.0</ecf:SendingMDEProfileCode>
    <CoreFilingMessage xmlns="urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:CoreFilingMessage-4.0">
      <nc:DocumentEffectiveDate>
        <nc:DateTime>2013-10-10T15:07:06.757-04:00</nc:DateTime>
      </nc:DocumentEffectiveDate>
      <nc:DocumentIdentification>
        <nc:IdentificationID>6283348</nc:IdentificationID>
      </nc:DocumentIdentification>
      <nc:DocumentInformationCutOffDate>
        <nc:DateTime>2013-10-10T15:07:06.757-04:00</nc:DateTime>
      </nc:DocumentInformationCutOffDate>
      <nc:DocumentPostDate>
        <nc:DateTime>2013-10-10T15:06:36-04:00</nc:DateTime>
      </nc:DocumentPostDate>
      <nc:DocumentReceivedDate>
        <nc:DateTime>2013-10-10T15:07:06.757-04:00</nc:DateTime>
      </nc:DocumentReceivedDate>
      <nc:DocumentSubmitter>
        <ecf:EntityPerson s:id="FILER">
          <nc:PersonName>
            <nc:PersonGivenName>XXXX</nc:PersonGivenName>
            <nc:PersonMiddleName>XXXX</nc:PersonMiddleName>
            <nc:PersonSurName>XXXX</nc:PersonSurName>
            <nc:PersonFullName>XXXX</nc:PersonFullName>
          </nc:PersonName>
          <nc:PersonOtherIdentification>
            <nc:IdentificationID>XXXX</nc:IdentificationID>
            <nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
          </nc:PersonOtherIdentification>
          <nc:PersonOtherIdentification>
            <nc:IdentificationID>XXXX</nc:IdentificationID>
            <nc:IdentificationCategoryText>FLEPORTAL_LOGONNAME</nc:IdentificationCategoryText>
          </nc:PersonOtherIdentification>
          <nc:PersonOtherIdentification>
            <nc:IdentificationID>XXXX</nc:IdentificationID>
            <nc:IdentificationCategoryText>BAR_NUMBER</nc:IdentificationCategoryText>
          </nc:PersonOtherIdentification>
          <nc:PersonOtherIdentification>
            <nc:IdentificationID>Unaffiliated Users</nc:IdentificationID>
            <nc:IdentificationCategoryText>EMPLOYER</nc:IdentificationCategoryText>
          </nc:PersonOtherIdentification>
          <ecf:PersonAugmentation>
            <nc:ContactInformation>
              <nc:ContactEmailID>XXXX</nc:ContactEmailID>
              <nc:ContactMailingAddress>
                <nc:StructuredAddress>
                  <nc:AddressDeliveryPointText>XXXX</nc:AddressDeliveryPointText>
                  <nc:LocationCityName>XXXX</nc:LocationCityName>
                  <nc:LocationStateUSPostalServiceCode>XX</nc:LocationStateUSPostalServiceCode>
                  <nc:LocationStateName>XX</nc:LocationStateName>
                </nc:StructuredAddress>
                <nc:AddressFullText>XXXX</nc:AddressFullText>
              </nc:ContactMailingAddress>
              <nc:ContactTelephoneNumber s:id="PRIMARYPHONE">
                <nc:FullTelephoneNumber>
                  <nc:TelephoneNumberFullID>XXXX</nc:TelephoneNumberFullID>
                </nc:FullTelephoneNumber>
              </nc:ContactTelephoneNumber>
            </nc:ContactInformation>
          </ecf:PersonAugmentation>
        </ecf:EntityPerson>
      </nc:DocumentSubmitter>
      <ecf:SendingMDELocationID s:id="Filing Assembly MDE">
        <nc:IdentificationID>XXXX</nc:IdentificationID>
        <nc:IdentificationID>XXXX</nc:IdentificationID>
        <nc:IdentificationCategoryText>FLEPORTAL</nc:IdentificationCategoryText>
      </ecf:SendingMDELocationID>
      <ecf:SendingMDEProfileCode>urn:oasis:names:tc:legalxml-courtfiling:schema:xsd:WebServicesMessaging-2.0</ecf:SendingMDEProfileCode>
      <civil:Case>
        <nc:ActivityDescriptionText s:id="CIRCUIT CIVIL">FCL-NON-HOMESTD 50,001-249,999</nc:ActivityDescriptionText>
        <nc:ActivityStatus>
          <nc:StatusText>ORIGINAL PEND                           </nc:StatusText>
          <nc:StatusDate>
            <nc:DateTime>2013-10-10T00:00:00-04:00</nc:DateTime>
          </nc:StatusDate>
        </nc:ActivityStatus>
        <nc:CaseTitleText>XXXXXXXXXXXXX</nc:CaseTitleText>
        <nc:CaseCategoryText s:id="8768812">FCH</nc:CaseCategoryText>
        **<nc:CaseTrackingID>XXXXXXXXXX</nc:CaseTrackingID>**
        <nc:CaseTrackingID s:id="ucn">XXXXXXXXXX</nc:CaseTrackingID>
        <j:CaseAugmentation>
          <j:CaseCourt>
            <nc:OrganizationIdentification>
              <nc:IdentificationID>5</nc:IdentificationID>
              <nc:IdentificationCategoryText>FLEPORTAL_ORGANIZATION</nc:IdentificationCategoryText>
            </nc:OrganizationIdentification>
            <nc:OrganizationIdentification>
              <nc:IdentificationID>1</nc:IdentificationID>
              <nc:IdentificationCategoryText>FLEPORTAL_ORGANIZATION_UNIT</nc:IdentificationCategoryText>
            </nc:OrganizationIdentification>
            <nc:OrganizationIdentification>
              <nc:IdentificationID>Trial</nc:IdentificationID>
              <nc:IdentificationCategoryText>XXXXXXX</nc:IdentificationCategoryText>
            </nc:OrganizationIdentification>
            <nc:OrganizationIdentification>
              <nc:IdentificationID>XXXXXXX</nc:IdentificationID>
              <nc:IdentificationCategoryText>XXXXXXX</nc:IdentificationCategoryText>
            </nc:OrganizationIdentification>
            <nc:OrganizationName>XXXXXXX</nc:OrganizationName>
            <nc:OrganizationUnitName>XXXXXXX</nc:OrganizationUnitName>
            <j:CourtName>XXXXXXX</j:CourtName>
          </j:CaseCourt>
        </j:CaseAugmentation>
        <ecf:CaseAugmentation>
          <nc:LanguageCode xsi:nil="true" />
        </ecf:CaseAugmentation>
      </civil:Case>
      <FilingConfidentialityIndicator>false</FilingConfidentialityIndicator>
      <FilingLeadDocument s:id="DOC00001" s:metadata="# Pages=2">
        <nc:DocumentApplicationName>application/pdf</nc:DocumentApplicationName>
        **<nc:DocumentDescriptionText s:id="Affidavits and Oaths">Affidavit:  Military Status Unknown</nc:DocumentDescriptionText>**

C# Code:

private void Form1_Load(object sender, EventArgs e)
{
    string sourceDir = @"\\filepath of XML";
    //var pattern = "*.xml";

    XmlReaderSettings settings = new XmlReaderSettings();
    settings.IgnoreComments = true;
    settings.IgnoreProcessingInstructions = true;
    settings.IgnoreWhitespace = true;
    settings.CheckCharacters = false;


    string DocID = null;
    int elementCount = 0;
    string reqID = null;
    string attyName = null;
    string attyBarID = null;
    //string reqDateTime = null;
    string empName = null;

    // Reads only XML files from the specific folder
    string[] fileEntries = Directory.GetFiles(sourceDir, "*.xml");

    foreach (string fileName in fileEntries)
    {
        DateTime dt = File.GetLastWriteTime(fileName);
        dt.ToString("yyyy-MM-dd HH:mm:ss");

            XmlReader xr = XmlReader.Create(fileName, settings); //reads XML from folder
            {
                while (xr.Read())
                {
                    if (xr.NodeType == XmlNodeType.Element && xr.Name == "nc:PersonFullName")
                    {
                        attyName = xr.ReadElementContentAsString();
                    }

                    if (xr.NodeType == XmlNodeType.Element && xr.Name == "nc:IdentificationID")
                    {
                        elementCount++;
                        DocID = xr.ReadElementContentAsString();
                        if (elementCount == 1)
                        {
                            reqID = DocID;
                        }

                        if (elementCount == 3)
                        {
                            empName = DocID;
                        }

                        if (elementCount == 8)
                        {
                            attyBarID = DocID;

                            elementCount = 0;
                             break;
                        }
                    }

                    if (xr.NodeType == XmlNodeType.Element && xr.Name == "nc:CaseTrackingID")
                        {
                            caseIDCount++;
                            CaseID = xr.ReadElementContentAsString();
                            if (caseIDCount == 3)
                            {
                                casenumber = CaseID;

                                caseIDCount = 0;
                                break;
                            }
                        }

                        int StartPos; // Current pos in file.

                        StreamReader sr = new StreamReader(fileName);
                        String Str = sr.ReadToEnd();

                        int Count = 0;
                        StartPos = 0;
                        do
                        {
                            StartPos = Str.IndexOf("<nc:BinaryBase64Object>", StartPos);
                            if (StartPos >= 0)
                            {
                                StartPos++;
                                Count++;
                            }
                        } while (StartPos >= 0);
                        int index = dataGridView1.Rows.Add();

                        DataGridViewRow row = dataGridView1.Rows[index];
                        dataGridView1.Sort(dataGridView1.Columns["datetime_completed"], ListSortDirection.Ascending);

                        row.Cells["trans_nbr"].Value = reqID;
                        row.Cells["user_completed"].Value = empName;
                        row.Cells["datetime_completed"].Value = dt;
                        row.Cells["atty_bar_no"].Value = attyBarID;
                        row.Cells["attorney_name"].Value = attyName;
                        row.Cells["doc_count"].Value = Count;
                        row.Cells["CaseNumber"].Value = casenumber;
               }
            }
        }
    }
Was it helpful?

Solution 2

So from my research, I made it more complicated than needed. Being able to get the element directly was more beneficial than running through an "IF" statement. I did notice that the elementCount++ was not allowing the element below to be read.

xr.ReadToFollowing("nc:CaseTrackingID");//this will directly get the element name
casenumber = xr.ReadElementContentAsString();

OTHER TIPS

It looks like CaseTrackingID has ** surrounding the tag. have you tried removing the double * from the XML file? I am not sure what the significance of the ** is but probably it is interfering with reading the file.

**<nc:CaseTrackingID>XXXXXXXXXX</nc:CaseTrackingID>**

That looks like a problem. Not sure if ** needs to be there are not.

Edit

How about changing the code like this instead. This will capture the text node while traversing the nodes

if (xr.NodeType == XmlNodeType.Element)
{
    element = xr.Name;
}
else if (xr.NodeType == XmlNodeType.Text)
{
    if (element == "nc:PersonFullName")
    {
        attyName = xr.Value;
    }
    else if (element == "nc:IdentificationID")
    {
        elementCount++;
        DocID = xr.Value;
        if (elementCount == 1)
        {
            reqID = DocID;
        }

        if (elementCount == 3)
        {
            empName = DocID;
        }

        if (elementCount == 8)
        {
            attyBarID = DocID;

            elementCount = 0;
            break;
        }
    }
    else if (element == "nc:CaseTrackingID")
    {
        elementCount++;
        DocID = xr.Value;
        if (elementCount == 1)
        {
            reqID = DocID;
        }

        if (elementCount == 3)
        {
            empName = DocID;
        }

        if (elementCount == 8)
        {
            attyBarID = DocID;

            elementCount = 0;
            break;
        }
    }
}

Also put the elelment variable outside the loop

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