Solved

Create VB.Net 2005 classes based on XML Schema (.xsd)

Posted on 2006-06-22
8
545 Views
Last Modified: 2007-12-19
I am looking for resources on being able to create vb.net classes based on a set of 4 schema's that interrelate.  Basically, I am being given the schemas and I need to produce a program that will receive an XML file based on it, and then send back an XML file based on it also.  All together there are 19 distinct XML documents being described in the schema's and I would like to find an automated way to produce some or all of this background code to use it efficiently.

I have tried xsd.exe and had no success.  It couldn't handle these in coordination together.  I know they were created using XMLSpy, but that is not able to generate vb code, only c#.

Any help would be appreciated at this point as I am over my head and sinking fast.
0
Comment
Question by:arosema
  • 4
  • 3
8 Comments
 
LVL 41

Expert Comment

by:graye
ID: 16970743
Obviously, the "school answer" is to XSD.EXE to create the classes for you.   But since the *.xsd files are formatted by a "foreign" utiliity that's not an option for you.

So, why not just take a "low-tech" approach to use the XSD files to create the schema for an "ordinary" DataSet (not using the strongly-typed DataSet feature at all).

The code would look like this:

        Dim testing As New DataSet

        ' Load the prototype XSD file...
        testing.ReadXmlSchema("C:\SomeFolder\SomeXSDfile.xsd")

       ' Receiving a file based upon that schema...
       testing.ReadXml("C:\SomeFolder\SomeXMLfile.xml")

       ' Writing an xml file based upon that schema...
       testing.WriteXml("C:\SomeFolder\SomeXMLfile.xml")


0
 
LVL 1

Author Comment

by:arosema
ID: 16970993
The only problem I see with this is the size of the schema's as a whole and the requirements of the project going forward, that as these change I need to have an easy way of updating the xml document set.

These 4 schema's have a total of 4000 lines of xml in them, where one file has about 300 reused components that the other schema's will reference.  Just getting my mind around this complicated set of documents is going to be a challenge, making it into code is even tougher.
0
 
LVL 41

Expert Comment

by:graye
ID: 16973168
That's all the more reason to use the "ordinary" DataSet.... it can adapt to chanages in the XSD file without any code changes or need to recompile.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:arosema
ID: 16983753
Do you have any web site showing this more in detail, or with more explanation?  I am not understanding all the details of this yet.
0
 
LVL 41

Expert Comment

by:graye
ID: 16984127
Huh?  (I wonder if we're communicating here)

I had proposed a technique whereby you do not use XSD.EXE to create a strongly-typed dataset.  Instead, I recommeded that you use an "ordinary" dataset.  That way you'd be able to load the XSD file at run time (not at design time) to build the schema for a disconnected dataset.  After the dataset is built, you'd be able to load the XML file (which is based upon that XSD file), manipulate the data, and write it back as an XML file.

I've got a few article on how to use "ordinary" datasets that you might find useful.

http://home.hot.rr.com/graye/Articles/BeginningADO.htm
http://home.hot.rr.com/graye/Articles/SavingDataADO.htm

The DataSet's ReadXmlSchema(), ReadXml(), and WriteXml() methods are pretty much straight forward.  You'd use them just like the short example above.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclasstopic.asp

I made the assumption that the XSD files had just an empty database schema... but 4000 lines is a bit much.  Is there anything else is in the XSD file?
0
 
LVL 1

Author Comment

by:arosema
ID: 16984228
I believe I tried to ask too much in my original question.  Let me get it down to just what I need right now, I can always ask more questions later if I need to (as separate questions so you can get more points).

I am being provided an XSD file containing all the data fields I need to produce and give to a web service where the system I am responsible for has the data across 100 or so tables on a mainframe.  I can get the data off of the mainframe, but it will not be coming through as a normal dataset, as I would expect to come from SQL and such.  I basically need to take the data coming into me from the mainframe and convert it into an XML file based on the schema.    

I can figure out how to map the data to the fields within the schema, if I can get the schema structure and relationships built into the code with vb2005.  In my mind this is alot like EDI field mapping, however, I have never written a translator for that either.
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 16985491
I'm still a little confused, but that's OK :)

This is part of the question that I'm still confused by "get the schema structure and relationships built into the code".  Most folks don't attempt to do this in code.  Instead they use the ADO.Net DataSet features that are already present in the Dot Net Framework.  ADO.Net acts like a miniature disconnected database, with full relational support.   So, there's nothing to code... merely reading in the XSD file will create all of the tables, set up all of the relationships, etc.

So, are you saying that your design can't use an ADO.Net DataSet, and therefore you must create this all in code?   Whew!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now