Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with created .xsd when creating xml file

Posted on 2014-04-27
17
Medium Priority
?
301 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 64

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 64

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
 

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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

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…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

885 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