简体   繁体   English

XmlSerializer不遵守默认名称空间?

[英]XmlSerializer not observing default namespace?

I have this class: 我有这个课:

 [Serializable]   
    public class Element 
    {
        [XmlAttribute("maxOccurs")]
        public int MaxOccurs{get; set;}
        [XmlAttribute("minOccurs")]
        public int MinOCcurs{get; set;}
        [XmlAttribute("name")]
        public string Name{get; set;}
        [XmlAttribute("nillable")]
        public bool IsNillable{get; set;}
        [XmlAttribute("type")]
        public string Type{get; set;}

    }

I have created an XmlSerializer like so: 我已经创建了一个XmlSerializer,如下所示:

XmlSerializer serializer = new XmlSerializer(elementType, "http://www.w3.org/2001/XMLSchema");

When I attemp to deserialize this sample XML 当我尝试反序列化此示例XML

http://www.w3.org/2001/XMLSchema\\" /> http://www.w3.org/2001/XMLSchema \\“ />

I get the following exception message: 我收到以下异常消息:

{"http://www.w3.org/2001/XMLSchema'> was not expected."} {“ http://www.w3.org/2001/XMLSchema'>不是预期的。”}

What did I miss ? 我错过了什么 ?

TIA, TIA,

Check out the XmlSerializer constructor - 查看XmlSerializer构造函数-

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.xmlserializer.aspx http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.xmlserializer.aspx

You will want to pass in "your" namespace, not the w3c namespace. 您将要传入“您的”命名空间,而不是w3c命名空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM