1

ケース番号を読み取り、それを datagridview 行に入れる必要があります。他の要素が選択されていますが、ファイル パス内のすべての XML のケース番号 (nc:CaseTrackingID) を取得できません。私が抱えているもう 1 つの問題は、存在する Base64Object ごとに nc:DocumentDescriptionText を取得することです (この数は、1 回から処理されているドキュメントの数までさまざまです)。XML の例と、XML を読み取るために使用されている現在のコードを含めました。どんな援助でも大歓迎です。

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# コード:

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;
               }
            }
        }
    }
4

2 に答える 2

0

タグCaseTrackingIDを囲んでいるようです。**XML ファイルから二重の * を削除しようとしましたか? ** の意味はわかりませんが、ファイルの読み取りを妨げている可能性があります。

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

それは問題のように見えます。** が必要かどうかは不明です。

編集

代わりに、このようにコードを変更してみてはいかがでしょうか。これにより、ノードをトラバースしながらテキスト ノードがキャプチャされます。

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;
        }
    }
}

また、elelment変数をループの外に置きます

于 2013-10-14T19:09:13.057 に答える