我如何使用C#解析此xml文档,我仅对ComplianceInfo部分感兴趣?
<RootDTO>
<SbisInfo>
<Errors />
<InfoMessages>
<InfoMessageDTO>
<Message>Service completed successfully</Message>
</InfoMessageDTO>
</InfoMessages>
<Customer>
<BPID>150242138</BPID>
<ComplianceInfo>
<ComplianceStatusCode>007</ComplianceStatusCode>
<ComplianceStatusInd>Y</ComplianceStatusInd>
<FraudConsentGivenInd>Y</FraudConsentGivenInd>
<UndesirableStatusCode>009</UndesirableStatusCode>
<PepStatusCode>007</PepStatusCode>
<KycStatusCode>001</KycStatusCode>
<CraStatusCode>004</CraStatusCode>
</ComplianceInfo>
</Customer>
</SbisInfo>
</RootDTO>
答案 0 :(得分:1)
您可以使用ComplianceInfo
和XPath选择器从XmlDocument
节点获取数据,如下所示:
string xml = @"your-xml-here";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNode node = doc.SelectSingleNode("/RootDTO/SbisInfo/Customer/ComplianceInfo");
string ComplianceStatusCode = node["ComplianceStatusCode"].InnerText;
string ComplianceStatusInd = node["ComplianceStatusInd"].InnerText;
string FraudConsentGivenInd = node["FraudConsentGivenInd"].InnerText;
string UndesirableStatusCode = node["UndesirableStatusCode"].InnerText;
string PepStatusCode = node["PepStatusCode"].InnerText;
string KycStatusCode = node["KycStatusCode"].InnerText;
string CraStatusCode = node["CraStatusCode"].InnerText;