我目前正在处理XML文件,其中我必须检索特定元素下的节点。这些节点大多包含DateTime
个对象,当它们被检索时,它们会得到更新。问题是其中一个属性比其他属性低两个级别(导致需要第二个.Descendants
)。如何将低两级(_StartDate
)的属性与其中一个属性进行比较。我特意希望将_StartDate
与_AccountReportedDate
进行比较。
var creditLiabilities = xDoc.Descendants("CREDIT_LIABILITY").Descendants("_PAYMENT_PATTERN")
.Select(x => new
{
Element = x,
AccountOpenedDate = x.Attribute("_AccountOpenedDate") == null ? string.Empty : x.Attribute("_AccountOpenedDate").Value + "-01",
AccountClosedDate = x.Attribute("_AccountClosedDate") == null ? string.Empty : x.Attribute("_AccountClosedDate").Value + "-01",
AccountPaidDate = x.Attribute("_AccountPaidDate") == null ? string.Empty : x.Attribute("_AccountPaidDate").Value + "-01",
AccountReportedDate = x.Attribute("_AccountReportedDate") == null ? string.Empty : x.Attribute("_AccountReportedDate").Value + "-01",
LastActivityDate = x.Attribute("_LastActivityDate") == null ? string.Empty : x.Attribute("_LastActivityDate").Value + "-01",
AccountStatusDate = x.Attribute("_AccountStatusDate") == null ? string.Empty : x.Attribute("_AccountStatusDate").Value + "-01",
Monthcount = x.Attribute("_MonthsReviewedCount") == null ? string.Empty : x.Attribute("_MonthsReviewedCount").Value,
StartDate = x.Attribute("_StartDate") == null ? string.Empty :x.Attribute("_StartDate").Value,
}
);
以下是XML代码:
<CREDIT_LIABILITY CreditLiabilityID="CreditLiabilityID_52885" x_MasterTradelineId="52885" x_CDOTradelineId="153216" BorrowerID="Borrower" CreditFileID="CreditFileId_14462 CreditFileId_14460 CreditFileId_14461" x_TradelineGroupId="152665" x_Primary="Y" x_BureauName="Experian" x_SubscriberCode="1631440" _AccountIdentifier="7634134580" _AccountOpenedDate="2014-04" _AccountOwnershipType="Individual" _AccountReportedDate="2014-11" _AccountStatusDate="2015-01" _AccountStatusType="Open" x_FannieAccountStatusType="Open" x_StatusLong="Current account/was 30 days past due date" _AccountType="Installment" _ConsumerDisputeIndicator="N" _DerogatoryDataIndicator="N" _HighBalanceAmount="21811.00" _LastActivityDate="2014-09" _ManualUpdateIndicator="N" x_ActualPaymentAmount="363.00" _MonthsReviewedCount="8" _TermsMonthsCount="60" _UnpaidBalanceAmount="19993.00" x_UnpaidBalanceNumber="19993.0000" CreditLoanType="CreditCard" x_FNMACreditLoanCode="CC" x_RealEstateRelated="0" x_PrimaryRealEstate="0" x_ECOA2="B" x_CREDITOR_Name="FORD CRED" x_PrimaryGroupBy="Installment" _MonthlyPaymentAmount="363.00" _TermsSourceType="Provided" x_EstPayment="N" x_EstPaymentPct="0.020" _MonthsRemainingCount="53">
<_CREDITOR _Name="FORD CRED" />
<_CURRENT_RATING _Code="C" _Type="Late30Days" />
<_LATE_COUNT _30Days="1" _60Days="0" _90Days="0" x_30Lates="07/14" x_60Lates="" x_90Lates="" />
<_PAYMENT_PATTERN _Data="CCC1CC" _StartDate="2014-11" />
<CREDIT_REPOSITORY _SourceType="TransUnion" x_Primary="No" _SubscriberCode="03796761" x_CDOTradelineId="153213" />
<CREDIT_REPOSITORY _SourceType="Equifax" x_Primary="No" _SubscriberCode="644FA04640" x_CDOTradelineId="153215" />
<CREDIT_REPOSITORY _SourceType="Experian" x_Primary="Yes" _SubscriberCode="1631440" x_CDOTradelineId="153216" />
</CREDIT_LIABILITY>