Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

defining objects with xml/schema

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jarlaxle - 13 Mar 2008 16:57 GMT
This is more of wanting to get some opinions and if anyone has run into the
same design issue.

I need to have about a hundred c# classes that simply represent an object
and contain data (no methods).  These objects will be modified pretty often
by alot of different people and need to be serialized/deserialized to binary
and xml.

I basically have three options:

1.  write the classes in c#
2.  represent the classes in xml and auto-generate them
3.  represent the classes in xsd and auto-generate them

option 1 can be done but gets very reptitive and messy when there are many
sub-objects.
option 2 gives a very clear representation of the object and is easy for
other people to modify/add new fields, however does not contain enough data
to distinguish the types that are generated (data type, array, etc.).
option 3 does the job but is so hard to visualize and maintain/modify and
will be hard for other people who don't have a grasp of xsd schema.  plus xsd
schema is really to represent xml and not a programmable object.

I was thinking of representing my object with a hybrid of xml and xsd and
having a custom generator like xsd.exe create the c# objects.  an object
could look like this...

<myobject>
 <item1>xs:type=boolean</item1>
 <item2 myattr1="xs:type=dateTime">xs:type=string</item2>
 <item3>
     <item4 xs:array>xs:type=mytype</item4>
 </item3>

something like that...of course "xs:" could be something different but
indicates a code generator option.  it would produce somethig like...

class  myobject
{
   public bool item1 {get; set;}
   public item2Object {get;set;}
   public item3Object {get;set;}

   public class item2Object
   {
       [XmlAttribute]
       public bool myattr1 {get; set;}

       [XmlText]
       public string Value {get;set;}
   }
   public class item3Object
   {
       public List<mytype> item4 {get; set;}
   }
}

I think that would give a good flexible way of generating objects that could
be easily maintained and easily compared for backward compatibility problems.

any thoughts?
parez - 13 Mar 2008 17:24 GMT
On Mar 13, 11:57 am, Jarlaxle <Jarla...@discussions.microsoft.com>
wrote:
> This is more of wanting to get some opinions and if anyone has run into the
> same design issue.
[quoted text clipped - 58 lines]
>
> any thoughts?

Let me start of by saying that i am not an expert..

I was in a similar situation. I started off with with option 3, spend
some time writing a custom code generator (i had some speacial
requirements)  and then i switched to option.

The reason I switched was becuase
1)I am more comforable writing c# code than xsd.
2) I was NOT going to use the XSD  for validation on my end or  the
server end.
3)I mite end up using the a code generator like codesmith to generate
the remaining classes from the DB schema.
4) my boss asked me.
parez - 13 Mar 2008 17:29 GMT
> On Mar 13, 11:57 am, Jarlaxle <Jarla...@discussions.microsoft.com>
> wrote:
[quoted text clipped - 75 lines]
> the remaining classes from the DB schema.
> 4) my boss asked me.

Correction..
spent time
switched to option 1
Jarlaxle - 13 Mar 2008 17:48 GMT
i just think seeing the object in a compact tree structure like xml helps in
visualizing the component, easier to make changes and coud save time.

obviously this is accepted since there are tools like xsd.exe and
xsdobjgen.exe  I think it just lacks the ability to specify details.

> > On Mar 13, 11:57 am, Jarlaxle <Jarla...@discussions.microsoft.com>
> > wrote:
[quoted text clipped - 79 lines]
> spent time
> switched to option 1
Joseph Daigle - 13 Mar 2008 17:39 GMT
I've used XSD.exe to generate code for a few smaller scale XML projects, and
it has served me quite well. Obviously the hardest part is properly creating
the schema such that it produces sane-looking XML sane-functioning classes
from the tool.

As a starting point you can also use XSD.exe to infer and a schema from a
supplied XML file. From there you can seperate out your classes, and then
generate the C#.

Some ideas.

Signature

Joseph Daigle

> This is more of wanting to get some opinions and if anyone has run into
> the
[quoted text clipped - 64 lines]
>
> any thoughts?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.