I am using C#(Vs.Net 2003)
The error I am getting is...
System.Xml.XmlException: This is an unexpected token. The expected token is
'EndElement'
I have come to understand that this error is being caused by a character or
set of characters...in the value of an xml element.
I am receiving the xml data basically via a webservice(I have no control
over this data).
I am deserializing the xml data into a c# class I have created. The
deserialization of the data was working great...until I received "bad" xml
data. I think the character is '&' or ' " '. I could be wrong but it is a
character or set of.....that is causing the error.
The code i am using is....
object obj = new object();
XmlSerializer xs = new XmlSerializer(type);
MemoryStream memoryStream = new
MemoryStream(StringToUTF8ByteArray(xmlstring));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
obj = xs.Deserialize(memoryStream); <--- The error occurs at this point...
I have also tried..
System.Xml.XmlDocument xml = new XmlDocument();
xml.LoadXml(xmlstring);<--- error at this point also...
Now!...I have been searching for a while...i gave up on it..and now i am
back on the search. I ended up here and was hoping that solutions I came
across would help...unfortunately...nothing. If ANYONE can help me with this
situation..i would be "Oooo So Greatful".
Soln I have tried: - Changing the class field types from string to
xmlelement that then referencing the data by the InnerText Property.
- I also tried a "formatXMLString" method I came across..and all that
happened was that the exception error was not occuring at the same point.
Exception error:There is an error in XML document (28, 132);
All I want to do is take a string of xmldata and deserialize it into a class.
I realise that when I output the string of xmldata onto a webpage it comes
up..formatted properly.
Thanks