<p>I have a simple CAML query like</p>

<pre><code>&lt;Where&gt;&lt;Eq&gt;&lt;Field="FieldName"&gt;&lt;Value Type="Text"&gt;Value text&lt;/Value&gt;&lt;/Field&gt;&lt;/Eq&gt;&lt;/Where&gt;
</code></pre>

<p>And I have a variable to substitute for <code>Value text</code>. What's the best way to validate/escape the text that is substituted here in the .NET framework?
I've done a quick web search on this problem but all what I found was <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlconvert.aspx" rel="nofollow noreferrer"><code>System.Xml.Convert</code></a> class but this seems to be not quite what I need here.</p>

<p>I know I could have gone with an <code>XmlWriter</code> here, but it seems like a lot of code for such a simple task where I just need to make sure that the <code>Value text</code> part is formatted well.</p>

use
```
System.Xml.Linq.XElement
```
and
```
SetValue
```
method. This will format the text
(assuming a string)
, but also allows you to set xml as the value.