提问人:Hasan 提问时间:11/6/2023 最后编辑:dbcHasan 更新时间:11/7/2023 访问量:34
如何使用 .net 将 xml 内容中的列表内容转换为列表?将 InstallmentList 中的 OtsInstallmentsDetails 元素分配到列表
How can I convert the content of a list in xml content into a list using .net?Assigning OtsInstallmentsDetails elements in InstallmentList to the list
问:
下面是 XML:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope xmlns:soap=\"">
<soap:Body>
<ControlApplicationsResponse xmlns=\"http://FSM\">
<ControlApplicationsResult>
<ErrorMessage xmlns=\"">kaydı var</ErrorMessage>
<ResponseCode xmlns=\"http://core.intertech.com.tr/\">02</ResponseCode>
<InstallmentList xmlns=\"">
<OtsInstallmentsDetails>
<SubscriberNumber>53326</SubscriberNumber>
<SubscriberName>ergesrg</SubscriberName>
<InvoiceDate>2023-09-22T16:13:00</InvoiceDate>
<InvoiceNumber>0001032087</InvoiceNumber>
<InstallmentExplanation>1 Taksit</InstallmentExplanation>
<InstallmentSeqNumber>1</InstallmentSeqNumber>
<PaymentDate>2023-09-25T00:00:00</PaymentDate>
<PaymentAmount>1000.00</PaymentAmount>
<InstallmentAmount>0.00</InstallmentAmount>
</OtsInstallmentsDetails>
还有我的代码:
string xmlData = result; // The XML shown above
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlData);
XmlNodeList installmentList = xmlDoc.ChildNodes[1].FirstChild.FirstChild.FirstChild.ChildNodes;
List<OtsInstallment> installments = new List<OtsInstallment>();
foreach (XmlNode installment in installmentList)
{
if (installment.Name == "OtsInstallmentsDetails")
{
OtsInstallment installmentt = new OtsInstallment
{
SubscriberNumber = installment["SubscriberNumber"].InnerText,
SubscriberName = installment["SubscriberName"].InnerText,
InvoiceDate = DateTime.Parse(installment["InvoiceDate"].InnerText),
InvoiceNumber = installment["InvoiceNumber"].InnerText,
InstallmentExplanation = installment["InstallmentExplanation"].InnerText,
InstallmentSeqNumber = int.Parse(installment["InstallmentSeqNumber"].InnerText),
PaymentDate = DateTime.Parse(installment["PaymentDate"].InnerText),
PaymentAmount = decimal.Parse(installment["PaymentAmount"].InnerText),
InstallmentAmount = decimal.Parse(installment["InstallmentAmount"].InnerText)
};
installments.Add(installmentt);
}
}
答: 暂无答案
评论