Wayne29
asked on
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</Addre ss2>
</sample>
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</Addre
</sample>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Please find the answer as below.
Thanks.
' Create XmlReader to pass as argument.
Dim xtr As New XmlTextReader(Server.MapPa
' 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.ToStri
Next xsi
Next xs
Dim x As String = st.ToString()
Dim y As New StreamWriter(Server.MapPat
y.Write(x)
y.Close()