1

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" ?

Alma
  • 3,780
  • 11
  • 42
  • 78
  • That's old school. Use System.Linq.Xml instead. Much quicker and easier way to handle xml. –  Jun 12 '15 at 17:03
  • check this http://www.dotnetcurry.com/showarticle.aspx?ID=564 – DanielVorph Jun 12 '15 at 17:03
  • Check the following links, similar question is answered: http://stackoverflow.com/questions/18818618/read-xml-node-attribute http://stackoverflow.com/questions/1600065/how-to-read-attribute-value-from-xmlnode-in-c – Mrinal Kamboj Jun 12 '15 at 17:31

1 Answers1

3

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

string residentType = xnList[0].ParentNode.Attributes["Type"].Value;
evanb
  • 3,061
  • 20
  • 32