Below is an example of how my xml looks currently:
<Records>
<Record>
<Field id='NAMEOFBUSINESS'>
<Value>J's Burgers</Value>
</Field>
<Field id='BUSINESSPHONE'>
<Value>777-888-9999</Value>
</Field>
<Record>
</Records>
However, I need it to look like this:
<Records>
<Record>
<Field id='NAMEOFBUSINESS'>
<Value>J's Burgers</Value>
</Field>
<Field id='BUSINESSPHONE'>
<Value>777-888-9999</Value>
</Field>
<Record>
</Records>
Currently my code looks like this:
using (var sr = new StreamReader(filePath, encode))
{
xmlDocument.Load(sr);
}
XmlNodeList nlist = null;
XmlNode root = xmlDocument.DocumentElement;
if (root != null)
{
nlist = root.SelectNodes("//Field");
}
if (nlist == null)
{
return;
}
foreach (XmlElement node in nlist)
{
if (node == null)
{
continue;
}
var value = node.Value;
if (value != null)
{
var newValue = value.Replace("'", "'");
node.Value = newValue;
}
}
using (var xmlWriter = new XmlTextWriter(filePath, encode))
{
xmlWriter.QuoteChar = '\'';
xmlDocument.Save(xmlWriter);
}
So I'm needing to escape the "'", but only within the value elements that the apostrophe is present in.