0

I've a problem whereby the XML that I've generated contains:

<attribute name="Actors">Trevante Rhodes , André Holland , Janelle Monáe</attribute>

but it should be this:

<attribute name="Actors">Trevante Rhodes , André Holland , Janelle Monáe</attribute>

@IntelliData's answer to the question posted here seems to suggest that the only solution is to replace them with their HTML encoded counter parts.

So... if I have a source file that may contain any foreign character from one or more countries, does this mean that I'd have to write a routine to do just that?

And if I have no choice, is there a more efficient way to do this search and replace?

myData = myData.Replace("À","&#192;").Replace("à","&#224;").Replace(...)

MORE INFO

To create the XML file, I am using

using (StreamWriter sw = new StreamWriter(myTxtFile))
{
...
}

myTxtFile thus contains

 Trevante Rhodes , André Holland , Janelle Monáe , Ashton...

I then open the .txt file using:

using (StreamReader sr = new StreamReader(mySourceFile, Encoding.GetEncoding("iso-8859-1")))
{
...
some processing to assign the data to XML nodes...
...
}

and finally create the XML file:

using (StreamWriter sw = new StreamWriter(xmlDataFilename, false, Encoding.GetEncoding("utf-8"))) 
{
...
myXMLObject.outerXml
...
}

which produces this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<productRequest>
    <attribute name="Actors"> Trevante Rhodes , André Holland , Janelle Monáe , Ashton...</attribute>
</productRequest>

MORE INFO 2

The answer to the search and replace question lies here

err1
  • 499
  • 9
  • 22
  • 1
    What encoding doe your xml specifiy? What encoding is it actually? What are you using to view the xml? – piet.t Jul 11 '17 at 11:34
  • The XML has this and to view the XML, I used Firefox. – err1 Jul 11 '17 at 11:55
  • Well, it seems Firefox does not honor the specified xml-encoding since from the look of it the special characters are actually encoded as UTF-8. Does the receiving application have any problems with the UTF-8 encoded special characters? If not then it is essentially a problem of your debugging tools (i.e. Firefox)... – piet.t Jul 11 '17 at 12:26
  • Open the XML file in visual studio. Does it still exhibit odd encoding? If not, that's just FF. If for some reason you have to support viewing xml documents in a web browser, then you'll need to encode the document for viewing, but not for storage in a file. –  Jul 11 '17 at 12:29
  • Good points, both. Will check. But why was I marked down for asking a reasonable question? Before I posted, I did do some research, and it's a problem that is genuinely stumping me. – err1 Jul 11 '17 at 12:37

0 Answers0