Board index » delphi » Re: XML + .NET (D8)
Trevor de Koekkoek
Delphi Developer |
Trevor de Koekkoek
Delphi Developer |
Re: XML + .NET (D8)2005-11-16 02:30:52 AM delphi129 "nisbus" <XXXX@XXXXX.COM>writes QuoteDS := DataSet.Create; DS.WriteXml(sr); String s = sr.ToString(); return s; -Trevor |
nisbus
Delphi Developer |
2005-11-16 11:04:05 PM
Re: XML + .NET (D8)
Hi,
I'm trying to read a dataset from an SQL server and return it as a XML text through a webservice. This is where I am at: function TWebService1.GetXML: String; var SQL : String; SQLCMD : SQLCommand; SQLConn : SQLConnection; DT : DataTable; SQLDA : SqlDataAdapter; DS : DataSet; FStream : System.IO.FileStream; XMLWrite : XMLTextWriter; XMLRead : XMLTextWriter; begin SQL := 'SELECT * FROM Banking'; SQLConn := 'SQLConnection.Create('server=********;database=**;User ID=**;password=****'); SQLDA := SQLDataAdapter.Create(SQL,SQLConn); DS := DataSet.Create; Fstream := FileStream.Create('XMLTEst.XML',System.IO.Filemode.Create); XMLWrite := XmlTextWriter.Create(FStream,Encoding.Unicode); DS.WriteXml(XMLWrite); XMLWrite.Close;//Put the XML to the FileStream result := ?; end; How do I Return the XML result as a string? thanks, nisbus |
nisbus
Delphi Developer |
2005-11-18 02:10:25 AM
Re: XML + .NET (D8)
Trevor de Koekkoek writes:
Quote"nisbus" <XXXX@XXXXX.COM>writes result := DS.GetXML; Now the question is about the well formedness of the XML I am outputting. Ex. I have a table that has the following field structure: _ID varchar(255) SDate dateTime Field1 float Field2 float I'd like to be able to send it out so that I don't have to parse the resulting XML text document like the datetime and the floating point numbers with regards to system locale. The XML I would like to put out should represent datetime fields as TXSDateTime and float fields as float. I've tried using your example and adding XMLSchema information with the file: DS.WriteXml(sr,XMLWriteMode.WriteSchema); which seems to render the correct result but I have to do some testing with the resulting document, is this the right approach? Another question is the encoding of the documents. Everything seems to be in UTF-8 and I can not find a way to change it. I'm using Unicode characters on the server side so I'd need to have all my XML documents in Unicode. The Encoding property of the StringWriter is Read/Only so I am kind of stuck with that. Why not use the XMLTextWriter? it has encoding abilities but I can't get it is output as a string. Also I'd like to be able to send Unicode characters as parameters to a webmethod, but up until now I haven't been able to. Is that a problem with the Web.Config file? Lastly: Are people outputting XML as String or as some other type? What are the benefits of XML as a string and what are the drawbacks (size is probably one.) Thanks again, nisbus |