I'm trying to load an XHTML document into an XDocument but I'm getting "reference to undeclared entity" exceptions thrown at me. I need to resolve entities like ®
and »
.
I believe my document is properly formed, here is the head:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
When I do an XDocument.Load(<StringReader>)
is when I'm getting these exceptions thrown.
I had the same problem as Dave and came across this question that helped me a lot. Based on Dave's answer and Pavel's suggestion for optimization I updated the class. Now the DTDs can be stored as embedded resources and loaded if necessary. I know this post is a few years old but maybe this can help someone.
Example usage:
LocalXhtmlXmlResolver class:
This is a collaboration of msdn and blog postings.