472,145 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 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 9347
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by D Witherspoon | last post: by
28 posts views Thread by Act | last post: by
10 posts views Thread by Zap | last post: by
4 posts views Thread by Oyvind | last post: by
3 posts views Thread by zc2468 | last post: by
4 posts views Thread by alacrite | last post: by
2 posts views Thread by Peter Duniho | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

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.