Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Save XML node as CDATA rather then just a regular node

Posted on 2006-06-25
3
Medium Priority
?
329 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
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 1000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

927 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