473,441 Members | 1,786 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,441 software developers and data experts.

Map XSD/XML data to VB.net classes

Hi,

That's my first post here so I hope this is the right group to post to.
I have to design a good strategy to manipulate XML data in VB.net
language.

Here's the business case:
- I will have a large number (200+) of XML forms created with Infopath
that represents industrial machines specifications. Infopath makes a
XSD available for each form template.
- These forms templates will be maintained by non programmers.
- I am building an application that gathers form data to compute
several indicators (cost, volume, weight...) based on the data inside
the XML files created by Infopath. Implementing these indicators is
rather complex, because of mutual dependencies between forms and other
data non-xml'd. Therefore, computing an indicator cannot be done at
form level.
- structure of XML data is simple (basic types, little repeating
sections, no complex-nested data)

So now, here's the programmer case:
- I have good knowledge of VB.net & SQL Server technologies.
- I have little practice with XPath and Xml Schema.

Since forms templates will change, creating by hand VB classes with a
compatible structure (that maps XSD) will be a big job (several months,
plus added maintenance costs as form templates changes).

So I'd like to solve the more generical problem: how to map XML data
into business components? Is there some way to generate a strongly
typed class from an XSD and instanciate it with a specific XML doc ? Is
there some magical VS.net wizard for that or shoud I implement a
dynamic class creator from XSD?

Thanks in advance,
Pascal.

Nov 12 '05 #1
3 9403
See xsd.exe that is available from the Visual Studio .Net command prompt.
This tool can generated strongly typed classes from an XSD schema.

"Pascal Brunot" <pa***********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi,

That's my first post here so I hope this is the right group to post to.
I have to design a good strategy to manipulate XML data in VB.net
language.

Here's the business case:
- I will have a large number (200+) of XML forms created with Infopath
that represents industrial machines specifications. Infopath makes a
XSD available for each form template.
- These forms templates will be maintained by non programmers.
- I am building an application that gathers form data to compute
several indicators (cost, volume, weight...) based on the data inside
the XML files created by Infopath. Implementing these indicators is
rather complex, because of mutual dependencies between forms and other
data non-xml'd. Therefore, computing an indicator cannot be done at
form level.
- structure of XML data is simple (basic types, little repeating
sections, no complex-nested data)

So now, here's the programmer case:
- I have good knowledge of VB.net & SQL Server technologies.
- I have little practice with XPath and Xml Schema.

Since forms templates will change, creating by hand VB classes with a
compatible structure (that maps XSD) will be a big job (several months,
plus added maintenance costs as form templates changes).

So I'd like to solve the more generical problem: how to map XML data
into business components? Is there some way to generate a strongly
typed class from an XSD and instanciate it with a specific XML doc ? Is
there some magical VS.net wizard for that or shoud I implement a
dynamic class creator from XSD?

Thanks in advance,
Pascal.

Nov 12 '05 #2
Visual Studio.NET has a tool called XSD.exe, which if given an XSD, will
create a .NET class representation for it.

I don't know anything about InfoPath, but I assume if it is exposing data in
XML (based on the XSD), it will be XML that can be deserialised into a .NET
object (once you've run xsd.exe on it).

Maybe someone else who knows about InfoPath can help a bit more.

"Pascal Brunot" wrote:
Hi,

That's my first post here so I hope this is the right group to post to.
I have to design a good strategy to manipulate XML data in VB.net
language.

Here's the business case:
- I will have a large number (200+) of XML forms created with Infopath
that represents industrial machines specifications. Infopath makes a
XSD available for each form template.
- These forms templates will be maintained by non programmers.
- I am building an application that gathers form data to compute
several indicators (cost, volume, weight...) based on the data inside
the XML files created by Infopath. Implementing these indicators is
rather complex, because of mutual dependencies between forms and other
data non-xml'd. Therefore, computing an indicator cannot be done at
form level.
- structure of XML data is simple (basic types, little repeating
sections, no complex-nested data)

So now, here's the programmer case:
- I have good knowledge of VB.net & SQL Server technologies.
- I have little practice with XPath and Xml Schema.

Since forms templates will change, creating by hand VB classes with a
compatible structure (that maps XSD) will be a big job (several months,
plus added maintenance costs as form templates changes).

So I'd like to solve the more generical problem: how to map XML data
into business components? Is there some way to generate a strongly
typed class from an XSD and instanciate it with a specific XML doc ? Is
there some magical VS.net wizard for that or shoud I implement a
dynamic class creator from XSD?

Thanks in advance,
Pascal.

Nov 12 '05 #3
Thanks Dave.

I've made several tests and I am able to use XSD generated classes with
infopath.

The main problem was that Infopath generates xsi:nil="true" attributes
for value types (int, double etc..) and the XML serialized does not
like it at all. To be handled correctly, the xml node must be completly
omitted in the XML. So to deserialize correctly my infopath form, I
have to apply first a XSL that will delete terminal nil nodes.

Here's my deserialization code that may be useful.
Pascal.

__________________________________________________ ____

clean.xsl:

<!-- XSL "specialized identity pattern" -->
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//*[(count(child::*) = 0) and (string-length(.) =
0)]"/>
</xsl:stylesheet>

VB.net:

Dim xmldser As New
System.Xml.Serialization.XmlSerializer(<XSDGenerat edClassName>)

docXML = New XPath.XPathDocument(New XmlTextReader("infopathform.xml"))

transform = New Xsl.XslTransform
Dim writer As XmlTextWriter = New XmlTextWriter("temp.xml",
System.Text.Encoding.UTF8)
' Apply XSL
transform.Load("cleaninfoxml.xsl")
transform.Transform(docXML, Nothing, writer)

writer.Close

' Load object from "clean" XML
Dim st As New System.IO.StreamReader("temp.xml")
Dim objSPR As <XSDGeneratedClassName>
objSPR = CType(xmldser.Deserialize(New System.Xml.XmlTextReader(st)),
<XSDGeneratedClassName>)

Nov 12 '05 #4

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

Similar topics

0
by: sedefo | last post by:
I ran into this Microsoft Patterns & Practices Enterprise Library while i was researching how i can write a database independent data access layer. In my company we already use Data Access...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
1
by: Vikas | last post by:
Hi y'all, I have an existing GUI application where various windows has columns which are mapped to data members of various classes. Now, I have to implement a new functionality to all the...
28
by: Act | last post by:
Why is it suggested to not define data members as "protected"? Thanks for help!
10
by: Zap | last post by:
Widespread opinion is that public data members are evil, because if you have to change the way the data is stored in your class you have to break the code accessing it, etc. After reading this...
4
by: Oyvind | last post by:
I'm working on a Windows forms/C# database application. My background is 6-7 years of VB 4 - 6, MS Access, VC++, mixed in with a lot of T-SQL and MS SQL Server in general and some OOA/OOD. ...
3
by: zc2468 | last post by:
I am new to dot net and would like to write an application using a solid 3 tier design because I expect the app to require a lot of updates and maintenance over time. I am creating my own data...
4
by: alacrite | last post by:
I have a class that I want to turn its contents into csv file. I want to be able to set the value of the delimiter, the name of the file it gets saved to, the path of that file, and maybe a few...
2
by: Peter Duniho | last post by:
I've been learning about mechanisms .NET offers to export data. The initial goal is to see what sorts of ways are available to save an application's state (document, internal database, whatever). ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.