Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2006-06-22
8
555 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

791 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