Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

XML Encoding

RSS
Modified on Mon, Sep 17, 2012, 9:37 AM by Administrator Categorized as XML, XSL, and XPath, ·Net Framework
The following code will XML-encode the specified string. You can convert code between C# and VB.NET at this website.

using System.IO;
using System.Xml;

StringWriter s = new StringWriter();
XmlTextWriter w = new XmlTextWriter(s);
w.WriteString(inputText);
string result = s.ToString();

Alternate Method

public static string XmlEncode(string input)
{
    input = input.Replace("&", "&");
    input = input.Replace("\"", """);
    input = input.Replace("'", "'");
    input = input.Replace("<", "&lt;");
    input = input.Replace(">", "&gt;");
    return input;
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.