473,378 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

XML serializatin vs. an XSD schema

Hi there,

I have a C# object heirarchy and an XSD document to which I wish to
match the serialized objects in that heirarchy. I have an abstract
parent class called "Test" which has no properties, and a set of
derived classed which implement specific functionality, for example
"TestUserOnline", "TestUserOnPC" etc. Each of these has properties
which correspond to the arguments of that operation. For example,
"TestUserOnline" has a "user" property, "TestUserOnPC" has a "user"
property and a "pc" property. I want these to serialise so that in the
xml these appear as a "Test" element, with a single element beneath it
for the specifics of this operation, like this

....
<Test>
<TestUserOnPc user="bob" pc="bobsPC"/>
</Test>
....

This is the way its done in the XSD file, and I'd like to get the XSD
file matching the output so I can use the XSD file to give me
intellisense when I'm writing XML to represent these objects.

I've used XMLInclude's for the types which I want to count as "Test"s,
and what I'm getting when I serilaize is this.

....
<Test xsi:type="TestUserOnPC" user="bob" pc="bobsPC"/>
....

Obv this isn't what I want, as I won't get any intellisense to give me
only "user" and "pc" on this type of test. So the question is, is
there anyway to use XML attributes etc. to serialize the objects into
the kind of form I want, or another form which would allow
intellisense?

Ta,
Steve.
Nov 12 '05 #1
1 2484
One way to do this is to infer the schema from a sample XML file.
you can do this with the xsd.exe utility.
It will generate and XSD from the sample XML you provide.
You can then iterate on the XSD, modifying it as you see fit.
Then serialize, and see if it works for you.

For example, running xsd.exe on the following xml file:
<Collection>
<Test>
<TestUserOnPc user="bob" pc="bobsPC"/>
</Test>
<Test>
<TestUserOnline user="mary"/>
</Test>
<Test>
<TestUserOnline user="bob"/>
</Test>
</Collection>
Gives me this xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Collection" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Collection" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="TestUserOnPc" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="user" type="xs:string" />
<xs:attribute name="pc" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="TestUserOnline" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="user" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
You can change maxOccurs, or change the targetnamespace, or ....
Given this XSD, you should be able to produce something that VS.NET can use
for Intellisense, as per
http://msdn.microsoft.com/library/en...ckgrounder.asp

http://staff.develop.com/candera/web...b-24113a9a8a58
-Dino
"Steve Morrell" <St***********@techprt.co.uk> wrote in message
news:3d**************************@posting.google.c om...
Hi there,

I have a C# object heirarchy and an XSD document to which I wish to
match the serialized objects in that heirarchy. I have an abstract
parent class called "Test" which has no properties, and a set of
derived classed which implement specific functionality, for example
"TestUserOnline", "TestUserOnPC" etc. Each of these has properties
which correspond to the arguments of that operation. For example,
"TestUserOnline" has a "user" property, "TestUserOnPC" has a "user"
property and a "pc" property. I want these to serialise so that in the
xml these appear as a "Test" element, with a single element beneath it
for the specifics of this operation, like this

...
<Test>
<TestUserOnPc user="bob" pc="bobsPC"/>
</Test>
...

This is the way its done in the XSD file, and I'd like to get the XSD
file matching the output so I can use the XSD file to give me
intellisense when I'm writing XML to represent these objects.

I've used XMLInclude's for the types which I want to count as "Test"s,
and what I'm getting when I serilaize is this.

...
<Test xsi:type="TestUserOnPC" user="bob" pc="bobsPC"/>
...

Obv this isn't what I want, as I won't get any intellisense to give me
only "user" and "pc" on this type of test. So the question is, is
there anyway to use XML attributes etc. to serialize the objects into
the kind of form I want, or another form which would allow
intellisense?

Ta,
Steve.

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: wooks | last post by:
<?xml version='1.0'?> <userlogin xmlns="urn:faster:userlogin" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> <login>mick</login> <password>brown</password> </userlogin> Above is my...
0
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > ...
6
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. ...
1
by: Hari Om | last post by:
Subject: XML Schema to XML Schema Conversion I have an XML Schema A which needs to mapped to another XML Schema B. Is there any handy tool which I could use to convert from Schema A to Schema B?...
4
by: Gordon Dickens | last post by:
I have target xml to generate from schema. All of the XML instances have the same global element i.e. <base>. I would like to combine all of the schemas into a single schema where I could...
2
by: Stanimir Stamenkov | last post by:
I'm trying to find out if it is permissible to include a schema document with absent target namespace to a schema with specified target namespace, and if it is, what are the rules to resolve the...
0
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
4
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set...
0
by: Derek | last post by:
I am creating an intranet using Visual Web Developer Express Edition. Everything has been working OK until yesterday when I started getting 62 messages all beginning "Could not find schema...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.