A XML question

N

Nikolay Petrov

Hi guys,
I am looking for a general answer of my quistion, no specific code.
What I need to do is to read data from a text file, parse it and save it as
XML.
I have an sample XML file and XML Schema(.xsd) file for validation.
I can easly read the data from the text file in put in in DataSet, but I
don't know what to do to export the data in XML file and validate it to the
Schema. And of course the file should look as the sample provided.

Any help will be appreciated.

TIA
 
C

Cor Ligthert

Nikolay,

First an XML file can be a document, a dataset or whatever. It is a way of
saving data using free tags.

Your problem is a dataset in XML when you have problems with that, than tell
that because the use of XML can be very different.

Your problem.

When your dataset is false, than it gives an error. When you want to have
the schema with it, than just write it as

ds.WriteXML("c:\mydataset.xml",XmlWriteMode.WriteSchema )

I hope this helps?

Cor
 
C

Cor Ligthert

I need a way to fill the dataset according to the schema.And what is the input?

Cor
 
C

Cor Ligthert

Nikolay,

It really is not clear to me what you want to validate when you have using
the schema filled the dataset withouth any error, what can than be wrong in
that dataset?.

Cor
 
H

Herfried K. Wagner [MVP]

Nikolay Petrov said:
I have an sample XML file and XML Schema(.xsd) file for validation.
I can easly read the data from the text file in put in in DataSet, but I
don't know what to do to export the data in XML file and validate it to
the Schema. And of course the file should look as the sample provided.

You can use 'XmlValidatingReader' to check if the file sticks to the rules
defined in an XSD schema.
 
N

Nikolay Petrov

Maybe I wasn't clear enough.
I generate the dataset from the schema file. That's ok.
I've made an reader which reads the supplied sample XML file and shows it in
DataGrid. Works fine too. But when I save the file from dataset, the new
file is a little bit different from the sample file. They must be the same.
This is what I need.

I use this simple code:

Private Sub ReadXML()
Dim objOFD As New Windows.Forms.OpenFileDialog
With objOFD
.Multiselect = False
.Filter = "XML files (*.xml)|*.xml"
.Title = "Choose file"
End With
If objOFD.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim FS As New System.IO.FileStream(objOFD.FileName,
IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.Read)
F1.ReadXml(FS)
FS.Close()
End If
End Sub

Private Sub WriteXML()
Dim objOFD As New Windows.Forms.SaveFileDialog
With objOFD
.AddExtension = True
.DefaultExt = "XML"
.Filter = "XML files (*.xml)|*.xml"
.Title = "Save file"
End With
If objOFD.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim FS As New System.IO.FileStream(objOFD.FileName,
IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)
F1.WriteXml(FS)
FS.Flush()
FS.Close()
End If
End Sub

Part of the source file is:
<?xml version="1.0" encoding="Windows-1251"?>
<f >
<h timestamp="2001-12-17T09:30:47" sender="12345678">ðßÒ×Á ÔßÒÇÏ×ÓËÁ
ÂÁÎËÁ</h>
<b cod="12345678" name="ðôâ - ËÌÏÎ ÷ÁÒÎÁ">


and what I get after save is:

<f xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.bsbg.net/schemas/ibank.xsd">
<h timestamp="2001-12-17T09:30:47.0000000+02:00" sender="12345678"
xmlns="">ðßÒ×Á ÔßÒÇÏ×ÓËÁ ÂÁÎËÁ</h>
<b cod="12345678" name="ðôâ - ËÌÏÎ ÷ÁÒÎÁ" xmlns="">

I got all this "xmlns" and ".0000000+02:00" which are not needed.
I know that the "xmlns" properties are shown because of the Schema file, but
I don't need them in output.
And also this time zone thing should be removed too.
 
C

Cor Ligthert

Nikolay,

You can in my opinion direct write and read the dataset with
dataset.writexml(path) and dataset.readxml(path) without that
streamreader/writer part.

However you are you not able to delete the parts that belong to a dataset in
a dataset xml file as you want, because with that it is not a dataset
anymore.

I have done partially the same as you want, when I did as well not like all
that time information in my XML file by creating two datasets, one with
datetime as column and one with the same columns however instead of datetime
string values.

I looped through that and delete the time part. (Not actual however to tell
it easy). However it is not really a good approach in my opinion and only
good for a special purposes and than absolute culture dependend what we
should try to avoid in my opinion.

When you want a clear XML document, than you will have to use another
method.

You can have a look at this page for that.

http://msdn.microsoft.com/library/d...uide/html/cpconEmployingXMLInNETFramework.asp

I hope this helps?

Cor
 
N

Nikolay Petrov

Thanks Cor.
I wonder if I edit the XML Schema and make the datetime values strings.
Maybe that would help?
 

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

Similar Threads


Top