title: Referencing external named character entities when using XmlReader?
body: <p>I want to reference an URL having character entities using C#/.NET on an <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreader(v=VS.90).aspx" rel="nofollow noreferrer">XmlReader</a> instance, for example <a href="http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent" rel="nofollow noreferrer">this w3c entity set</a> defining <code>&amp;nbsp;</code> and other chars.</p>
  
  <p>If I were to accomplish it in pure XML it would something like this, or a variation:<br>
  <code>&lt;!ENTITY foo SYSTEM "http://example.org/myent.ent"&gt;</code></p>
  
  <p>I'm actually <strong>reading fragments of XHTML</strong> source (containing named entities) and therefore need the XML 1.0/<a href="http://htmlhelp.com/reference/html40/entities/" rel="nofollow noreferrer">HTML 4</a> named <a href="http://www.w3.org/TR/xhtml1/#h-A2" rel="nofollow noreferrer">Entity Sets defined by w3c</a> to be defined/recognized.<br>
  ( I'm asking how to <em>programmatically</em> reference them on-the-fly while setting up the XmlReader and its Settings for reading fragments; however I'm open to options). </p>
  
  <p>Either way, if I don't include these named entities the reader will cough and produce .NET errors such as the following XmlException for <code>&amp;nbsp;</code> and other non-numeric entities:</p>
  
  <blockquote>
    <p>Test 'Xml_Tester.Test_Reading' failed:
    System.Xml.XmlException : Reference to
    undeclared entity 'nbsp'. Line 6,
    position 393.</p>
  </blockquote>
  
  <p><em>Note</em>: I'm successfully referencing an <a href="http://www.w3.org/TR/xhtml1-schema/#schemas" rel="nofollow noreferrer">XHTML Schema</a> using the <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.schemas.aspx" rel="nofollow noreferrer">XmlReaderSettings.Schemas</a> collection property, and assume there has to be an equally easy way to call in external entity references without modifying the XML source, but it evades me.</p>
  
  <hr>
  
  <h2>Etc:</h2>
  
  <p>I've come across the following significant info bits while searching for an answer -they're  likely useful here ...</p>
  
  <p><strong>Support for entities</strong><br>
  To use entities, authors have to use the DTD mechanism. See section 1.5 to use DTD and XML Schema together.
  -- <a href="http://www.w3.org/TR/xhtml1-schema/#diffs" rel="nofollow noreferrer">http://www.w3.org/TR/xhtml1-schema/#diffs</a></p>
  
  <p><strong>1.5. Using DTD and XML Schema together</strong><br>
  DTD validation and XML Schema validation are not mutually exclusive. Sometimes authors might want to use some DTD features (e.g. entities) while taking advantage of the XML Schema validation.
  -- <a href="http://www.w3.org/TR/xhtml1-schema/#together" rel="nofollow noreferrer">http://www.w3.org/TR/xhtml1-schema/#together</a></p>
  
  <p><strong>Combining XML Documents with XInclude</strong><br>
  External entities must be declared in a DTD or an internal subset. This opens a Pandora's Box full of implications, such as the fact that the document element must be named in Doctype declaration and that validating readers may require that the full content model of the document be defined in DTD among others.<br>
  -- <a href="http://msdn.microsoft.com/en-us/library/aa302291.aspx#xinc_topic1" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa302291.aspx#xinc_topic1</a></p>