0

所以我有一个 xmlDocument,我需要检查是否附加了信用评分。为此,我使用 xmlNodes.SelectSingleNode,然后检查 innerText。

我的问题是:其中一个节点在实际节点名称中有一个 ID 字段。所以我认为 C# 将其解释为节点名称的一部分。

 public void DeperPostAppend()
    {
        DirectoryInfo CompDir = new DirectoryInfo(FilePrep.CompletedDirectory);

          foreach (FileInfo File in CompDir.GetFiles())
          {
              // Load xml documents for sorting
              XmlDocument xmlDoc = new XmlDocument();
              try
              {
                  xmlDoc.Load(File.FullName);
              }
              catch
              {
                  if (File.Extension != ".xml")
                      return;
              }

            //XmlNode auto = xmlDoc.SelectSingleNode("//ACORD//InsuranceSvcRq//PersAutoPolicyQuoteInqRq");
            XmlNode home = xmlDoc.SelectSingleNode("//ACORD//InsuranceSvcRq//HomePolicyQuoteInqRq");
            XmlNode creditAuto = xmlDoc.SelectSingleNode("//ACORD//InsuranceSvcRq//PersAutoPolicyQuoteInqRq//PersPolicy//CreditScoreInfo//CreditScore");
            XmlNode creditHome = xmlDoc.SelectSingleNode("//ACORD//InsuranceSvcRq//HomePolicyQuoteInqRq//PersPolicy//CreditScoreInfo//CreditScore");

                //if file is type home quote
            if (File.Extension == ".xml" && creditHome != null)
                {
                    if (creditHome.InnerText != "ERR" || creditHome.InnerText != "NOH")
                    {
                        DeperHome();
                    }
                }
                //If file is type Auto Quote
            else if (File.Extension == ".xml" && creditAuto != null)
                {
                    if (creditAuto.InnerText != "ERR" || creditAuto.InnerText != "NOH")
                    {
                        DeperAuto();
                    }
                }
          }

    }//end DeperPostAppend

//ACORD//InsuranceSvcRq//HomePolicyQuoteInqRq//PersPolicy//CreditScoreInfo//CreditScore

PersPolicy 是问题所在。该节点在文档上看起来像这样。

<PersPolicy id="AE4562BEE086A92470D4">

我想忽略 id 部分,因为它会更改每个文档并且我有数千个文档要处理。

4

1 回答 1

0

我只是决定使用类来处理节点如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;


/// <summary>
/// 
/// </summary>

public class PersPolicy
{
    XElement self;
    public PersPolicy(XElement self) { this.self = self; }

    public CreditScoreInfo CreditScoreInfo { get { return _CreditScoreInfo ?? (_CreditScoreInfo = new CreditScoreInfo(self.Element("CreditScoreInfo"))); } }
    CreditScoreInfo _CreditScoreInfo;

    public string PolicyNumber
    {
        get { return (string)self.Element("PolicyNumber"); }
        set { self.Element("PolicyNumber").SetValue(value); }
    }
}

/// <summary>
/// 
/// </summary>
public class CreditScoreInfo
{
    XElement self;
    public CreditScoreInfo(XElement self) { this.self = self; }

    public string CreditScore
    {
        get { return (string)self.Element("CreditScore"); }
        set { self.Element("CreditScore").SetValue(value); }
    }
    public string CreditScoreDt
    {
        get { return (string)self.Element("CreditScoreDt"); }
        set { self.Element("CreditScoreDt").SetValue(value); }
    }
}
于 2012-04-23T19:03:02.007 回答