tim
tim

Reputation: 1369

How to embed special character in XML and have XDocument parse it

How to embed special character in XML and have XDocument parse it?

<?xml version="1.0" encoding="utf-8"?>
<Customers>
<Customer>
<CustomerID>BLAUS</CustomerID>
<CompanyName>Blauer See Delikatessen</CompanyName>
<ContactName>Hanna Moos</ContactName>
<Region>testing</Region>
</Customer>
<Customer>
<CustomerID>SPLIR</CustomerID>
<CompanyName>Split Rail Beer &#x25BA Ale</CompanyName>
<ContactName>Art raunschweiger</ContactName>
<Region>WY</Region>
</Customer>
</Customers>

Upvotes: 0

Views: 254

Answers (1)

Oded
Oded

Reputation: 499152

The file you posted is not valid XML which is why it will fail to parse.

The problem is in this line:

<CompanyName>Split Rail Beer &#x25BA Ale</CompanyName>

Which should be:

<CompanyName>Split Rail Beer &#x25BA; Ale</CompanyName>

A properly encoded numeric entity is &#x25BA; (note the trailing ;) - this translates to the character ►.

Upvotes: 2

Related Questions