开发者

xml deserialization problem

i have a problem when i trying to use XmlSerializer to deserialize an xml file into a class i made myself, the xml file content is :

<UserInfoView xmlns="http://schemas.datacontract.org/2004/07/iEverydayLog.Models.ViewModel" 
              xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

    <Address>Ultimo NSW</Address>

    <Id>685c7109-56c5-4a69-82d6-c9a286225d7e</Id>

    <Name>Tester Name</Name>

    <NumberOfCards>1</NumberOfCards>

</UserInfoView>

it failed with this message : There is an error in XML document (1, 2).

but when i remove these words:

xmlns="http://schemas.datacontract.org/2004/07/iEverydayLog.Models.ViewModel"     xmlns:i="h开发者_如何学Pythonttp://www.w3.org/2001/XMLSchema-instance"

it works ok, does any one know what happens here?

my class is defined like this:

    public class UserInfoView
    {
        public string Address;

        public string Name;

        public string Id;

        public int NumberOfCards;
    }


There is a default xml namespace; you can fix this by adding [XmlRoot] to tell it the namespace to expect:

[XmlRoot(Namespace="http://schemas.datacontract.org/2004/07/iEverydayLog.Models.ViewModel")]
public class UserInfoView {...}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜