1

我需要读出案例编号并将其放入 datagridview 行。正在选择其他元素,但我无法获取文件路径中每个 XML 的案例编号 (nc:CaseTrackingID)。我遇到的另一个问题是为每个存在的 Base64Object 获取 nc:DocumentDescriptionText(这个数字的范围可以从一次到正在处理的许多文档)。我已经包含了 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 回答
0

所以根据我的研究,我让它比需要的更复杂。能够直接获取元素比运行“IF”语句更有益。我确实注意到 elementCount++ 不允许读取下面的元素。

xr.ReadToFollowing("nc:CaseTrackingID");//this will directly get the element name
casenumber = xr.ReadElementContentAsString();
于 2013-10-16T11:50:01.557 回答