Solved

Save XML node as CDATA rather then just a regular node

Posted on 2006-06-25
3
322 Views
Last Modified: 2008-02-01
How can I save each node as CDATA rather then default text which gets processed by VB and removes all potentially invalid characters ?
The code I have now is below, where can I set the node being saved as CDATA ?


Dim I As Integer = 0
Dim FileLocation As String = StatusStrip1.Items(0).Text
Dim loXMLDoc As XmlDocument = New XmlDocument, loNode As XmlNode        
loXMLDoc.Load(FileLocation)


For I = 0 To dgPublic.Rows.Count - 1
    ID = dgPublic.Rows(I).Cells(0).Value.ToString
    sValue = dgPublic.Rows(I).Cells(1).Value.ToString
    Try
        loNode = loXMLDoc.SelectSingleNode("//Root/PS/KeyWord[@id=" & ID & "]")
        loNode.InnerText = sValue
    Catch ex As Exception
        blDONE = False
        strERROR = strERROR & "Node ID " & ID & " failed to update." & vbCrLf
    End Try
Next

loXMLDoc.Save(FileLocation)
0
Comment
Question by:vpekulas
3 Comments
 
LVL 7

Expert Comment

by:pradeepsudharsan
Comment Utility
Use  WriteCData method of XmlWriter Class
Dim writer As XmlTextWriter = Nothing
writer = New XmlTextWriter(filename, Nothing)
writer.Formatting = Formatting.Indented

writer.WriteStartDocument()
 writer.WriteCData("value")
writer.WriteEndDocument()
writer.Flush()
   writer.Close()


0
 

Author Comment

by:vpekulas
Comment Utility
OK, but how I can use this to update specific node ? As you can see in the code above I'm asking it
to update node:

loNode = loXMLDoc.SelectSingleNode("//Root/PS/KeyWord[@id=" & ID & "]")

How can I do the same for the WriteCData  method ?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
Comment Utility
Try this:

        If loNode.HasChildNodes Then
            Dim data As XmlCDataSection = loNode.ChildNodes(0)
            data.InnerText = "New text goes here"
        End If

Bob
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now