Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

How to create XSD file dynamically based on XML file?

How can I create XSD file based on the XML file programatically using asp.net (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.

<sample>
<title>Mr.</title>
<forename>Wayne</forename>
<surname>Feraera</feraera>
<Address1>Canb</Address1>
<Address2>Australia</Address2>
</sample>
0
Wayne29
Asked:
Wayne29
1 Solution
 
Wayne29Author Commented:
It's Ok Guys. I got it.
Please find the answer as below.
Thanks.

' 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
            xs.Write(writer)
            st.Append(writer.ToString())

            Dim xsi As XmlSchemaImport
            For Each xsi In xs.Includes
                Dim strWriter = New StringWriter
                xs.Write(strWriter)
                st.Append(strWriter.ToString())
            Next xsi
        Next xs


        Dim x As String = st.ToString()
        Dim y As New StreamWriter(Server.MapPath(".") + "\NewSchema2.xsd")
        y.Write(x)
        y.Close()
0
 
EE_AutoDeleterCommented:
Wayne29,
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.

EE_AutoDeleter
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now