XML文档(2,2)中存在错误. [英] There is an error in XML document (2, 2).

查看:121
本文介绍了XML文档(2,2)中存在错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?xml version="1.0" encoding="UTF-8"?>
<Address xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <FirstName>4</FirstName>
  <FamilyName>4</FamilyName>
  <UserLevel>عاد?</UserLevel>
  <Password>4</Password>
</Address>

Addresses =(AddressBook) SerializableData.Load(DataFileName,typeof(AddressBook));

""""""""""DataFileName is AddressBook.xml""""""""


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




我有这个问题,我解决不了.堆栈跟踪:




I have this problem and I cant solve it. Stack trace :

at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)\r\n<br />
at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)\r\n<br />
at AddressBook.Module.SerializableData.Load(Stream stream, Type newType) in C:\\ExCs\\ExCs\\Classes\\SerializableData.cs:line 38\r\n<br />
 at AddressBook.Module.SerializableData.Load(String filename, Type newType) in C:\\ExCs\\ExCs\\Classes\\SerializableData.cs:line 28\r\n<br />
 at ExCs.UserManager.UserManager_Load_1(Object sender, EventArgs e) in C:\\ExCs\\ExCs\\Modules\\UserManager.cs:line 214\r\n<br />
at System.Windows.Forms.UserControl.OnLoad(EventArgs e)\r\n<br />
at System.Windows.Forms.UserControl.OnCreateControl()\r\n<br />
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n<br />
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n<br />
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n<br />
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)\r\n<br />
at System.Windows.Forms.Control.CreateControl()\r\n   at System.Windows.Forms.Control.WmShowWindow(Message& m)\r\n   at System.Windows.Forms.Control.WndProc(Message& m)\r\n   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n<br />
at System.Windows.Forms.ContainerControl.WndProc(Message& m)\r\n<br />
at System.Windows.Forms.Form.WmShowWindow(Message& m)\r\n   at System.Windows.Forms.Form.WndProc(Message& m)\r\n   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n<br />
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n<br />
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)\r\n<br />
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)\r\n<br />
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)\r\n<br />
at System.Windows.Forms.Control.set_Visible(Boolean value)\r\n<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.Run(Form mainForm)\r\n<br />
at ExCs.Program.Main() in C:\\ExCs\\ExCs\\Classes\\Program.cs:line 18\r\n<br />
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n<br />
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n<br />
at System.Threading.ThreadHelper.ThreadStart()"

推荐答案

为我以前的错误假设道歉.

Apologies for my previous incorrect assumption.

Addresses =(AddressBook) SerializableData.Load(DataFileName,typeof(AddressBook));


您正在尝试加载AddressBook类型,但是XML包含一个Address元素,因此它不匹配.


You are trying to load a type of AddressBook but the XML contains an element that is an Address so it does not match.


这篇关于XML文档(2,2)中存在错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆