473,320 Members | 2,080 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,320 software developers and data experts.

How can I get schema from a class/object at runtime

Hello all,

I have the following serializable class.
----------------------------------------------------------------------------
--
Public Class Test

_testID as int32
_testName as String

Public Sub New()
MyBase.New()
End Sub

<XmlAttributeAttribute()> Public Property TestID() As int32
Get
Return _testID
End Get
Set(ByVal Value As int32)
_testID= value
End Set
End Property

<XmlAttributeAttribute()> Public Property TestName() As String
Get
Return _testName
End Get
Set(ByVal Value As String)
_testName= value
End Set
End Property
End Class
----------------------------------------------------------------------------
-

I know I can use XSD.exe to build an XSD file from this class at design
time. But is their any way to build an XSD schema at runtime (in memroy)
based on my class.

I know I can use reflection to query the members of my objects and build my
schema, but I was hoping that there might me something in the .net framework
which can acomplish this more efficiently.

Thank you in advance for your help.

Reguards,
HJ Rodriguez
Nov 12 '05 #1
2 1942
Use the XmlSerializer class to serialize the object to XML, load that into a
DataSet and then call InferXmlSchema on the DataSet.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"HJ Rodriguez" <ha*****@yahoo.com> wrote in message
news:On**************@TK2MSFTNGP11.phx.gbl...
Hello all,

I have the following serializable class.
-------------------------------------------------------------------------- -- --
Public Class Test

_testID as int32
_testName as String

Public Sub New()
MyBase.New()
End Sub

<XmlAttributeAttribute()> Public Property TestID() As int32
Get
Return _testID
End Get
Set(ByVal Value As int32)
_testID= value
End Set
End Property

<XmlAttributeAttribute()> Public Property TestName() As String
Get
Return _testName
End Get
Set(ByVal Value As String)
_testName= value
End Set
End Property
End Class
-------------------------------------------------------------------------- -- -

I know I can use XSD.exe to build an XSD file from this class at design
time. But is their any way to build an XSD schema at runtime (in memroy)
based on my class.

I know I can use reflection to query the members of my objects and build my schema, but I was hoping that there might me something in the .net framework which can acomplish this more efficiently.

Thank you in advance for your help.

Reguards,
HJ Rodriguez

Nov 12 '05 #2
Thank you Dare

HJ
"Dare Obasanjo [MSFT]" <da***@online.microsoft.com> wrote in message
news:40********@news.microsoft.com...
Use the XmlSerializer class to serialize the object to XML, load that into a DataSet and then call InferXmlSchema on the DataSet.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"HJ Rodriguez" <ha*****@yahoo.com> wrote in message
news:On**************@TK2MSFTNGP11.phx.gbl...
Hello all,

I have the following serializable class.


--------------------------------------------------------------------------
--
--
Public Class Test

_testID as int32
_testName as String

Public Sub New()
MyBase.New()
End Sub

<XmlAttributeAttribute()> Public Property TestID() As int32
Get
Return _testID
End Get
Set(ByVal Value As int32)
_testID= value
End Set
End Property

<XmlAttributeAttribute()> Public Property TestName() As String
Get
Return _testName
End Get
Set(ByVal Value As String)
_testName= value
End Set
End Property
End Class


--------------------------------------------------------------------------
--
-

I know I can use XSD.exe to build an XSD file from this class at design
time. But is their any way to build an XSD schema at runtime (in memroy) based on my class.

I know I can use reflection to query the members of my objects and build

my
schema, but I was hoping that there might me something in the .net

framework
which can acomplish this more efficiently.

Thank you in advance for your help.

Reguards,
HJ Rodriguez


Nov 12 '05 #3

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

Similar topics

2
by: Olaf Meyer | last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints specified in the schema (e.g. constraints specified via unique element). The validation works with the XML editor I'm using...
0
by: Olaf Meyer | last post by:
I'm wondering if I can also express uniquness constraints on attributes of objects that I have referenced from somewhere else. To be a bit more precise here a short and simple XML document. The...
1
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm designing my first XML-based application and am stuck on an issue that I presume is pretty simple. I'm trying to write a schema that can be used to validate my XML file. ...
10
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
3
by: MR | last post by:
Is there a way to load an XML schema into a dataset from a resource or other object? I am using ReadXmlSchema(filename) and that works fine. However, I have many XSD files that I would rather not...
12
by: Maansi Sanghi | last post by:
Hi, Is there a way to use the System.Xml.Schema classes in VC++ 6.0? Regards, Maansi
1
by: serge | last post by:
SQL BPA says the following: "One or more objects are referencing tables/views without specifying a schema! Performance and predictability of the application may be improved by specifying schema...
16
by: Bob Stearns | last post by:
The syntax diagram of DROP SCHEMA requires RESTRICT. Is there an easy way to drop an old, unnecessary, but populated schema?
3
by: John Glover | last post by:
To whoever can help, Is there a way to get the Xml schema for a user defined type at runtime? I've looked at the XmlSerializer as I had hoped there might be a way to retrieve it. I've also...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.