Internal Dataset or Internal XML File

tonycrew

Well-known member
Joined
Apr 20, 2009
Messages
55
Programming Experience
Beginner
Is it possible to have an internal XML dataset within a VB 08 program..?

I ask because we at present have the program load an external XML on startup, but i would prefer this to be internal withing the program to stop other editing the XML file.
 
A file is a file. You can embed XML into an executable but you can't then edit it. If you want a database with security then you need to use a database with security instead of an XML file. That said, you could encrypt. It won't stop people changing it but the file will become unusable if they do, so they can't falsify the data in it.
 
Cheers, i would like the XML then to be embeded... this way we can edit it in each new build... How would we do that..?
 
So, you're saying that you don't want to edit the XML data at run time? If so then you simply add your XML file as a resource on the Resources tab of the project properties, then get it back at run time from My.Resources.
 
We got all the My.Resources and all..

VB.NET:
ds2.ReadXml(My.Resources.sonyPS)

but it comes up with an error saying, (Illegal characters in path.)

and yes it is an xml..
 
We got all the My.Resources and all..

VB.NET:
ds2.ReadXml(My.Resources.sonyPS)

but it comes up with an error saying, (Illegal characters in path.)

and yes it is an xml..
What you're doing there is telling the DataSet to read the data in the file at the path contained in My.Resources.sonyPS. That isn't a file path at all though, is it? It's the actual XML code itself. If that overload of ReadXml is expecting a file path then you have to pass it a file path. If you don't have a file path then you can call that overload.

ReadXml will also accept a Stream, a TextReader or an XmlReader, so you need to create one of those that contains your XML data. The easiest option would to create a StringReader:
VB.NET:
Using reader As New IO.StringReader(My.Resources.sonyPS)
    ds2.ReadXml(reader)
End Using
A StringReader is like a StreamReader except it will read text from a string instead of from a file.
 
Back
Top