Solved

Help with created .xsd when creating xml file

Posted on 2014-04-27
17
289 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
[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
  • 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 63

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 63

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 63

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 63

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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