Undefined XML Parsing Entity & Exception

I am trying to identify non breaking space entityin an ad <!doctype />. The code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ENTITY nbsp "&#x00A0;"> ] />

 <html xmlns="http://www.w3.org/1999/xhtml">
  .. .... 

But still, when I create an XDocument object from the above document, I get an exception

Undefined entity &nbsp. 

What am I doing wrong?

+5
source share
2 answers

Firstly, a combination of external and internal objects is "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ENTITY nbsp "&#x00A0;"> ]not needed, because it http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdincludes www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent, which includes <!ENTITY nbsp "&#160;">, which is exactly the same as yours.

So the bit should only be:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Secondly, XDocument does not check DTD by default. However, you can Loadwith XmlValidatingReaderor XmlTextReaderwith the appropriate settings

If possible, [ , !], XmlReader XmlPreloadedResolver, W3C URI DTD .ent , , , ( " ", , , ). , .

+3

&#160;.

+9

All Articles