Intaguesata
New Member
I need to take in XML with common parent nodes but with varying child nodes. Once I get it, I need to grab the tag names of the child nodes and use those names as headers. In the following example, all incoming XML will be wrapped as follows:\[code\]<customers> <customer> ...varying child nodes that do not have child nodes themselves </customer></customers>\[/code\]I have found that this works:\[code\]List<string> headerList = new List<string>();XmlDocument xmlDoc = new XmlDocument();xmlDoc.LoadXml(someXML);XmlNodeList xnl = xmlDoc.SelectNodes("customers/customer");foreach (XmlNode xn in xnl){ for (int x = 0; x < xn.ChildNodes.Count; x++) { headerList.Add(xn.ChildNodes[x].Name.ToString()); }}\[/code\]Is there a better way to do this?Thanks in advance.