XML to save some settings

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.
 
Z

zacks

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.
 
Z

zacks

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.
 
E

Eric bouxirot

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
 
Z

zacks

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.
 
Z

zacks

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.
 
E

Eric bouxirot

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
 
S

Steve Long

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
 

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

change XML encoding 6
xml 1
Reading XML Encoding errors 12
Writing settings to a file??? XML control??? 19
Good tutorial for working with XML 17
Tab characters in an XML file 7
read and write to xml 1
INI or XML 9

Top