creating schema from a xml file dynamiccaly

B

Bappaditya

Hi,
I am relatively new to .net compact framework.I have created an
application where i have added a xml file and then created its
schema(from Create Schema in the toolbar). In a loading of a form, i
have written the following code to read the schema and the xml file:

Private exerciseDS As New DataSet
Private xmlFileName As String
Private xsdFileName As String

xmlFileName = "\program
files\SmartDeviceApplicationDemoXml\Exercise.xml"
xsdFileName = "\program
files\SmartDeviceApplicationDemoXml\Exercise.xsd"
Dim FsXML As New FileStream(xmlFileName, FileMode.Open)
Dim FsXSD As New FileStream(xsdFileName, FileMode.Open)

' Load the schema into the DataSet.
Dim xtrXSD As New XmlTextReader(FsXSD)
exerciseDS.ReadXmlSchema(xtrXSD)
xtrXSD.Close()
FsXSD.Close()

Dim xtrXML As New XmlTextReader(FsXML)
exerciseDS.ReadXml(xtrXML)
xtrXML.Close()
FsXML.Close()

Now this works fine enough.
But when i tried to create a xml file dynamically in the following
way:

Dim oXMLDOM As New XmlDocument
' Create Exercise root element
Dim oRoot As XmlElement = oXMLDOM.CreateElement("Exercise")
oXMLDOM.AppendChild(oRoot)

' Create new Exercise element
Dim oID As XmlElement = oXMLDOM.CreateElement("id")
oRoot.AppendChild(oID)

' Create new Exercise element
Dim oDate As XmlElement = oXMLDOM.CreateElement("Date")
oRoot.AppendChild(oDate)

' Create new Exercise element
Dim oTime As XmlElement = oXMLDOM.CreateElement("Time")
oRoot.AppendChild(oTime)

' Create new Exercise element
Dim oType As XmlElement = oXMLDOM.CreateElement("Type")
oRoot.AppendChild(oType)

'Create the xml processing instruction.
Dim oXMLPI As XmlProcessingInstruction =
oXMLDOM.CreateProcessingInstruction("xml", "version='1.0'
encoding='ISO-8859-1'")
'Append the processing instruction to the XML document.
oXMLDOM.InsertBefore(oXMLPI, oXMLDOM.ChildNodes(0))

' Save the document
oXMLDOM.Save("\program
files\SmartDeviceApplicationDemoXML\Exercise.xml")

I have successfully created the xml document. But i am to generate the
schema. I am also not getting any code anywhere. Can anyone help me
out?

Thanks
Bappaditya
 
F

Franky

You can open a Visual Studio .Net Session but new Project WINDOW (regular
Frame Work) add your XML file and use the New XML Schema. So now your
Schema is genereted.. you can load it on runtime.
FileStream fs = new FileStrream(fileename, FileMode.Open, FileAccess.Read);
XmlTextReader xtr = new XmlTextReader (fs);

_________________________
Franky
(e-mail address removed)
 
M

Mark Ihimoyan [MSFT]

Alternatively,
you could reload the Xml into a dataset
and call the WriteXmlSchama method of the dataset to create a schema
dynamically.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top