Elias Ghali
Elias Ghali

Reputation: 853

XmlTextReader An error occurred while parsing EntityName c#

I am trying to read an XML file containing special characters:

<measValue measObjLdn="SSar-Oil-&-Gas, 564DC5">
     <measResults>1 0 0 100 0 1 </measResults>
</measValue>

Using the below logic, where stream is coming from an xml file:

        using (var xr = new XmlTextReader(stream))
        {
            xr.Namespaces = (NamespaceManager != null);
            xr.DtdProcessing = DtdProcessing.Ignore;

            while (xr.Read())
            {
                if (xr.NodeType == XmlNodeType.Element && arrTag.Contains(xr.Name))
                {
                    var node = (XElement)XNode.ReadFrom(xr);
                    yield return node;
                }
            }
            xr.Close();
        }

However it's throwing an error with the below error

An error occurred while parsing EntityName

I know the "&" isn't a valid character, but I'm not generating the file, is there any way to ignore these special characters?

Upvotes: 0

Views: 199

Answers (0)

Related Questions