0

**This is for silverlight application.

I have a stream with xml data, which after loading massage the data and generate final file. I start by load using XDocument.Load(stream). One of the file was failing to load and after some research I foung out that one of the element has a value of 'First & Second' and load fails on hitting &.

Is it possible to load XML with special characters? ( I am sure the answer is no, but worth asking).

Is it possible to preprocess the XML (without performance hit) and change the special characters to someother characters and after the process put it back to normal value.

svick
  • 236,525
  • 50
  • 385
  • 514
Nair
  • 7,438
  • 10
  • 41
  • 69
  • I am able to resolve it by reading the stream before loading the data in XDocument and check for & and add CDATA using the following link http://www.w3schools.com/xml/xml_cdata.asp – Nair Jun 10 '10 at 21:10
  • There are related questions on SO - http://stackoverflow.com/questions/121511/reading-xml-with-an-into-c-xmldocument-object - http://stackoverflow.com/questions/996552/c-parse-malformed-xml – Jonas Van der Aa Jun 10 '10 at 20:13

1 Answers1

2

In XML, & should be & otherwise it's not valid XML. If you don't have control over the XML files, load them as text, replace & with & in memory (but be careful not to replace the & that are part of entities like existing & > or < !) and load them as XML again.

Jens Kloster
  • 11,099
  • 5
  • 40
  • 54
Julien Lebosquain
  • 40,639
  • 8
  • 105
  • 117