473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

XML writer in web service

Hi,
I am trying to implement the following:
connect to data source, run stored procedure, store data in data table.
This all works fine, data table is accessed and the rows and columns are
writing their data into a string.
What I want to do is put XML data tags around the returned data, if I do
this as follows
<code>

GCS.DrugData = GCS.DrugData + "<ROW>" ;
foreach (DataColumn myColumn in myTable.Columns)
{
GCS.DrugData = GCS.DrugData + myRow[myColumn] + "," ;
}
GCS.DrugData = GCS.DrugData + "</ROW>" ;

</code>

The result is that the starting tag is created as <DrugDatabut the
tags I have entered (<ROW>) are not recognised as XML. How do I enter
XML tags directly into the return string?

Thanks,
Erwin
Dec 17 '07 #1
5 1873
E.Oosterhoorn wrote:
Hi,
I am trying to implement the following:
connect to data source, run stored procedure, store data in data table.
This all works fine, data table is accessed and the rows and columns are
writing their data into a string.
What I want to do is put XML data tags around the returned data, if I do
this as follows
<code>

GCS.DrugData = GCS.DrugData + "<ROW>" ;
foreach (DataColumn myColumn in myTable.Columns)
{
GCS.DrugData = GCS.DrugData + myRow[myColumn] + "," ;
}
GCS.DrugData = GCS.DrugData + "</ROW>" ;

</code>

The result is that the starting tag is created as <DrugDatabut the
tags I have entered (<ROW>) are not recognised as XML. How do I enter
XML tags directly into the return string?
Can't you simply use the WriteXml method of a DataTable?
<URL:http://msdn2.microsoft.com/en-us/library/system.data.datatable.writexml.aspx>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 17 '07 #2
Martin Honnen wrote:
E.Oosterhoorn wrote:
>Hi,
I am trying to implement the following:
connect to data source, run stored procedure, store data in data
table. This all works fine, data table is accessed and the rows and
columns are writing their data into a string.
What I want to do is put XML data tags around the returned data, if I
do this as follows
<code>

GCS.DrugData = GCS.DrugData + "<ROW>" ;
foreach (DataColumn myColumn in myTable.Columns)
{
GCS.DrugData = GCS.DrugData + myRow[myColumn] + "," ;
}
GCS.DrugData = GCS.DrugData + "</ROW>" ;

</code>

The result is that the starting tag is created as <DrugDatabut the
tags I have entered (<ROW>) are not recognised as XML. How do I enter
XML tags directly into the return string?

Can't you simply use the WriteXml method of a DataTable?
<URL:http://msdn2.microsoft.com/en-us/library/system.data.datatable.writexml.aspx>
thanks,
no, I am using .Net framework 1. and that is with framework 3.0
That should be incredibly easy, if it was available.
Dec 17 '07 #3
E.Oosterhoorn wrote:
no, I am using .Net framework 1. and that is with framework 3.0
That should be incredibly easy, if it was available.
WriteXml for a DataTable is also available in the .NET framework 2.0.
With 1.1 DataSet has a WriteXml method
<URL:http://msdn2.microsoft.com/en-us/library/system.data.dataset.writexml(VS.71).aspx>
so you could add your table you want to write to a DataSet and write
that out. Or you need to use XmlTextWriter to generate the XML yourself.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 17 '07 #4
Martin Honnen wrote:
E.Oosterhoorn wrote:
>no, I am using .Net framework 1. and that is with framework 3.0
That should be incredibly easy, if it was available.

WriteXml for a DataTable is also available in the .NET framework 2.0.
With 1.1 DataSet has a WriteXml method
<URL:http://msdn2.microsoft.com/en-us/library/system.data.dataset.writexml(VS.71).aspx>
so you could add your table you want to write to a DataSet and write
that out. Or you need to use XmlTextWriter to generate the XML yourself.

Martin, thanks for your help,

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.
Erwin
Dec 17 '07 #5
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/
Dec 17 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David McBride | last post by:
I'm getting the following message when I run my Perl script that uses the XML::Writer module: "Processing instruction target begins with 'xml' at .../makeconf/LW/LWTest.pm line 75" The pi()...
0
by: boy | last post by:
Hi all, I have created a simple template class as follow, but i encountered memory leakage on the base.Render(writer). Have all you of encountered the same problem? using System; using...
2
by: googleboy | last post by:
Hi. I am trying to write out a csv file with | instead of comma, because I have a field that may have many commas in it. I read in a csv file, sort it, and want to write it out again. I read...
1
by: ED | last post by:
I created a query with my detail data, but am struggling with the report writer. Any help would be appreciated! I have the first grouping "Service Line" and then second grouping "Physician" My...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Thomassen | last post by:
I am searching for a _simple_ wave file writer function – any good places to search. What I need is code that can store audio in 16 bit (signed short) and is capable of adjust the sampling...
1
by: tkpmep | last post by:
I expected the following code to work: f = file(fn,"wb") writer = csv.writer(f) for i in range(IMax): writer.writerow(].append( for j in range(N)])) but instead i got the following error...
2
by: Geoff | last post by:
Hello, I have three files: ~~~~~~~~~ people.xml ~~~~~~~~~ <?xml version="1.0"?> <people xmlns:xi="http://www.w3.org/2001/XInclude" > <xi:include href="AlanTuring.xml"/>
0
by: Larry Linson | last post by:
"JohnReed" <x@y.zwrote Terms of Service violation, USENET rules violation, and newsgroup spam complaint filed with ISP and news server. The FAQ at http://www.mvps.org/access/netiquette.htm...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.