5
Answers

How to put a string value inside CDATA block?

Lise

Lise

13y
3.3k
1
Hi.  

I want to serialize a class to a string (who is a property of another class). I do it like this:

(schema is the XML I want to put in the string.)

Dim ser As New XmlSerializer(GetType(schemaobject))

Dim sw As New IO.StringWriter()

ser.Serialize(sw, schema)

 

sw.ToString will give the xml, and I can write:

Dim objReader As System.IO.StreamWriter

objReader = New StreamWriter("C:\xmlfile.txt")

objReader.Write(sw.ToString)

objReader.Close()

But I don't want to write the xml to file I want it stored in a string variable, and I need to put the whole xml inside a CDATA block, how can I do that? I will put sw.ToString (that is my xml) inside a CDATA block and then store my xml inside the CDATA in a string.

How can I do that in VB.NET?

Thanks.

Lise

Answers (5)