Dino Chiesa [MSFT]
7/9/2003 3:25:00 AM
return an XmlNode
"Dave" <davet65109@hotmail.com> wrote in message
news:01f101c33a82$29b58fb0$a401280a@phx.gbl...
> I have a webservice in which I dump XML into a string and
> return it. The only problem is that it has the < and
> > in it. How can I return bonafide XML?
>
>
> <WebMethod> Public Function GetResults(ElectionDate as
> datetime) As string
> Dim CN As SqlConnection = New SqlConnection(sConnection)
> CN.Open()
>
> Dim CMD As SqlCommand = New SqlCommand()
> CMD.CommandText = "lp_ElectionResultsForXML"
> CMD.CommandType = CommandType.StoredProcedure
> CMD.CommandTimeout = 15
> CMD.Connection = CN
> CMD.Parameters.Add("@ElectionDate",
> System.Data.SqlDbType.SmallDateTime).Value = ElectionDate
>
> Dim reader As XmlReader = CMD.ExecuteXmlReader()
>
> Dim ds As DataSet = New DataSet()
> ds.ReadXml(reader, XmlReadMode.Fragment)
>
> Dim doc As XmlDataDocument = New XmlDataDocument(ds)
>
> strXML = doc.innerxml
>
> strXML = strxml.Replace("<Schema1>","<ElectionResults "
> & "LastUpdate=""" & datetime.Now() & """>")
> strXML = strXML.Replace("</Schema1>","</ElectionResults>")
>
> CN.Close()
>
> Return strXML
>
> You see the cheap way I put an attribute in this. The
> stored procedure uses FOR XML EXPLICIT, ELEMENT and I
> can't figure a better way!
>