How to create XSD file dynamically based on XML file?

Posted on 2006-04-10
Last Modified: 2012-05-05
How can I create XSD file based on the XML file programatically using (C# / VB.Net)?

I know the command line utilities xsdinference tool to do the same.

But i WOULD like to do the same dynamically through my code.

Question by:Wayne29

    Author Comment

    It's Ok Guys. I got it.
    Please find the answer as below.

    ' Create XmlReader to pass as argument.
            Dim xtr As New XmlTextReader(Server.MapPath(".") + "\XMLFile1.xml")

            ' Create the XmlSchemaCollection that the inferred schema is
            ' added to.
            Dim xsc As New XmlSchemaCollection

            ' Create Infer object.
            Dim objInfer As New Infer

            ' Infer schema
            xsc = objInfer.InferSchema(xtr)
            Dim st As New System.Text.StringBuilder

            Dim xs As XmlSchema
            For Each xs In xsc
                Dim writer = New StringWriter

                Dim xsi As XmlSchemaImport
                For Each xsi In xs.Includes
                    Dim strWriter = New StringWriter
                Next xsi
            Next xs

            Dim x As String = st.ToString()
            Dim y As New StreamWriter(Server.MapPath(".") + "\NewSchema2.xsd")

    Accepted Solution

    Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Building “do-it-yourself” web sites has become an epidemic. There are so many blogs, web sites and even books that "teach" you how to build your web site in a few extremely simple and easy steps. Building a web site has become easier than boiling an…
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 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