Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 serializer = 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,

like image 817
Klaus Nji Avatar asked Jun 29 '26 21:06

Klaus Nji


1 Answers

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.

like image 59
Kris Krause Avatar answered Jul 01 '26 19:07

Kris Krause



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!