write xml to memory instead of file

M

M.Posseth

Hello all ,

I have this VB.NET code , it generates a xml document that is then
read into a string and send to a unix webservice

Dim XMLHess As New XmlTextWriter("test.xml",
System.Text.Encoding.GetEncoding("iso-8859-1"))

With XMLHess
.Formatting = Formatting.Indented
.Indentation = 2
.WriteStartDocument()
.WriteStartElement("onlinebestellung")
.WriteStartElement("request")
.WriteElementString("cmd", "INQUIRY") 'INQUIRY 'ORDER
.WriteEndElement()
.WriteStartElement("positionen")
'loop voor de artikelen
.WriteStartElement("artikel")
.WriteElementString("bestellartikelnummer","24.0110-0116.1")
.WriteElementString("bestellmenge", "1")
.WriteElementString("hersteller", "ATE")
.WriteEndElement()
'einde artikelloop
.WriteEndDocument()
.Close()
Dim sRead As New StreamReader("test.xml")
strXML = sRead.ReadToEnd()
End With
MsgBox(strXML)

Dim shopHess As New HessShop.ITiRepSrvservice

Dim strError As String, intReturn As Integer, intSucces As Integer

Debug.WriteLine(strXML)

intSucces = shopHess.XMLExecute("logoninfo", strXML, strError,
intReturn)



It is working fine however i do not want to generate a physical file
write to it and read it back , my server is a verry powerfull machine (
cluster server ) and i would like to generate the xml format in memory
and then output it to a string and send it to the webservice


Does someone have an idea what i need to modify to acomplish this ??

Michel ,
 
C

Cor Ligthert

Michel,

I find this the easiest ones

Serialize
\\\\
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.tostring
///
Deserialize
\\\
Dim sr As New System.IO.StringReader(mystring)
Dim ds2 As New DataSet
ds2.ReadXml(sr)
///
I hope this helps a little bit?

Cor
 
M

M.Posseth

Cor said:
Michel,

I find this the easiest ones

Serialize
\\\\
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Dim mystring As String = sw.tostring
///
Deserialize
\\\
Dim sr As New System.IO.StringReader(mystring)
Dim ds2 As New DataSet
ds2.ReadXml(sr)
///
I hope this helps a little bit?

Cor

Cor ,, you are great

changed my code to this

Dim sw As New System.IO.StringWriter
Dim XMLHess As New XmlTextWriter(sw)

With XMLHess
.Formatting = Formatting.Indented
.Indentation = 2
.WriteStartDocument()
.WriteStartElement("onlinebestellung")
.WriteStartElement("request")
.WriteElementString("cmd", "INQUIRY") 'INQUIRY 'ORDER
.WriteEndElement()
.WriteStartElement("positionen")
'loop voor de artikelen
.WriteStartElement("artikel")
.WriteElementString("bestellartikelnummer","24.0110-0116.1")
.WriteElementString("bestellmenge", "1")
.WriteElementString("hersteller", "ATE")
.WriteEndElement()
'einde artikelloop
.WriteEndDocument()
.Close()
strXML = sw.ToString
End With
MsgBox(strXML)


and it works exactly how i wanted


i was already considering to write the xml myself in a string but this
is much better :)

regards and have a nice day

Michel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top