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. Class for deserializing array

Class for deserializing array

Scheduled Pinned Locked Moved XML / XSL
data-structuresxmljsontutorialquestion
3 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.
  • H Offline
    H Offline
    Howard Richards
    wrote on last edited by
    #1

    This is probably a "Doh!" moment... I had stored some values in an XML file thus: f1 f2 f3 f4 f1 f2 f3 f4 I wanted to deserialize these into into a class so I could enumerate each command, and then the string array of fields. Long story short is I got lost in the Xml.Serialization namespace attributes, and gave up. The root was easy, an [XmlRoot("Commands")] public class Commands which contained a Command array. However I could not figure out how to get the Command array to return an array of Field[] strings. Anything like public string Field[] would result in value In the end I gave up and rewrote the XML by adding an intermediate class Fields which I could prefix with [XmlArray("Fields"), XmlArrayItem("Field")].. f1 f2 f3 f4 f1 f2 f3 f4 But is there a way to achieve the original result?? 'Howard

    G 1 Reply Last reply
    0
    • H Howard Richards

      This is probably a "Doh!" moment... I had stored some values in an XML file thus: f1 f2 f3 f4 f1 f2 f3 f4 I wanted to deserialize these into into a class so I could enumerate each command, and then the string array of fields. Long story short is I got lost in the Xml.Serialization namespace attributes, and gave up. The root was easy, an [XmlRoot("Commands")] public class Commands which contained a Command array. However I could not figure out how to get the Command array to return an array of Field[] strings. Anything like public string Field[] would result in value In the end I gave up and rewrote the XML by adding an intermediate class Fields which I could prefix with [XmlArray("Fields"), XmlArrayItem("Field")].. f1 f2 f3 f4 f1 f2 f3 f4 But is there a way to achieve the original result?? 'Howard

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      There is no direct way to achieve the original: f1 f2 f3 f4 f1 f2 f3 f4 since each would be considered a stand-alone class field with the same name (which would be a syntax error). However, you can use XSLT to translate the deserialized format into the original format. "We make a living by what we get, we make a life by what we give." --Winston Churchill

      H 1 Reply Last reply
      0
      • G George L Jackson

        There is no direct way to achieve the original: f1 f2 f3 f4 f1 f2 f3 f4 since each would be considered a stand-alone class field with the same name (which would be a syntax error). However, you can use XSLT to translate the deserialized format into the original format. "We make a living by what we get, we make a life by what we give." --Winston Churchill

        H Offline
        H Offline
        Howard Richards
        wrote on last edited by
        #3

        Thanks - I sort of figured out that I must be doing it wrong as there did not seem to be a way to achieve it. So I wasn't missing something after all.

        'Howard

        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