I'm trying to strip illegal characters out of an XML string before I send it off to a public web service. The xml will look something like this:
<field name="notes">This is a note. Any character could appear here</field>
I need to pull out any ampercand (&) charachters in the any of the fields, as well as any < or > characters, which would make the XML unreadable.
I've tried it like this:
Private Shared Function cleanQuery(ByVal queryNode As String) As String
Dim root As XElement = XElement.Parse(queryNode)
For Each x As XElement In root.Elements
x.Value = x.Value.Replace("&", "&").Replace("<", "<").Replace(">", ">")
That doesn't work so well. I get the error stating:
There are multiple root elements. Line 1, position 15.
I tried wrapping the XML in a single root element, like this:
Private Shared Function cleanQuery2(ByVal q
View Complete Post