Jyina
Jyina

Reputation: 2892

Is it possible to escape & while loading xml?

I have an & character in one of the xml nodes as below.

<dependents>9 & 5</dependents>

When I try to load the file as below, it is giving an error "An error occured while parsing EntityName.". Is it possible to escape this character and load successfully? Thank you.

 m_InputXMLDoc = new XmlDocument();
        if (System.IO.File.Exists(InputFile))
        {
            m_InputXMLDoc.Load(InputFile);
        }

Upvotes: 1

Views: 150

Answers (2)

SLaks
SLaks

Reputation: 887195

Your XML is invalid.
You need to change it to &amp;.

Upvotes: 6

TheGeekYouNeed
TheGeekYouNeed

Reputation: 7539

Use a CDATA section

<dependents><![CDATA[9 & 5]]></dependents>

Upvotes: 6

Related Questions