XDocument Determine Last Child of Parent

Irrepejeamype

New Member
Walking an XML document with XDocument using descendants how would I determine I am at the last child of the parent?\[code\]XDocument xmlDoc = XDocument.Parse(xml) foreach (var element in xmlDoc.Descendants()) { //Need to determine the last child of the parent and do something here. }\[/code\]Example of XML and what is expected to be returned. I need to dynamically walk the document and not specify the XPath or Xquery since these will be used generically for various XML documents without getting into a lot of details of the why... Just looking to see if I can do this with XDocument or if there is a better approach still not specifying the tag names in a XPath or XQuery unless it can be done dynamically without knowing how many levels deep the document may be., \[code\]<?xml version="1.0"?><Root> <Customer><CustID>1</CustID><Name>Smith, Joe</Name><CustomerTransDetail><CustID>1</CustID><CustTransID>1</CustTransID><Note>NA</Note></CustomerTransDetail><CustomerTransDetail><CustID>1</CustID><CustTransID>2</CustTransID><Note>N/A</Note></CustomerTransDetail></Customer><Customer><CustID>2</CustID><Name>Smith, Jane</Name><CustomerTransDetail><CustID>2</CustID><CustTransID>1</CustTransID><Note>N/A</Note></CustomerTransDetail><CustomerTransDetail><CustID>2</CustID><CustTransID>2</CustTransID><Note>N/A</Note></CustomerTransDetail></Customer></Root>\[/code\]I need to know when I hit the last child of the parent so I can do something. So every time I hit Name node or Note node for example I can do something.
 
Back
Top