XML to save some settings

  • Thread starter Thread starter Eric bouxirot
  • Start date Start date
E

Eric bouxirot

hi there,

i never used XML beforre, i prefere INI files, but i want do same
things with XML file format..

before i can save/read some element of INI files without the need to
parse or read all the file.. juste like getxxxxINI("Section", "Key")
and it return a string...
same for writing..without need to rewrite all the file..

is it possible to do same things with XML and all XML class in VB.NET
??

do you have some links or samples ??

thank a lot.
 
Eric said:
hi there,

i never used XML beforre, i prefere INI files, but i want do same
things with XML file format..

before i can save/read some element of INI files without the need to
parse or read all the file.. juste like getxxxxINI("Section", "Key")
and it return a string...
same for writing..without need to rewrite all the file..

is it possible to do same things with XML and all XML class in VB.NET
??

do you have some links or samples ??

thank a lot.

You need to figure out XML Serialization. Once you do, you will never
go back to INI files. After serializing an XML, everything in it is
availble as a bunch or properties.
 
You need to figure out XML Serialization. Once you do, you will never
go back to INI files. After serializing an XML, everything in it is
availble as a bunch or properties.

Er, that should be after DE-serializing an XML file, the entire
contents are in a bunch of properties.

The trick is setting up a class structure that mirrors the structure of
the XML file.
 
Er, that should be after DE-serializing an XML file, the entire
contents are in a bunch of properties.

The trick is setting up a class structure that mirrors the structure of
the XML file.

ok, i understand, but if in futur i need to enhance the stucture of
data, then i can't read anymore the settings....
is it right ?
then, how can i do ?

thanks
 
Eric said:
ok, i understand, but if in futur i need to enhance the stucture of
data, then i can't read anymore the settings....
is it right ?
then, how can i do ?

thanks

English must be your second language as your question is a bit garbled.
But if I understand correctly, if you need to add more settings to the
XML file, you would just add the appropriate properties to the already
existing class structure. The first time the XML file is serialized,
the new properties would show up as new XML nodes.

Using XML for a settings file is mainly for fairly complex applications
settings. If your need is simple, the My.Settings facility in Visual
Studio is actually easier to use.
 
Eric said:
ok, i understand, but if in futur i need to enhance the stucture of
data, then i can't read anymore the settings....
is it right ?
then, how can i do ?

thanks

English must be your second language as your question is a bit garbled.
But if I understand correctly, if you need to add more settings to the
XML file, you would just add the appropriate properties to the already
existing class structure. The first time the XML file is serialized,
the new properties would show up as new XML nodes.

Using XML for a settings file is mainly for fairly complex applications
settings. If your need is simple, the My.Settings facility in Visual
Studio is actually easier to use.
 
English must be your second language as your question is a bit garbled.

oh...my english is so bad ??
:)
But if I understand correctly, if you need to add more settings to the
XML file, you would just add the appropriate properties to the already
existing class structure. The first time the XML file is serialized,
the new properties would show up as new XML nodes.

it's ok. do you have any example ?
Using XML for a settings file is mainly for fairly complex applications
settings. If your need is simple, the My.Settings facility in Visual
Studio is actually easier to use.

i want to learn XML too... if i use XML now here for simple
application, then i learn how it work and i can use it in more complex
applications for other things later...

thanks
 
The problem with XML Serialization is just the case the Eric states, if he
needs to add properties later, then adds them to the class, then tries to
deserialize one that's serialized with differening properties, he's kind of
sol...

Learning the XML is, perhaps, a better solution to his current problem.
One of the things I often do is start with an template XML file to use in my
applications. Although, it's not that difficult to create one on the fly.
You might want to take a look at the XmlDocument class in the .NET Framework

Let's say you open a template xml file with an object of XmlDocument type

Dim xdoc As New XmlDocument

xdoc.load("somefile")
'Get the root of the document

dim root as XmlElement
root = xdoc.DocumentElement

'Add and element to an Element that already exists
Dim node As XmlNode = root.SelectSingleNode("SomeElementName")
If Not node Is Nothing Then
Dim NewNode As XmlNode = xdoc.CreateElement("ElementName")
' Add the new node to the node you searched for
node.AppendChild(NewNode)
End if

' Iterating nodes
Dim node as XmlNode = root.SelectSingleNode("nodename")

For Each n as XmlNode In node.ChildNodes
' do something with n
Next

' Save the changes after iterating
xdoc.save()

HTH
Steve
 
Back
Top