Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Createing a dataset using and XSD

Posted on 2011-02-16
7
Medium Priority
?
1,195 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
[X]
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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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