vpekulas
asked on
Save XML node as CDATA rather then just a regular node
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.ToSt ring
sValue = dgPublic.Rows(I).Cells(1). Value.ToSt ring
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 )
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).
sValue = dgPublic.Rows(I).Cells(1).
Try
loNode = loXMLDoc.SelectSingleNode(
loNode.InnerText = sValue
Catch ex As Exception
blDONE = False
strERROR = strERROR & "Node ID " & ID & " failed to update." & vbCrLf
End Try
Next
loXMLDoc.Save(FileLocation
ASKER
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 ?
to update node:
loNode = loXMLDoc.SelectSingleNode(
How can I do the same for the WriteCData method ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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()