开发者

XmlSerializer not observing default namespace?

开发者 https://www.devze.com 2022-12-17 02:59 出处:网络
I have this class: [Serializable] public class Element { [XmlAttribute(\"maxOccurs\")] public int MaxOccurs{get; set;}

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 serial开发者_JAVA百科izer = new XmlSerializer(elementType, "http://www.w3.org/2001/XMLSchema");

When I attemp to deserialize this sample XML

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

I get the following exception message:

{"http://www.w3.org/2001/XMLSchema'> was not expected."}

What did I miss ?

TIA,


Check out the XmlSerializer constructor -

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.

0

精彩评论

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