Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with created .xsd when creating xml file

Posted on 2014-04-27
17
Medium Priority
?
298 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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 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