Solved

Save XML node as CDATA rather then just a regular node

Posted on 2006-06-25
3
324 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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