problems synchronizing XML file and Dataset

clweeks

Member
Joined
Feb 21, 2007
Messages
18
Programming Experience
3-5
Hi all, I'm doinking with XML for the first time and could use some help.

I'm generating two XML filesin one application with the following code and essentially a duplicate of this code with a different datatable and path:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] XMLs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] StreamWriter(path & [/SIZE][SIZE=2][COLOR=#a31515]"\"[/COLOR][/SIZE][SIZE=2] & fn)[/SIZE]
[SIZE=2]ds.Tables([/SIZE][SIZE=2][COLOR=#a31515]"imageXML"[/COLOR][/SIZE][SIZE=2]).WriteXml(XMLs, XmlWriteMode.WriteSchema)[/SIZE]

These files are zipped up and ecrypted and FTPed to another location where they are unzipped and decrypted by another application that has to take in the XML data. In once case, I'm just binding it to a DataGridView with no problems, thus:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] catXML [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] XmlDataDocument()[/SIZE]
[SIZE=2]catXML.DataSet.ReadXml(currentBatch.FullName & [/SIZE][SIZE=2][COLOR=#a31515]"\categories.XML"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]dgvCategories.DataSource = catXML.DataSet.Tables(0).DefaultView[/SIZE]

But for the other XML, I need to load the data into a Dataset and then operate on that data through the UI. I've been struggling with the instructions at http://msdn2.microsoft.com/en-us/library/1t4362sd(VS.80).aspx -- trying different options. I've got the data to load into my dataset and act as I want it to using this:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] mainXML [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] XmlDataDocument[/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] batchData [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataSet = mainXML.DataSet[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] dataPrep()[/SIZE]
[SIZE=2]batchData.ReadXmlSchema([/SIZE][SIZE=2][COLOR=#a31515]"C:\Documents and Settings\weeksc\My Documents\Visual Studio 2005\Projects\dsEntry\dsEntry\batchDataSchema.xsd"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]mainXML.Load(currentBatch.FullName & [/SIZE][SIZE=2][COLOR=#a31515]"\"[/COLOR][/SIZE][SIZE=2] & currentBatch.Name.Substring(4) & [/SIZE][SIZE=2][COLOR=#a31515]"_responses.XML"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

But it only seems as good as my first approach which was more or less as in the simple DataGridView binding above using the XmlDataDocument.DataSet.ReadXml() method. The XML file isn't being constantly updated as changes are made to the DataSet. Am I misunderstanding what is being synchronized? What's my best approach if I want the XML file on disk to be updated with every change to the DataSet in memory? Should I be generating the XML files in the first application with or without the schema? If with, how can I use it to type the DataSet? Or do I even want to?

I'm not sure if they'll matter, but I want to include the xsd and some xml file data for completeness:
HTML:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="batchItems" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="imageXML">
<xs:complexType>
<xs:sequence>
<xs:element name="image_id" type="xs:int" minOccurs="0" />
<xs:element name="image_name" type="xs:string" minOccurs="0" />
<xs:element name="sort_order_original" type="xs:int" minOccurs="0" />
<xs:element name="sort_order_new" type="xs:int" minOccurs="0" />
<xs:element name="category_number" type="xs:int" minOccurs="0" />
<xs:element name="comment" type="xs:string" minOccurs="0" />
<xs:element name="rescan_flag" type="xs:boolean" minOccurs="0" />
<xs:element name="delete_flag" type="xs:boolean" minOccurs="0" />
<xs:element name="flip_image_flag" type="xs:short" minOccurs="0" />
<xs:element name="updated_by" type="xs:string" minOccurs="0" />
<xs:element name="last_updated" type="xs:dateTime" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
HTML:
<NewDataSet>
<imageXML>
<image_id>9106</image_id>
<image_name>\\abtscan03\Processed$\DS\newProcessing\261___31663\originals\261___31663___10001000___00001.tif</image_name>
<sort_order_original>1</sort_order_original>
<sort_order_new>1</sort_order_new>
<category_number>99999</category_number>
<comment />
<rescan_flag>false</rescan_flag>
<delete_flag>false</delete_flag>
<flip_image_flag>0</flip_image_flag>
<updated_by>dssBuilder</updated_by>
<last_updated>2007-02-26T10:08:43-06:00</last_updated>
</imageXML>
<imageXML>
<image_id>9107</image_id>
<image_name>\\abtscan03\Processed$\DS\newProcessing\261___31663\originals\261___31663___10001000___00002.tif</image_name>
<sort_order_original>2</sort_order_original>
<sort_order_new>2</sort_order_new>
<category_number>99999</category_number>
<comment />
<rescan_flag>false</rescan_flag>
<delete_flag>false</delete_flag>
<flip_image_flag>0</flip_image_flag>
<updated_by>dssBuilder</updated_by>
<last_updated>2007-02-26T10:08:43-06:00</last_updated>
</imageXML>
</NewDataSet>
 
Last edited by a moderator:
OK, well, by reading and hacking at every possible combination of methods in every order (well, not really, but you get the idea) I've gotten to my next hurdle.
I used the xsd.exe to do something -- convert my schema to a "Partial Public Class," I guess. So now I'm declaring:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] mainXML [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] XmlDataDocument[/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] typedBatchData [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] batchItems[/SIZE]
Then I load these with the following sub:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] dataPrep()[/SIZE]
[SIZE=2]typedBatchData = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] batchItems[/SIZE]
[SIZE=2]typedBatchData.ReadXml(inputPathName)[/SIZE]
[SIZE=2]mainXML = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] XmlDataDocument(typedBatchData)[/SIZE]
 
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2]
[/SIZE]
I guess in the end, it worked pretty well. I'm uncomfortable using the typed DataSet class thing because I don't understand it well, but I guess that's how I learn new techniques. :)
 
Last edited:
Back
Top