The character sequence ’
is the HTML Entity (named) for the Unicode Character 'RIGHT SINGLE QUOTATION MARK' (U+2019).
The entity ’
isn't actually allowed in XML without first declaring it:
<!DOCTYPE section [
<!ENTITY rsquo '’'>
]>
When it comes to working with XML files, you generally shouldn't do so as plain text. Instead, you should choose a specialized library designed for working with XML. Microsoft lists a number of approaches in its article XML Processing Options. Under the heading .NET Framework Options, Microsoft says for LINQ To XML, "Use this option if you're writing new code."
With that in mind, I've written a short program in C# to demonstrate a possible approach for you. (I'm hoping you can translate the concepts to VB.) Below, you'll find the expected output from the program following by the program itself.
Expected Output
<Persons>
<Person>
<Name> John / </Name>
<age> 24 </age>
<DOB>
<year> 1990 </year>
<month> 03 </month>
<date> 23 </date>
</DOB>
</Person>
<Person>
<Name> Jane / </Name>
<age> 21 </age>
<DOB>
<year> 1993 </year>
<month> 04 </month>
<date> 25 </date>
</DOB>
</Person>
</Persons>
Example Program
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
class LinqToXmlDemo
{
static public void Main(string[] args)
{
XDocument document = XDocument.Parse(GetXml());
// Define a LINQ to XML query to return an enumeration of the
// `Name` elements. (Those are the elements whose values you
// wish to edit.)
var query =
from name in document.Root.Elements("Person").Elements("Name")
select name;
// The character that you want to remove.
string s = Convert.ToChar(0x2019).ToString();
// Iterate through each of the `Name` elements returned by the
// query and remove the character of interest.
foreach (var name in query)
{
if (name != null)
{
name.Value = ((string)name).Replace(s, String.Empty);
}
}
// Output the edited document.
Console.WriteLine(document.Root.ToString());
}
static string GetXml()
{
return
@"<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE section [
<!ENTITY rsquo '’'>
]>
<Persons>
<Person>
<Name>’ John /’ </Name>
<age> 24 </age>
<DOB>
<year> 1990 </year>
<month> 03 </month>
<date> 23 </date>
</DOB>
</Person>
<Person>
<Name>’ Jane /’ </Name>
<age> 21 </age>
<DOB>
<year> 1993 </year>
<month> 04 </month>
<date> 25 </date>
</DOB>
</Person>
</Persons>";
}
}