Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

XElement parser does not ignore entity tokens in attribute value

$
0
0

I have sample XML file:

<?xml version="1.0" encoding="UTF-8"?><root><name id="show_file.php?fid=120983&action=download" /></root>

I use simple C# console application to dump the content of this XML:

static void Main(string[] args)
{
    var xmlPath = @"c:\test.xml";
    var xml = XElement.Load(xmlPath);
    Console.WriteLine(xml.ToString());
}

However, an error occurs:

An unhandled exception of type 'System.Xml.XmlException' occurred in System.Xml.dll
Additional information: '=' is an unexpected token. The expected token is ';'

The error points to "=" sign here "&action=". I looked up the stack trace:

System.Xml.XmlException was unhandled
  HResult=-2146232000
  Message='=' is an unexpected token. The expected token is ';'. Line 67, position 93.
  Source=System.Xml
  LineNumber=67
  LinePosition=93
  SourceUri=""
  StackTrace:
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
       at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(String expectedToken1, String expectedToken2)
       at System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(Int32 pos, String expectedToken1, String expectedToken2)
       at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& 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.ParseElementContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
       at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
       at System.Xml.Linq.XElement.ReadElementFrom(XmlReader r, LoadOptions o)
       at System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options)
       at System.Xml.Linq.XElement.Parse(String text, LoadOptions options)
       at System.Xml.Linq.XElement.Parse(String text)
       at ConsoleApp.Program.Main(String[] args) in D:\Projects\ConsoleApp\Program.cs:line 21

The point of interest is System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos). As I understand, Xml searches for entity tokens in attribute value. But is it mandatory? I think I can store in attribute value ANY characters and their combinations as far as I use parenthesis. Am I right?


There is no knowledge that is not power.



Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>