Solved

Createing a dataset using and XSD

Posted on 2011-02-16
7
1,184 Views
Last Modified: 2012-05-11
Hi there everyone,

I'm now trying to figure out how to create a dataset from the XSD so that I can load it. I've run the XSD.exe and it created the resulting vb extension. I've imported that into the project and it ended up as part of the XSD. But when I try to refer to it in my program, intellisence doesn't recognize the xsd as a dataset.

The long term goal here is to be able to fill the dataset and then do a 'writexml' out of that dataset.

Any suggestions would be greatly appreciated. Thanks! - Eric -
0
Comment
Question by:carpetking
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34921757
I am confused about your question, and the ultimate goal.  Are you working with a typed DataSet or a non-typed DataSet?
0
 

Author Comment

by:carpetking
ID: 34921842
Well, I can understand partially your confusion. The title should have read...

"Creating a dataset using an XSD"

In other words, I want to create a dataset based on an XSD that I received from a government agency. I will then populate the dataset based on the contents from a series of data tabels. After the dataset is populated I want to the do a getxml (or writexml) to get the resulted XML outof the dataset.

My end result is to get xml data that is in the format of the XSD that was provided to my by the state agency.

Does that make more sence or is it still clear as mud?

Thanks for your help! - Eric -
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 34922880
Eric, I believe that you are saying that you want to use the XSD schema as a basis for creating another DataSet object with the same schema, which is described in this article:

How Do I...Create DataSet mappings from an XSD schema?
http://authors.aspalliance.com/quickstart/howto/doc/Xml%5CDataSetMapXSDSchema.aspx

The DataSet class has a close affiliation with the XmlDataDocument class. The DataSet class provides a relational view of the XML data loaded through the XmlDataDocument. To build a relational mapping between these two views, you need to use the ReadXmlSchema method of the DataSet. You use this method when you create the XmlDataDocument as in the following call, XmlDataDocument.DataSet.ReadXmlSchema. Now, any changes made to the DataSet are reflected in the XmlDataDocument and vice versa.

Let me know if that is what you are talking about...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:carpetking
ID: 34927758
Hi there TheLearnedOne,

Thank you so much for the response. You understood what I was trying to get at perfectly. Also, I think you have found the solution, but I'm not able to get to the source code on the internet. It looks like the link is broken. I was able to get to the meat of the solution though based on what is shown in the article. My program is blowing up, probably because I don't have all of the correct code implemented. I'll keep slugging away at it to see if I can get it figured out. If you know of some place else that I can download the entire solution, please let me know.

If not, don't worry about it, I'll keep plugging away and mark your last response as the solution.

Thanks again so much for your help! - Eric-
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 34927822
To illustrate this relationship, the following sample code reads and loads the books.xsd schema file into the DataSet property on an XmlDataDocument. Notice how the ReadXmlSchema method takes the schema loaded into a StreamReader and generates the relational mappings. If there is already a relational view defined in the XmlDataDocument, the sample throws an exception.

Dim myStreamReader as StreamReader = nothing
try
    myStreamReader = new StreamReader(schema)
    Console.WriteLine("Reading Schema file ...")
    myXmlDataDocument.ReadXmlSchema(myStreamReader)
catch e as exception
    Console.WriteLine ("Exception: " & e.ToString())
finally
    If Not myStreamReader Is Nothing
        myStreamReader.Close()
    end if
end try

Open in new window


So how do you know what the internal tables generated from the schema look like? Well, the DataSet has a Tables property that is a collection of the internal tables. Each table has a Columns collection and each column has a ColumnName and a DataType. You can simply iterate over these collections and format the output to display the internal table structure built from the supplied schema, as shown in the following code.

 Displays the DataSet tables structure
private sub DisplayTableStructure()
    Console.WriteLine()
    Console.WriteLine("Table structure")
    Console.WriteLine()
    Console.WriteLine("Tables count=" & myXmlDataDocument.Tables.Count.ToString())

    Dim i,j as integer

    for i = 0 to (myXmlDataDocument.Tables.Count - 1)
        Console.WriteLine("TableName='" & myXmlDataDocument.Tables(i).TableName & "'.")
        Console.WriteLine("Columns count=" & myXmlDataDocument.Tables(i).Columns.Count.ToString())

        for j = 0 to (myXmlDataDocument.Tables(i).Columns.Count - 1)
            Console.WriteLine(Strings.chr(9) & "ColumnName='" & _
                              myXmlDataDocument.Tables(i).Columns(j).ColumnName & _"', type = " & _
                              myXmlDataDocument.Tables(i).Columns(j).DataType.ToString())
        next
        Console.WriteLine()
    next
end sub

Open in new window


The following output shows the table names, column names, and the column types displayed by the DisplayTableStructure method for the books.xsd schema.


Table structure

Tables count=3
      TableName='bookstore'.
      Columns count=1
            ColumnName='bookstore_Id', type = System.Int32
      TableName='book'.
      Columns count=5
            ColumnName='title', type = System.String
            ColumnName='price', type = System.Decimal
            ColumnName='genre', type = System.String
            ColumnName='book_Id', type = System.Int32
            ColumnName='bookstore_Id', type = System.Int32
      TableName='author'.
      Columns count=3
            ColumnName='first-name', type = System.String
            ColumnName='last-name', type = System.String
            ColumnName='book_Id', type = System.Int32

0
 

Author Comment

by:carpetking
ID: 34927884
TheLearnedOne!

I figured it out... the problem with my program was that I didn't define a 'New' dataset in my DIM statement. It turns out that the schema from the state agency has some custom stuff in it that the Streamreader doesn't understand. so, I'll have to deal with that Manually.

None the less, I appreciate all of your help! You are the best! - Eric -
0
 

Author Closing Comment

by:carpetking
ID: 34927887
Thanks for all of the help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy/Clone an object. 9 29
Recommendation vb6 to vb.net or others 14 109
I need help exporting info from a dataset to Excel in my VB.Net application 7 50
Variable Event ? 3 22
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

22 Experts available now in Live!

Get 1:1 Help Now