Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XML Serialization producing empty element when class has attributes

XML Serialization producing empty element when class has attributes

Scheduled Pinned Locked Moved XML / XSL
data-structuresxmljsonquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rob_ICS
    wrote on last edited by
    #1

    I'm trying to serialise a graph structure to XML. Everything is working fine except for one object which is alwasy coming out as an empty element. Even if I serialise it on its own. Its the most important object as it represents the link. Any idea why it wouldn't show any attributes? Heres the code: [Serializable()] [System.Xml.Serialization.XmlInclude(typeof(ParticipantNode))] public class EdgeToNeighbour { #region Private Member Variables private string id; private Node neighbour; #endregion #region Constructors public EdgeToNeighbour() { } public EdgeToNeighbour(Node neighbour) { this.neighbour = neighbour; this.id = neighbour.Key; } #endregion #region Properties /// /// The neighbour the edge is linking to. /// public Node Neighbour { get { return neighbour; } } public string ID { get{return id;} } #endregion } I've tried ignoring the complex type, i've tried adding XML text, I've tried lots of different combinations of XmlAttribute etc. but i always end up with this: Serialised on its own: <EdgeToNeighbour xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> Serialised as part of the graph structure: <anyType xsi:type="Node"> <Data> <ID>2</ID> <TypeID>0</TypeID> <Name>A Node</Name> </Data> <Edges> <EdgeToNeighbour /> <EdgeToNeighbour /> </Edges> </anyType> All I want is for edge to neighbour object to show the attribute ID so I can see the nodes it is linked to. Thanks in advance. Rob.

    D 1 Reply Last reply
    0
    • R Rob_ICS

      I'm trying to serialise a graph structure to XML. Everything is working fine except for one object which is alwasy coming out as an empty element. Even if I serialise it on its own. Its the most important object as it represents the link. Any idea why it wouldn't show any attributes? Heres the code: [Serializable()] [System.Xml.Serialization.XmlInclude(typeof(ParticipantNode))] public class EdgeToNeighbour { #region Private Member Variables private string id; private Node neighbour; #endregion #region Constructors public EdgeToNeighbour() { } public EdgeToNeighbour(Node neighbour) { this.neighbour = neighbour; this.id = neighbour.Key; } #endregion #region Properties /// /// The neighbour the edge is linking to. /// public Node Neighbour { get { return neighbour; } } public string ID { get{return id;} } #endregion } I've tried ignoring the complex type, i've tried adding XML text, I've tried lots of different combinations of XmlAttribute etc. but i always end up with this: Serialised on its own: <EdgeToNeighbour xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> Serialised as part of the graph structure: <anyType xsi:type="Node"> <Data> <ID>2</ID> <TypeID>0</TypeID> <Name>A Node</Name> </Data> <Edges> <EdgeToNeighbour /> <EdgeToNeighbour /> </Edges> </anyType> All I want is for edge to neighbour object to show the attribute ID so I can see the nodes it is linked to. Thanks in advance. Rob.

      D Offline
      D Offline
      Dave Herren
      wrote on last edited by
      #2

      All of you properties are either private or read only. Only public read/write properties are serialized unless you implement the ISerializable interface(which lets you determine exactly how your class is serialized). -- modified at 20:58 Wednesday 23rd May, 2007

      topcoderjax - Remember, Google is your friend.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups