Linq to XML - trying to print infinity character

I am using Linq to XML for some HTML output files. I need to put the infinity symbol ( ∞

) in the output code in some table cells. I am creating an XElement like this

var table = new XElement("table",
            new XElement("tr",
                new XElement("td", "∞")
            )
        );

      

var document = new XDocument (table); document.Save (MyFile);

and when the file is saved I can't see ∞

, I see instead &#8734

. How can I prevent this transfer?

+2


source to share


1 answer


LINQ to XML does the right thing - it assumes that when you give it a string as content, that's the content you want to see. It eludes you. You really do not want to run each <

, >

and &

independently.

What you need to do is provide it with the actual content you want - this is the infinity symbol. So try this:

var table = new XElement("table",
            new XElement("tr",
                new XElement("td", "\u8734")
            )
        );

      



This may not end up exiting as an object in the output file, but only the encoded character, but that should be fine if you don't have any encoding issues.

EDIT: I just checked and the infinity symbol is actually U + 221E, so you want "\ u221e". I cannot see what U + 8734 means ... it cannot be defined in Unicode at the moment.

+5


source







All Articles