RE: Xml deserialization problem..help needed.



Hi,
I think it is not special character that is causing your problem.Actually
the XML which you are receiving is malformed.Search in below link for
"System.Xml.XmlException: This is an unexpected token. Expected ‘EndElement’.
" and you will come to kmow more about this error.
http://media.techtarget.com/digitalguide/images/Misc/professionalVB_ch12.pdf.

Hope this helps
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"PierceBrosnan" wrote:

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

.



Relevant Pages

  • Re: Putting a "<" in an attribute value (was about CDATA sections)
    ... > are ambiguous (section 2.4 essentially says numeric character ... is a lawyer :-) XML has inherited these definitions with very few ... Once validity is established, an application will receive ... <!DOCTYPE header [ ...
    (comp.text.xml)
  • Re: Future of LISP. Alternative to XML. Web 3.0?
    ... I didn't realize it meant literally the cr character within the ... instead of XML representation for queries and responses. ... using s-expressions instead of XML, nobody is going to use it, ... Do *any* of those LISP projects have a server I ...
    (comp.lang.lisp)
  • RE: System.ArgumentException: Illegal characters in path
    ... But I don't use any xml string at all in my web ... It is a default data type string and I wonder it ... cannot accept latin character since string accepts all utf-8 characters. ... Microsoft XML 3.0 SP1 ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Suppressing character entity transformation
    ... I was gently chastizing Pavel for a minor stylistic point. ... When XSLT reads in a document, character references and entity references are expanded; when it writes the document back out as either XML or HTML, it should re-create character references where they're necessary. ... You really want to fix that, along the lines he illustrated (issuing actual elements rather than text that looks like tags) before you do anything else. ...
    (comp.text.xml)
  • Re: 2 Questions about validations
    ... in SGML any character that is not defined as a name character ... >>(But XML 1.0 always requires one or more white space characters there.) ... When I read the XML 1.0 spec, it made sense to me (well, perhaps the ... Considering what you get in the SGML parse tree in the end, ...
    (comp.infosystems.www.authoring.html)