• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1210
  • Last Modified:

XmlElement

public class NewSTBLog
      {
            [XmlElement(ElementName = "LogBatch")]
            public NewLogBatch STBLogBatch;

            [XmlElement(typeof(LogRecord))]      
            public object[] LogRecords;
      }  


      //Structure of the Batch
      public class NewLogBatch
      {
            [XmlIgnore()]
            public char MSFTVersion;

            [XmlIgnore()]
            public char DeviceSerialNumLen;
            public string DeviceSerialNum;
            public char BatchNumber;
            public string LogInitTime;

            [XmlIgnore()]
            public char AccessPointIdLen;  
            public string AccessPointId;                        
            public string EndLogTime;

            [XmlIgnore()]
            public short NumRecordsStored;      
      }               

          
      //Structure of the Log Records
      public class NewLogRecord
      {
            [XmlIgnore()]
            public int LogType;             
                    
            [XmlElement(typeof(ADClicks)), XmlElement(typeof(ADDisplays)), XmlElement(typeof(NewApplicationLogs))]      
            [XmlElement(typeof(AppPermissionViolations)), XmlElement(typeof(BoxPower)), XmlElement(typeof(DVR))]
            [XmlElement(typeof(GamePlay)), XmlElement(typeof(MenuClick)), XmlElement(typeof(MenuView)), XmlElement(typeof(TVView))]  
            public object oActivityLogs;  
      }                                    

At one point XmlElement(ElementName=LogBatch) used and else where typeof is used in XmlElement ... what does that mean ? cant i use both element name and type of in one XmlElement attribute ? whats the difference in the use of the 2 ?

Please explain !!!
0
deersuper
Asked:
deersuper
1 Solution
 
anyoneisCommented:
If you don't use "ElementName=xxx", then the field name will be used. In the cases where you are using typeof, you are essentially describing a collection of possible types that can be found in oActivityLogs.

Here is a pretty good basic example: http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute.type.aspx

David
0
 
devsolnsCommented:
Look at is IXmlSerializable.  Its official for use in .NET 2.0 and it leads to a much better class design than anything attribute based.  IXmlSerializable will allow public/protected/private members to be serialized.


-gp
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now