• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 38
  • Last Modified:

Inserting CDATA in xml node

I have an existing xml file and I want to be able to add data but with the <![CDATA[ somedata ]]> into the node wwhen I try i just get :   &lt;![CDATA[mystring]]&gt;.

try many things but so far fail

that what I use

                        If n1.Name = "name" Then

                            Dim MyXMLNode As XmlNode = n1.SelectSingleNode("ldm1")
                            'If we have the node let's change the text
                            If MyXMLNode IsNot Nothing Then
                                Dim strtxt As String = "<![CDATA[" & strtxtPlats & "]]>"
                                 ' CData = myXmlDocument.CreateCDataSection (strtxtPlats)
                                MyXMLNode.InnerText =strtxt

                            End If

1 Solution
hiramlightAuthor Commented:
Ok , I find the solution, I will post it as it may help other.

it i so simple thaat i miss it ...

all I need it to do was to replace .

   MyXMLNode.InnerText =strtxt


 MyXMLNode.InnerXml =strtxt

"innerxml"  will format the node in the correct CDATA format .

result : <ldm1><![CDATA[testing cdata formating in node]]></ldm1>

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now