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. XSD.exe and Choice Elements.

XSD.exe and Choice Elements.

Scheduled Pinned Locked Moved XML / XSL
csharpxmljsonhelpannouncement
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.
  • C Offline
    C Offline
    craftyFella
    wrote on last edited by
    #1

    Given the following XSD File Sequence Choice Element Singular Item (Doesn't have to be a reference) Collection of Items (Must be a Reference) As you can see there is a **choice element ** which has a choice of either a singular Item or a collection of Items. When you use XSD.exe to create the classes in .net you get the following: /// [System.Xml.Serialization.XmlElementAttribute("Collection", typeof(Item[]))] [System.Xml.Serialization.XmlElementAttribute("Item", typeof(Item))] public object Item { get { return this.itemField; } set { this.itemField = value; } } So .NET xsd.exe recognises it’s a choice element and creates the Serialization correctly. The problem occurs when you try and create a “WebReference” to the web service in a client application. If you look at the reference.cs it has an incorrect version: /// [System.Xml.Serialization.XmlElementAttribute("Collection", typeof(ArrayOfItemItem[]))] [System.Xml.Serialization.XmlElementAttribute("Item", typeof(TestXSDResultItem))] public object Item { get { return this.itemField; } set { this.itemField = value; } } As a result if you try and consume the web service by setting the choice element to a collection and returning that through the WS back into the client application you’ll end up with an empty collec

    B C 2 Replies Last reply
    0
    • C craftyFella

      Given the following XSD File Sequence Choice Element Singular Item (Doesn't have to be a reference) Collection of Items (Must be a Reference) As you can see there is a **choice element ** which has a choice of either a singular Item or a collection of Items. When you use XSD.exe to create the classes in .net you get the following: /// [System.Xml.Serialization.XmlElementAttribute("Collection", typeof(Item[]))] [System.Xml.Serialization.XmlElementAttribute("Item", typeof(Item))] public object Item { get { return this.itemField; } set { this.itemField = value; } } So .NET xsd.exe recognises it’s a choice element and creates the Serialization correctly. The problem occurs when you try and create a “WebReference” to the web service in a client application. If you look at the reference.cs it has an incorrect version: /// [System.Xml.Serialization.XmlElementAttribute("Collection", typeof(ArrayOfItemItem[]))] [System.Xml.Serialization.XmlElementAttribute("Item", typeof(TestXSDResultItem))] public object Item { get { return this.itemField; } set { this.itemField = value; } } As a result if you try and consume the web service by setting the choice element to a collection and returning that through the WS back into the client application you’ll end up with an empty collec

      B Offline
      B Offline
      BoneSoft
      wrote on last edited by
      #2

      I'm not sure off hand from your description if this will help or not, but I have a tool that builds code from XSD, but in the case of a Choice, I generate a property for each choice on the class. The code generated is XML serializable. You might want to grab a copy of the trial and see if it does what you need. You can try it on-line here[^], or you can download the trial here[^] Hope that helps.


      Try code model generation tools at BoneSoft.com.

      1 Reply Last reply
      0
      • C craftyFella

        Given the following XSD File Sequence Choice Element Singular Item (Doesn't have to be a reference) Collection of Items (Must be a Reference) As you can see there is a **choice element ** which has a choice of either a singular Item or a collection of Items. When you use XSD.exe to create the classes in .net you get the following: /// [System.Xml.Serialization.XmlElementAttribute("Collection", typeof(Item[]))] [System.Xml.Serialization.XmlElementAttribute("Item", typeof(Item))] public object Item { get { return this.itemField; } set { this.itemField = value; } } So .NET xsd.exe recognises it’s a choice element and creates the Serialization correctly. The problem occurs when you try and create a “WebReference” to the web service in a client application. If you look at the reference.cs it has an incorrect version: /// [System.Xml.Serialization.XmlElementAttribute("Collection", typeof(ArrayOfItemItem[]))] [System.Xml.Serialization.XmlElementAttribute("Item", typeof(TestXSDResultItem))] public object Item { get { return this.itemField; } set { this.itemField = value; } } As a result if you try and consume the web service by setting the choice element to a collection and returning that through the WS back into the client application you’ll end up with an empty collec

        C Offline
        C Offline
        craftyFella
        wrote on last edited by
        #3

        Got a fix from Microsoft in the end. Horah! FIX: A deserialized object may contain null objects when you deserialize an object from XML in the .NET Framework 2.0 http://support.microsoft.com/kb/918298

        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