title: Different behaviors between XmlDocument.LoadXml and XDocument.Parse
body: <p>Our project has been converted to use XDocument from XmlDocument few days ago, but we found a strange behavior while processing XML entity in attribute value with XDocument.Parse, the sample code as following:</p>
  
  <ol>
  <li><p>The XML string:</p>
  
  <p>string xml = @"&lt;char symbol=""&amp;#x0;"">";</p></li>
  <li><p>The XmlDocument.LoadXml code and result:</p>
  
  <pre><code>    XmlDocument xmlDocument = new XmlDocument();
      xmlDocument.LoadXml(xml);
      Console.WriteLine(xmlDocument.OuterXml);
  </code></pre>
  
  <p>Result:</p>
  
  <p>&lt;char symbol="&amp;#x0;" /></p></li>
  <li><p>The XDocument.Parse code and exception:</p>
  
  <pre><code>    XDocument xDocument = XDocument.Parse(xml);
      Console.WriteLine(xDocument.ToString());
  </code></pre>
  
  <p>Exception:</p>
  
  <p>A first chance exception of type 'System.Xml.XmlException' occurred in System.Xml.dll
  <strong>'.', hexadecimal value 0x00, is an invalid character. Line 1, position 18.</strong>
     at System.Xml.XmlTextReaderImpl.Throw(Exception e)
     at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
     at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
     at System.Xml.XmlTextReaderImpl.ParseNumericCharRefInline(Int32 startPos, Boolean expand, StringBuilder internalSubsetBuilder, Int32&amp; charCount, EntityType&amp; entityType)
     at System.Xml.XmlTextReaderImpl.ParseNumericCharRef(Boolean expand, StringBuilder internalSubsetBuilder, EntityType&amp; entityType)
     at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32&amp; charRefEndPos)
     at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos, Char quoteChar, NodeData attr)
     at System.Xml.XmlTextReaderImpl.ParseAttributes()
     at System.Xml.XmlTextReaderImpl.ParseElement()
     at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
     at System.Xml.XmlTextReaderImpl.Read()
     at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
     at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options)
     at System.Xml.Linq.XDocument.Parse(String text)</p></li>
  </ol>
  
  <p>It seems that the "&amp;#x0;" is an invalid character, so we change the value to a valid character such as "&amp;#x60;" then both methods worked well.</p>
  
  <p>Is there any way to change the XDocument.Parse behavior to ignore the invalid character in attribute like XmlDocument.LoadXml does?</p>