Converting the XML form of resultset to string in C#
-
Hi, In my C# application I am trying to execute a SQL query, transform the query results (using XSL) returned in a form of XML, and ultimately want the resutlset as a string in resultSetToAscii. I have started working on C# very recently, so I am sure that I am doing some silly mistake. Basically my code fails in the 3rd line here and the error desc is "Data at root level is invalid". Anybody any ideas? XPathDocument destination; XPathDocument source; source = new XPathDocument(new StringReader("//row")); destination = new XPathDocument(_xsl.Transform(source, null, (XmlResolver)null)); XPathNavigator nav = destination.CreateNavigator(); { XPathNodeIterator iterator = nav.Select("//row"); while (iterator.MoveNext()) { foreach (Field field in _destinationFields) { string data = ""; if (field.name != null) data = iterator.Current.GetAttribute(field.name, String.Empty); resultSetToAscii = data.PadRight(field.size, ' '); } } }
-
Hi, In my C# application I am trying to execute a SQL query, transform the query results (using XSL) returned in a form of XML, and ultimately want the resutlset as a string in resultSetToAscii. I have started working on C# very recently, so I am sure that I am doing some silly mistake. Basically my code fails in the 3rd line here and the error desc is "Data at root level is invalid". Anybody any ideas? XPathDocument destination; XPathDocument source; source = new XPathDocument(new StringReader("//row")); destination = new XPathDocument(_xsl.Transform(source, null, (XmlResolver)null)); XPathNavigator nav = destination.CreateNavigator(); { XPathNodeIterator iterator = nav.Select("//row"); while (iterator.MoveNext()) { foreach (Field field in _destinationFields) { string data = ""; if (field.name != null) data = iterator.Current.GetAttribute(field.name, String.Empty); resultSetToAscii = data.PadRight(field.size, ' '); } } }
You are creating a StringReader for the string "//row" and try yo use that as an xml document. The problem is that "//row" is far from a valid xml document. Are you trying to use xpath to read nodes from an xml document? Then you actually have to have an xml document to read from... --- b { font-weight: normal; }
-
You are creating a StringReader for the string "//row" and try yo use that as an xml document. The problem is that "//row" is far from a valid xml document. Are you trying to use xpath to read nodes from an xml document? Then you actually have to have an xml document to read from... --- b { font-weight: normal; }
-
Okay I understand. I think the resultset is in the form of xml. I get the resultset by executing this int iRecs = cmd.ExecuteNonQuery(); So what can I pass to this call below? source = new XPathDocument(...) Thanks.