WebMethod, XmlDocument and CreateProcessingInstruction

  • Thread starter Thread starter Lars Moastuen
  • Start date Start date
L

Lars Moastuen

I'm currently writing a webservice. I've successfully written a
service that gives me some XML data, but now I want to link a
XLS-stylesheet to that data. The way I'm trying to do that is to
create a webmethod that returns a XmlDataDocument, and use
CreateProcessingInstruction() to add a "stylesheet-header"... Problem
is that the headers I add using CreateProcessingInstruction() seems to
be removed (?) when the data is transferred over the web. When I use
XmlDocument.Save() the output is fine... What causes this? Is there
any workaround?

The optimal solution would allow me to return a ADO.NET DataSet, and
still link an XLS-datasheet to the document. Reason is that I'm
intending to use the service with crystal reports through the ADO.NET
driver (doesn't recognize methods not returning DataSet). Is there a
way?

My method is as follows:
[WebMethod]
public XmlDataDocument test()
{
Basin tree = db.GetBasinTree();

DataSet ds = new DataSet();
ds.EnforceConstraints = false;
DataTable tb = ds.Tables.Add("basin");
tb.Columns.Add("basinid", typeof(Decimal));
tb.Columns.Add("basinname", typeof(String));
tb.Columns.Add("parent", typeof(Decimal));
tb.Columns.Add("haschildren", typeof(bool));
AddBasinChildren(tb, tree);

XmlDataDocument xmlDoc = new XmlDataDocument(ds);
String stylesheet = "type=\"text/xsl\" href=\"test.xsl\"";
XmlProcessingInstruction xlsNode =
xmlDoc.CreateProcessingInstruction("xml-stylesheet", stylesheet);
xmlDoc.InsertBefore(xlsNode, xmlDoc.DocumentElement);
xmlDoc.Save("c:\\temp\\thisworks.xml");

return xmlDoc;
}

Help appreciated!
Lars Moastuen
GeoKnowledge
 
I am trying to do an identical thing

Did you ever find the solution ?

David Davies,
Goldman Sachs
 
Trying a cross post to
microsoft.public.dotnet.framework.webservices

David Davies said:
I am trying to do an identical thing

Did you ever find the solution ?

David Davies,
Goldman Sachs

Lars Moastuen said:
I'm currently writing a webservice. I've successfully written a
service that gives me some XML data, but now I want to link a
XLS-stylesheet to that data. The way I'm trying to do that is to
create a webmethod that returns a XmlDataDocument, and use
CreateProcessingInstruction() to add a "stylesheet-header"... Problem
is that the headers I add using CreateProcessingInstruction() seems to
be removed (?) when the data is transferred over the web. When I use
XmlDocument.Save() the output is fine... What causes this? Is there
any workaround?

The optimal solution would allow me to return a ADO.NET DataSet, and
still link an XLS-datasheet to the document. Reason is that I'm
intending to use the service with crystal reports through the ADO.NET
driver (doesn't recognize methods not returning DataSet). Is there a
way?

My method is as follows:
[WebMethod]
public XmlDataDocument test()
{
Basin tree = db.GetBasinTree();

DataSet ds = new DataSet();
ds.EnforceConstraints = false;
DataTable tb = ds.Tables.Add("basin");
tb.Columns.Add("basinid", typeof(Decimal));
tb.Columns.Add("basinname", typeof(String));
tb.Columns.Add("parent", typeof(Decimal));
tb.Columns.Add("haschildren", typeof(bool));
AddBasinChildren(tb, tree);

XmlDataDocument xmlDoc = new XmlDataDocument(ds);
String stylesheet = "type=\"text/xsl\" href=\"test.xsl\"";
XmlProcessingInstruction xlsNode =
xmlDoc.CreateProcessingInstruction("xml-stylesheet", stylesheet);
xmlDoc.InsertBefore(xlsNode, xmlDoc.DocumentElement);
xmlDoc.Save("c:\\temp\\thisworks.xml");

return xmlDoc;
}

Help appreciated!
Lars Moastuen
GeoKnowledge
 
Try Cross posting to dotnet.framework.webservices

David Davies said:
I am trying to do an identical thing

Did you ever find the solution ?

David Davies,
Goldman Sachs

Lars Moastuen said:
I'm currently writing a webservice. I've successfully written a
service that gives me some XML data, but now I want to link a
XLS-stylesheet to that data. The way I'm trying to do that is to
create a webmethod that returns a XmlDataDocument, and use
CreateProcessingInstruction() to add a "stylesheet-header"... Problem
is that the headers I add using CreateProcessingInstruction() seems to
be removed (?) when the data is transferred over the web. When I use
XmlDocument.Save() the output is fine... What causes this? Is there
any workaround?

The optimal solution would allow me to return a ADO.NET DataSet, and
still link an XLS-datasheet to the document. Reason is that I'm
intending to use the service with crystal reports through the ADO.NET
driver (doesn't recognize methods not returning DataSet). Is there a
way?

My method is as follows:
[WebMethod]
public XmlDataDocument test()
{
Basin tree = db.GetBasinTree();

DataSet ds = new DataSet();
ds.EnforceConstraints = false;
DataTable tb = ds.Tables.Add("basin");
tb.Columns.Add("basinid", typeof(Decimal));
tb.Columns.Add("basinname", typeof(String));
tb.Columns.Add("parent", typeof(Decimal));
tb.Columns.Add("haschildren", typeof(bool));
AddBasinChildren(tb, tree);

XmlDataDocument xmlDoc = new XmlDataDocument(ds);
String stylesheet = "type=\"text/xsl\" href=\"test.xsl\"";
XmlProcessingInstruction xlsNode =
xmlDoc.CreateProcessingInstruction("xml-stylesheet", stylesheet);
xmlDoc.InsertBefore(xlsNode, xmlDoc.DocumentElement);
xmlDoc.Save("c:\\temp\\thisworks.xml");

return xmlDoc;
}

Help appreciated!
Lars Moastuen
GeoKnowledge
 
Back
Top