E.Oosterhoorn wrote:
I have been looking at these methods, but I haven't used this type of
coding for a while, would you mind pointing me in the right direction
how I can take the data set and write this to a temp stream(?) to add to
the return tags in the web service.
I have a structure that contains strings where the data is to be
returned to the requester. The web service code creates these tags but I
want to add the result from the stored proc. inside these tags as XML.
What do I need to do to create a stream, write to the stream and read
that again to add to the string.
It is not clear to me what kind of XML you want to create. If you have a
DataTable and want to write it out to an XmlWriter or TextWriter with
..NET 1.1 then the following should help:
static void WriteTableXml(DataTable table, string rootElementName,
TextWriter textWriter)
{
WriteTableXml(table, rootElementName, new XmlTextWriter(textWriter));
}
static void WriteTableXml(DataTable table, string rootElementName,
XmlWriter xmlWriter)
{
xmlWriter.WriteStartElement(rootElementName);
foreach (DataRow row in table.Rows)
{
xmlWriter.WriteStartElement(XmlConvert.EncodeLocal Name(table.TableName));
foreach (DataColumn col in table.Columns)
{
xmlWriter.WriteElementString(XmlConvert.EncodeLoca lName(col.ColumnName),
row[col].ToString());
}
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
}
Example use is as follows:
DataTable table = new DataTable("table1");
DataColumn col1 = new DataColumn("col1", typeof(int));
table.Columns.Add(col1);
for (int i = 1; i <= 10; i++)
{
DataRow row = table.NewRow();
row[0] = i;
table.Rows.Add(row);
}
WriteTableXml(table, "root", Console.Out);
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/