How to ignore the attribute [XMLIgnore]

I am trying to serialize some objects derived from a third-party .NET Lib into an XML file.

When I Go To Definition for an object, some of the properties of this object are marked as [XMLIgnore]

Is there a way to tell my System.Xml.Serialization.XmlSerializer ignore the fact that some properties have this attribute and that it should serialize everything in the object.

I could probably get the source code and recompile it without XMLIgnore attributes, but it would be nice if the XmlSerializer had some nice override property like

 XmlSerializer xmls = new XmlSerializer( typeof(MyObject), Settings.DoNotApplyXMLAttributeRules ); 

Thanks in advance


EDIT

They tried XmlAttributeOverrides, as suggested, but did not experience much joy. Here is the definition of the object (it is from the FlickrAPI for the photo)

 [Serializable] public class Photo { //Some code omitted [XmlIgnore] public string LargeUrl { get; } } 

And heres the serializer code that I wrote ... still doesn't work ...

 XmlWriter xtw = XmlWriter.Create( Server.MapPath("~/App_Data/Data.xml") ); XmlAttributes photoAttributes = new XmlAttributes(); photoAttributes.XmlIgnore = false; XmlAttributeOverrides photoOverrides = new XmlAttributeOverrides(); photoOverrides.Add(typeof(Photo), "LargeUrl", photoAttributes); XmlSerializer xmlphoto = new XmlSerializer(typeof(Photo), photoOverrides); 
+6
c # xml xml-serialization
source share
1 answer

use:

 XmlAttributeOverrides 

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

Edit: (After an EDIT question)

the property must be public and have a getter and setter selector.

http://msdn.microsoft.com/en-us/library/182eeyhh%28VS.85%29.aspx

((see first note))

+12
source share

All Articles