Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 9th, 2007, 09:27 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSD.EXE Gen’d C# Deserializing w/ .xsd Subst Group

Hi,

I am trying to figure out how to get XSD.EXE (when generating C# classes from an .xsd) to add the XmlArrayItemAttribute Deserization Annotations to my C# generated class output: My specific case is when the .xsd has an element that holds an array of substitutionGroup'ed items.

Following is an example of a matching set of xsd, xml, xsd.exe command to generate C#, and the output C#.

When running a unit-test on the C#, the serialization only populates correctly if I manually add the following XmlArrayItemAttributes to the generated C# (directly below, and in complete context in the code block later in this post).

Can anyone make a suggestion of how to make XSD.EXE add these annotations (or another method of having this deserialize correctly)?

Thanks!

******MANUALLY ADDED XmlArrayItemAttribute ANNOTATIONS****** (see below Code Block for complete context)
[System.Xml.Serialization.XmlArrayItemAttribute("El ephant", typeof(ElephantType))]
[System.Xml.Serialization.XmlArrayItemAttribute("Ti ger", typeof(TigerType))]
[System.Xml.Serialization.XmlArrayItemAttribute("Mo nkey", typeof(MonkeyType))]
public AnimalAbstractType[] Animals {
get {
return this.animalsField;
}
...



*******ANIMAL.XSD********
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="Zoo" type="ZooType"/>
  <xs:complexType name="ZooType">
    <xs:sequence>
      <xs:element name="Animals" type="AnimalsType" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="AnimalsType">
    <xs:sequence>
      <xs:element ref="Animal" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
  <xs:element name="Animal" type="AnimalAbstractType" abstract="true"/>
  <xs:element name="Monkey" substitutionGroup="Animal" type="MonkeyType"/>
  <xs:element name="Tiger" substitutionGroup="Animal" type="TigerType"/>
  <xs:element name="Elephant" substitutionGroup="Animal" type="ElephantType"/>
  <xs:complexType name="AnimalAbstractType">
    <xs:sequence>
      <xs:element name="Name" type="xs:string" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="MonkeyType">
    <xs:complexContent>
      <xs:extension base="AnimalAbstractType">
        <xs:sequence>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <xs:complexType name="TigerType">
    <xs:complexContent>
      <xs:extension base="AnimalAbstractType">
        <xs:sequence>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <xs:complexType name="ElephantType">
    <xs:complexContent>
      <xs:extension base="AnimalAbstractType">
        <xs:sequence>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>


*******ANIMAL.XML********
<Zoo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Source\Pear\Prot otype\ImportExport\ImportExport\Animal.xsd">
<Animals>
<Monkey>
<Name>Curious George</Name>
</Monkey>
<Tiger>
<Name>Tigger</Name>
</Tiger>
<Elephant>
<Name>Dumbo</Name>
</Elephant>
</Animals>
</Zoo>

*******ANIMAL.BAT********
xsd /classes /language:cs Animal.xsd /namespace:Rayrew.Pear.ImportExport.Xml


*******ANIMAL.CS********
//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:2.0.50727.832
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
//------------------------------------------------------------------------------
//
// This source code was auto-generated by xsd, Version=2.0.50727.42.
//
namespace Rayrew.Pear.ImportExport.Xml {
using System.Xml.Serialization;
///
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlRootAttribute("Zoo", Namespace="", IsNullable=false)]
public partial class ZooType {
private AnimalAbstractType[] animalsField;
///
[System.Xml.Serialization.XmlArrayItemAttribute("An imal", IsNullable = false)]
/* BEGIN MANUALLY ADDED */
[System.Xml.Serialization.XmlArrayItemAttribute("El ephant", typeof(ElephantType))]
[System.Xml.Serialization.XmlArrayItemAttribute("Ti ger", typeof(TigerType))]
[System.Xml.Serialization.XmlArrayItemAttribute("Mo nkey", typeof(MonkeyType))]
/* END MANUALLY ADDED */
public AnimalAbstractType[] Animals {
get {
return this.animalsField;
}
set {
this.animalsField = value;
}
}
}
///
[System.Xml.Serialization.XmlIncludeAttribute(typeo f(ElephantType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeo f(TigerType))]
[System.Xml.Serialization.XmlIncludeAttribute(typeo f(MonkeyType))]
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
public partial class AnimalAbstractType {
private string nameField;
///
public string Name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
}
///
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlRootAttribute("Monkey" , Namespace="", IsNullable=false)]
public partial class MonkeyType : AnimalAbstractType {
}
///
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlRootAttribute("Tiger", Namespace="", IsNullable=false)]
public partial class TigerType : AnimalAbstractType {
}
///
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("c ode")]
[System.Xml.Serialization.XmlRootAttribute("Elephan t", Namespace="", IsNullable=false)]
public partial class ElephantType : AnimalAbstractType {
}
}




Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSD to WSDL sIldefonso XSLT 1 August 6th, 2007 08:57 AM
XSD JonDeNoitaly BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 May 7th, 2007 08:32 AM
xsd question kgoldvas XML 3 May 4th, 2006 03:14 AM
Merging XSD files in one XSD file by using what? haoxuqian XML 1 November 4th, 2005 01:42 PM
xsd:restriction zas XML 0 November 1st, 2005 10:43 PM



All times are GMT -4. The time now is 07:46 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.