views:

57

answers:

1

I've written a DataSet to a XML file using .WriteXML(FileName), and the DataSetName property of the dataset is the top-level tag in the file. However, when I try to read the file into a different DataSet using .ReadXML(FileName), the DataSetName isn't changed to the value of the top-level tag. Am I doing something wrong, or is ReadXML not supposed to set the DataSetName? Just strikes me as odd that it writes it out but won't read it in.

Here's my writing code, the XML file, and the reading code:

Writing:

dsNewReport.DataSetName = "Rejected"
dsNewReport.WriteXml(My.Application.Info.DirectoryPath & "/Reports/Incomplete/" & fileName)

The resulting XML:

<?xml version="1.0" standalone="yes"?>
<Rejected>
  <SearchData>
  //SNIP
  </SearchData>
</Rejected>

Reading:

dsSearchReport.ReadXml(My.Application.Info.DirectoryPath & "/Reports/Incomplete/Search_" & Search_SEQ_GUID & ".xml")
If dsSearchReport.DataSetName = "Rejected" Then
    return True
    'DataSetName = dsSearchReport after the read      
End IF
+1  A: 

ReadXml is not designed or tasked with setting your DataSet name - you'll have to do this yourself.

Sure - in your case, you want to set it to the root level name - but that might not be what everyone wants. Someone else might want to set it to the filename - or even something completely different.

So as a compromise, the ReadXml function doesn't do anything at all - it won't touch your DataSet name in any way, shape or form. There's no error on your part - that's just the way it is.

Marc

marc_s
understandable, but WriteXML sets the root level name to the DataSetName...weird, eh?
Tom Grochowicz
well, again - I guess they had to choose some kind of a default, and the name you gave the DataSet seemed to make sense. I agree - it might be useful to have a parameter on ReadXml to indicate that you'd like to use the root element name as the DataSet name - it's just not there (yet?)....
marc_s