Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ampersand in XML data not allowing to load xml

Tags:

c#

.net

xml

i am using a web service which is retrieving me xml, which contains lots of url. i am using below code to load it:

XmlDocument xdoc = new XmlDocument();
xdoc.Load(fileName.Trim());

its not able to load my xml if any ampersand exists in any element's content. my xml is like:

<media:thumbnail url="http://someurl/player/mezzanine/image.php?w=124&h=99&path=ndtv/a79d98c3030c041e0033105943c1b668_mezzn.jpg&hash=23991c2513a8e359d120840e6f897d4d" width="124" height="70" />
<media:fullimage url="" width="350" height="196" />

NOTE: i can't do changes in web service, as i am getting this from other provider. please help me. Thanks

i am getting this exception:

System.Xml.XmlException: '=' is an unexpected token. The expected token is ';'. Line 753, position 89.

on this row

<media:thumbnail url="http://someurl/player/mezzanine/image.php?w=124&h=99&path=ndtv/a79d98c3030c041e0033105943c1b668_mezzn.jpg&hash=23991c2513a8e359d120840e6f897d4d" width="124" height="70" />
like image 966
Dr. Rajesh Rolen Avatar asked Nov 19 '25 00:11

Dr. Rajesh Rolen


2 Answers

If you can't get the provider to fix their "XML", then the easiest thing to do is run it through a utility, such as Tidy .NET, which attempt to compensate for those sorts of issues and return a well-formed XML file that you can process.

like image 102
Mads Hansen Avatar answered Nov 20 '25 14:11

Mads Hansen


Replace each & in url with &amp;

like image 44
abatishchev Avatar answered Nov 20 '25 15:11

abatishchev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!