Alma
Alma

Reputation: 4410

How get the attribute value of XML node in C#

I am parsing the XML in C# this XML:

     <Resident Type="R">
          <Payment>1218</Payment>
     </Resident>

I am parsing this way(please answer this same way, not other methods)

  XmlDocument parsed_xml = new XmlDocument();
  parsed_xml.LoadXml(dto.xml);


  XmlNodeList test = parsed_xml.SelectNodes("/IER/Credit/Loan/LoanApp/Applicant/Personal/Individuals/Individual/Resident/Peyment");


  if (xnList != null)

            PAYMENT = xnList.Item(0).InnerText;

with this code I can get the Payment value that is 1218 but how I can get the attribute value of Type that is "R" ?

Upvotes: 1

Views: 9157

Answers (1)

evanb
evanb

Reputation: 3111

You'll want to look at the ParentNode to get the attribute.

string residentType = xnList[0].ParentNode.Attributes["Type"].Value;

Upvotes: 3

Related Questions