lakshminb7
lakshminb7

Reputation: 1602

How to change a text value tag to a cdata section

I generate a XMLDocument based on a dataset by binding the dataset to the XMLDocument object and then display it to user in vb.net. I have a requirement in which certain tags to contain cdata sections rather than text value. After generating the XMLDocument how to change only certain tag to cdata section and keeping all else as it is? Or is there a way to modify while binding itself?

Upvotes: 0

Views: 1019

Answers (3)

DreadPirateShawn
DreadPirateShawn

Reputation: 8412

You could use the "XmlDocument.CreateCDataSection(string)" method. First search each text string for "<" or ">" characters -- or for a full tag "" if known -- then use the appropriate method to output the data.

Upvotes: 1

lakshminb7
lakshminb7

Reputation: 1602

Actually the reason we are going with CDATA section is that the output text contain certain HTML format strings in it. When it is took as a plain text it will be taken by parser as a XMl element. For eg.

I need to display as

"<tag><![CDATA[Sample HTML tag <head> ]]> </tag>"

Upvotes: 0

Ned Batchelder
Ned Batchelder

Reputation: 376002

There is no difference between a text section and a CDATA, except how characters are quoted inside them. The parser that consumes the data won't see a difference. Are you sure you need to create a CDATA section?

Upvotes: 0

Related Questions