RE: Xml deserialization problem..help needed.



Ok....I got some more insight into the error and it says -
"The ']' character, hexadecimal value 0x5D, cannot begin with a name. Line
93, position 1765.
I also got -
"The '*' character, hexadecimal value 0x2A, cannot begin with a name.

I am going to try to google this out....

"Manish Bafna" wrote:

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: Non-ascii characters in VS.NET service
    ... method that takes a string parameter. ... How is it turning the character into hex? ... What do you mean by "an XML header"? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Illegal Charaters in path
    ... I am downloading this file using ... Stripping the first character solved the problem though. ... I have a small XML file, I uploaded to a web page. ... XmlDocument.Load doesn't have an overlaod that loads XML from a string. ...
    (microsoft.public.dotnet.languages.csharp)
  • 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: How to parse XML which contains & in the text ?
    ... "The ampersand character and the left angle bracket MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. ... bracket may be represented using the string ">", and MUST, for compatibility, be escaped using either ">" or a character reference when it appears in the string "]]>" in content, when that string is not marking the end of a CDATA section." ... You can't fix this in the DTD, the XML is invalid and the parser is correct to reject it. ...
    (comp.lang.java.programmer)
  • 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)