This post disappeared from a previous blog of mine so I'm reposting it.
—
I've been working with a third-party database adapter that returns encoded Xml in some cases. BizTalk handles the decoding just fine but when I have problems with the adapter it can be problematic to examine the encoded documents. After a few days of dealing with this I put together a couple of VS.NET macros for encoding/decoding Xml which I'm sure people can find other uses for.
Here's how you can create these macros:
- Open VS.NET.
- View the Macro Explorer.
- Copy and paste the code snips, below, into appropriately named macro module (I created a new Macro Module and named it XmlHelpers.)
- Make sure you add a reference to System.Web in the macro editor for the macro module you just pasted the code snips into.
- Add an Imports statement for System.Web
- Save the macro.
- Select an Xml fragment in the editor that you would like to encode or decode.
- Double-click the XmlEncode or XmlDecode macro in the Macro Explorer.
- Note that it is actually using the System.Web.HttpUtility.HtmlEncode/HtmlDecode functions.
Here are the snips:
Sub XmlDecode()
Dim theTextSelection As TextSelection = DTE.ActiveDocument.Selection
Dim actualText As String = theTextSelection.Text
theTextSelection.Delete()
theTextSelection.Insert(HttpUtility.HtmlDecode(actualText))
End Sub
Sub XmlEncode()
Dim theTextSelection As TextSelection = DTE.ActiveDocument.Selection
Dim actualText As String = theTextSelection.Text