private static string getNodes(string xpath, string result){ var sw = new StringWriter(); var sets = new XmlWriterSettings{OmitXmlDeclaration = true}; var xw = XmlWriter.Create(sw, sets); xw.WriteStartElement("__"); var iter = new XPathDocument(new StringReader(result)).CreateNavigator().Select(xpath); while (iter.MoveNext()){ if (iter.Current.NodeType == XPathNodeType.Attribute) { xw.WriteElementString("_"+iter.Current.Name,iter.Current.Value); } else{ iter.Current.WriteSubtree(xw); } } xw.WriteEndElement(); xw.Flush(); result = sw.ToString(); return result; }