Solved

Help with created .xsd when creating xml file

Posted on 2014-04-27
17
285 Views
Last Modified: 2014-05-02
Hi,

I'm using the code below to create an xml file from a dataset. How do I also create the schema (.xsd)?

dtsetCtry.WriteXml(Application.StartupPath + "\Data\Ctry.xml")

Thanks,

Victor
0
Comment
Question by:vcharles
  • 12
  • 4
17 Comments
 
LVL 8

Expert Comment

by:Ganapathi
ID: 40025876
You can use the inbuilt xsd.exe tool which will generate the XSD based on the DataSet dynamially.

Refer the well illustrated link below.

http://oreilly.com/pub/h/5157
0
 

Author Comment

by:vcharles
ID: 40025927
Thank you for the link will get back to you.
0
 

Author Comment

by:vcharles
ID: 40031999
Hi,

Do you how to achieve the same by code?

Thanks,

Victor
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40035237
Hi Victor;

You can use the Process Class to run the xsd.exe file supplying the XML file as input and it will produce the xsd file. Note that this program is part of the Visual Studio Tools and if you are building an application to be distributed then you will need to also package it with the application.
0
 

Author Comment

by:vcharles
ID: 40035544
Thank You. I will try it and get back to you.
0
 

Author Comment

by:vcharles
ID: 40035597
I tried Process.Start("Xsd.exe", "C:\Test.xml")

But received error message:

The system can not find the file specified, I'm certain the file is in the C folder.

V.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40035611
You will need to use the full path to the file xsd.exe. It is located in the Visual Studio Install directory in a tools folder. Also unless test.xml is located in the C drive root directory you will also nee a full path for that as well.
0
 

Author Comment

by:vcharles
ID: 40035800
Hi,

Won't hard coding the full path for the xsd
cause an error when I deploy the application?
Thanks.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:vcharles
ID: 40035803
Hi,

Please disregard last message
0
 

Author Comment

by:vcharles
ID: 40036195
Hi,

I can't seem to find xsd.exe, will keep looking.


V.
0
 

Author Comment

by:vcharles
ID: 40036223
Hi,

Below is the complete code from the link, I'm only using the process statement could that also be the reason why it can not find the path?


Imports System
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
            ' Opens the Internet Explorer application.
            Public Sub OpenApplication(myFavoritesPath As String)
            ' Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe")

            ' Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath)
        End Sub 'OpenApplication

        ' Opens urls and .html documents using Internet Explorer.
        Sub OpenWithArguments()
            ' url's are not considered documents. They can only be opened
            ' by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com")

            ' Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
            Process.Start("IExplore.exe", "C:\myPath\myFile.asp")
        End Sub 'OpenWithArguments

        ' Uses the ProcessStartInfo class to start new processes,
        ' both in a minimized mode.
        Sub OpenWithStartInfo()
            Dim startInfo As New ProcessStartInfo("IExplore.exe")
            startInfo.WindowStyle = ProcessWindowStyle.Minimized

            Process.Start(startInfo)

            startInfo.Arguments = "www.northwindtraders.com"

            Process.Start(startInfo)
        End Sub 'OpenWithStartInfo

        Shared Sub Main()
            ' Get the path that stores favorite links.
            Dim myFavoritesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)

            Dim myProcess As New MyProcess()

            myProcess.OpenApplication(myFavoritesPath)
            myProcess.OpenWithArguments()
            myProcess.OpenWithStartInfo()
        End Sub 'Main
    End Class 'MyProcess
End Namespace 'MyProcessSample
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40037649
Hi Victor;

I went through some documentation I had and found a much nicer way to create the XSD file in your program, see code snippet below.

Imports System.Xml
Imports System.Xml.Schema
Imports System.IO


'' Create an XmlReader to read in the XML document to create an XSD file for.
'' Change the path to fit your needs. 
Dim reader As XmlReader = XmlReader.Create("C:\Working Directory\linkfile2.xml")
'' Holds the XSD elements as they are created
Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()
'' Used to infer the XSD from the XML file
Dim schema As XmlSchemaInference = New XmlSchemaInference()
'' Create the XSD document
schemaSet = schema.InferSchema(reader)

'' Write the XSD document to a file. Change the path to where to
'' save it on the file system
Using sw As New StreamWriter("C:\Working Directory\LinkFile2.xsd")
    For Each s As XmlSchema In schemaSet.Schemas()
        s.Write(sw)
    Next
End Using

Open in new window

0
 

Author Comment

by:vcharles
ID: 40037745
Thank you. I will try it and get back to you.
0
 

Author Comment

by:vcharles
ID: 40037766
Hi,

I am getting the following error:

The process cannot access the file 'C:\TestProject\bin\Debug\Data\LinkFiles\LinkTest.xml' because it is being used by another process.


On Line:

Using sw As New StreamWriter(Application.StartupPath + "\Data\LinkFiles\LinkTest.xml")


V.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40037786
Check to make sure that the file is not already open in your program before this call.
0
 

Author Comment

by:vcharles
ID: 40037803
Hi,

It works when I use ("C:\Working Directory\LinkTest.xml")

Thank You.

Victor
0
 

Author Closing Comment

by:vcharles
ID: 40037806
THANK YOU!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

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

11 Experts available now in Live!

Get 1:1 Help Now