Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

c# - Error in XML document (2, 2)

when I am running this program, I am facing this error

  public static object Load(Stream stream,Type newType)
        {
      //create s serializer and load the object
     XmlSerializer serializer=new XmlSerializer(newType);
     object newobject =serializer.Deserialize(stream);
      //return the new object 
      return newobject;
         }

?xml version="1.0"?>
-<Address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <FirstName>ali </FirstName> <FamilyName>bradaran</FamilyName> <UserLevel>????</UserLevel> <Password>123</Password> </Address>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your problem is that there is an error in the XML document you are trying to read.

Open your XML document in Internet Explorer. If it is valid, it will display. If it is not, the error will be described and shown, which should help you track down the problem.

If the XML you posted is a genuine representation of what you're reading, there is a minus character and two semicolon characters that shouldn't be in the file. I'm also not sure you would want the xmlns attributes in your Address element?

I suggest you search for some XML tutorials on the web so you can get a better understanding of how XML must be formed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...