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 / .NET Framework / XML / November 2003

Tip: Looking for answers? Try searching our database.

xsd.exe and the resulting cs classes.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Iain - 26 Nov 2003 19:46 GMT
I'm embarking on a c# based project in which I would like to make use of a
lot of XML including database access and using hte xml and .net tools as  a
coding shortcut.

What I'm trying to understand at the moment is how to use xsd.exe and result
.cs files to mange the xml.

First question.

My XSD includes <sequence>s which have > 1 value.  the cs produced renders
this as a single instance, though if I change this to an array (manually)
the deserialization works as expected (nice!).  How can I tell xsd it SHOULD
be an array (I've tried setting maxOccurs, but this seems to make no
difference).

Second question.

I want some of the attributes (and elements for that matter) to be
mandatory.  Specifically, I would like an exception to be throw during
deserialisation (oops sorry about the 's' chaps - I speak British English as
a first tongue - the 'z' thing takes some getting used to!) if an attribute
is not present.  How do I do this?

Equally, I would like an exception thrown if an attribute or element NOT
specified in the XSD occurs.

In both cases, I'm kind of hoping I can do it without having to make
post-xsd.exe changes to the source.

Look forward to feedback!

iain
Dino Chiesa [Microsoft] - 27 Nov 2003 01:59 GMT
xsd makes an array when you have maxOccurs="unbounded", eg passing the
following xsd into xsd.exe  gives me an array:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" id="Ionic">
 <xs:complexType name="Root">
   <xs:sequence>
     <xs:element name="Stamp" maxOccurs="unbounded" type="xs:date"/>
   </xs:sequence>
 </xs:complexType>
 <xs:element name="Something" type="Root"/>
</xs:schema>

For Q2, when deserializing, pass the Deserialize() method an instance of
XmlValidatingReader.

Here is an example:

XmlReader xr = new XmlTextReader(fileName);
XmlValidatingReader vr = new XmlValidatingReader(xr);
vr.Schemas.Add("urn:example-org:person", "person.xsd");
Person p = (Person)ser.Deserialize(vr);

ref:
http://msdn.microsoft.com/msdnmag/issues/02/11/XMLFiles/default.aspx

-Dino

Signature

Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m

> I'm embarking on a c# based project in which I would like to make use of a
> lot of XML including database access and using hte xml and .net tools as  a
[quoted text clipped - 28 lines]
>
> iain
Iain - 27 Nov 2003 09:51 GMT
Thank you very much.

I had a maxOccurs, but in the wrong place (I'm still getting to grips with
xsd - it's one of those things that sounds obvious, but turns out to be VERY
complicated in detail!).

And the other trick is exactly what I'm looking for!

Iain
> xsd makes an array when you have maxOccurs="unbounded", eg passing the
> following xsd into xsd.exe  gives me an array:
[quoted text clipped - 61 lines]
> >
> > iain

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.