Solved

Save XML node as CDATA rather then just a regular node

Posted on 2006-06-25
3
325 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:pradeepsudharsan
ID: 16981141
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
ID: 16984072
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
ID: 16985629
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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