By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Visual basic express, read and update Xml file

P: n/a
Hi,

I'm steel trying to read and update my XML file with Visual Basic
Express but i am unable to find the right way to read my xml file and
update it if neccessary...

Here is my problem : evry day, i store the number of children in my
classroom in my XML file. For exemple, on monday, my app ask me
something like this : msgbox ("Are the 28 children here today ?",vbyesno)

If not, I write 25 in an inputbox and i store this information in the xml.

On tuesday, I run my app and I would like to be asked :
"Are the 3 children (which where missing yesterday) back today ?"

If yes, I want to store 28 in the xml file. If not, I store the number
written
in my inputbox.

Etc...

At the end, i would like to see my xml file in a treeView and be able to
retrive all the info stored in the differents nodes (Year, month, day).

Does anybody knoes how can I do ?

Think you for your attention (and sorry for my english)...

Evelyne

Feb 28 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
On Feb 28, 3:32 am, <fenouillet...@laposte.netwrote:
Hi,

I'm steel trying to read and update my XML file with Visual Basic
Express but i am unable to find the right way to read my xml file and
update it if neccessary...

Here is my problem : evry day, i store the number of children in my
classroom in my XML file. For exemple, on monday, my app ask me
something like this : msgbox ("Are the 28 children here today ?",vbyesno)

If not, I write 25 in an inputbox and i store this information in the xml.

On tuesday, I run my app and I would like to be asked :
"Are the 3 children (which where missing yesterday) back today ?"

If yes, I want to store 28 in the xml file. If not, I store the number
written
in my inputbox.

Etc...

At the end, i would like to see my xml file in a treeView and be able to
retrive all the info stored in the differents nodes (Year, month, day).

Does anybody knoes how can I do ?

Think you for your attention (and sorry for my english)...

Evelyne
All the Xml related classes are in the System.Xml namespace, so you
might want to pull up object browser and look at those classes.

Here's a quick example of an update routine that sets each Child1 node
to "Hello World!":

' An Xml File

<BaseNode>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
</BaseNode>

<pseudocode>

' Imports System.Xml is needed

Dim doc as new XmlDocument
doc.Load("C:\MyPath\MyXmlFile.xml")
for each node as XmlNode in doc.GetElementsByTagName("Parent")
if node.Name = "Child1" then
node.InnerText = "Hello World!"
end if
next

</pseudocode>

If you need something more specific, and can't find the answer in the
archives, please post back and I'll try to help.

Thanks,

Seth Rowe

Feb 28 '07 #2

P: n/a
"rowe_newsgroups" <ro********@yahoo.coma écrit dans le message de news:
11**********************@8g2000cwh.googlegroups.co m...
On Feb 28, 3:32 am, <fenouillet...@laposte.netwrote:
>Hi,

I'm steel trying to read and update my XML file with Visual Basic
Express but i am unable to find the right way to read my xml file and
update it if neccessary...

Here is my problem : evry day, i store the number of children in my
classroom in my XML file. For exemple, on monday, my app ask me
something like this : msgbox ("Are the 28 children here today ?",vbyesno)

If not, I write 25 in an inputbox and i store this information in the
xml.

On tuesday, I run my app and I would like to be asked :
"Are the 3 children (which where missing yesterday) back today ?"

If yes, I want to store 28 in the xml file. If not, I store the number
written
in my inputbox.

Etc...

At the end, i would like to see my xml file in a treeView and be able to
retrive all the info stored in the differents nodes (Year, month, day).

Does anybody knoes how can I do ?

Think you for your attention (and sorry for my english)...

Evelyne

All the Xml related classes are in the System.Xml namespace, so you
might want to pull up object browser and look at those classes.

Here's a quick example of an update routine that sets each Child1 node
to "Hello World!":

' An Xml File

<BaseNode>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
</BaseNode>

<pseudocode>

' Imports System.Xml is needed

Dim doc as new XmlDocument
doc.Load("C:\MyPath\MyXmlFile.xml")
for each node as XmlNode in doc.GetElementsByTagName("Parent")
if node.Name = "Child1" then
node.InnerText = "Hello World!"
end if
next

</pseudocode>

If you need something more specific, and can't find the answer in the
archives, please post back and I'll try to help.

Thanks,

Seth Rowe
Hi,
thank you very much for your reply.

In my XML file, the informations are stored like that :

<PUPILL_CP_1>
<YEAR_2006>
<OCTOBRE EffectifDeLaClasse="28" Presents="25" Absents="3" Comment="" />
<NOVEMBRE EffectifDeLaClasse="28" Presents="28" Absents="0"
Comment="...." />
<DECEMBRE EffectifDeLaClasse="28" Presents="20" Absents="5"
Comment="blabla bla" />
</YEAR_2006>
<YEAR_2007>
<JANVIER EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="DANGER important desease"/>
<FEVRIER EffectifDeLaClasse="28" Presents="27" Absents="1"
Comment="something else" />
<MARS EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="something" />
</YEAR_2007>
</PUPILL_CP_1>

Thanks to your help, I am now able to read my xml file. Then, if it's
possible,
I would like to do the following .

1/ While reading my XML file, I would like to update the attributs of the
nodes.

For exemple, if I run my app in marsh and if my app read this
Comment="DANGER
important desease" (in the node <JANVIER EffectifDeLaClasse="28"
Presents="10"
Absents="18" Comment="DANGER important desease"/>)
I would like to have a message like :

If Msgbox("In Marsh 2007, do you know something about the desease in
<JANVIER>
<2007?", VbYesNo) = VbYes then inputbox("Write a new comment about the
<JANVIER>
<2007desease.") end if
and then update the XML file and continue to read the file.

2/ Once my xml file is updated, I raise it in a TreeView. Then, when I click
on
the Node <YEAR_2006>, I would like to have a MsgBox where all the SubNodes
<OCTOBRE<NOVEMBRE<DÉCEMBREare listed.

If my explanations are clear enough, may be you know so practical solution
as the
previous you have already given to me !!!

Best regards,

Evelyne
Mar 1 '07 #3

P: n/a
On Mar 1, 1:43 am, <fenouillet...@laposte.netwrote:
"rowe_newsgroups" <rowe_em...@yahoo.coma écrit dans le message de news:
1172672252.407949.113...@8g2000cwh.googlegroups.co m...
On Feb 28, 3:32 am, <fenouillet...@laposte.netwrote:
Hi,
I'm steel trying to read and update my XML file with Visual Basic
Express but i am unable to find the right way to read my xml file and
update it if neccessary...
Here is my problem : evry day, i store the number of children in my
classroom in my XML file. For exemple, on monday, my app ask me
something like this : msgbox ("Are the 28 children here today ?",vbyesno)
If not, I write 25 in an inputbox and i store this information in the
xml.
On tuesday, I run my app and I would like to be asked :
"Are the 3 children (which where missing yesterday) back today ?"
If yes, I want to store 28 in the xml file. If not, I store the number
written
in my inputbox.
Etc...
At the end, i would like to see my xml file in a treeView and be able to
retrive all the info stored in the differents nodes (Year, month, day).
Does anybody knoes how can I do ?
Think you for your attention (and sorry for my english)...
Evelyne
All the Xml related classes are in the System.Xml namespace, so you
might want to pull up object browser and look at those classes.
Here's a quick example of an update routine that sets each Child1 node
to "Hello World!":
' An Xml File
<BaseNode>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
</BaseNode>
<pseudocode>
' Imports System.Xml is needed
Dim doc as new XmlDocument
doc.Load("C:\MyPath\MyXmlFile.xml")
for each node as XmlNode in doc.GetElementsByTagName("Parent")
if node.Name = "Child1" then
node.InnerText = "Hello World!"
end if
next
</pseudocode>
If you need something more specific, and can't find the answer in the
archives, please post back and I'll try to help.
Thanks,
Seth Rowe

Hi,
thank you very much for your reply.

In my XML file, the informations are stored like that :

<PUPILL_CP_1>
<YEAR_2006>
<OCTOBRE EffectifDeLaClasse="28" Presents="25" Absents="3" Comment="" />
<NOVEMBRE EffectifDeLaClasse="28" Presents="28" Absents="0"
Comment="...." />
<DECEMBRE EffectifDeLaClasse="28" Presents="20" Absents="5"
Comment="blabla bla" />
</YEAR_2006>
<YEAR_2007>
<JANVIER EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="DANGER important desease"/>
<FEVRIER EffectifDeLaClasse="28" Presents="27" Absents="1"
Comment="something else" />
<MARS EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="something" />
</YEAR_2007>
</PUPILL_CP_1>

Thanks to your help, I am now able to read my xml file. Then, if it's
possible,
I would like to do the following .

1/ While reading my XML file, I would like to update the attributs of the
nodes.

For exemple, if I run my app in marsh and if my app read this
Comment="DANGER
important desease" (in the node <JANVIER EffectifDeLaClasse="28"
Presents="10"
Absents="18" Comment="DANGER important desease"/>)
I would like to have a message like :

If Msgbox("In Marsh 2007, do you know something about the desease in
<JANVIER>
<2007?", VbYesNo) = VbYes then inputbox("Write a new comment about the
<JANVIER>
<2007desease.") end if
and then update the XML file and continue to read the file.

2/ Once my xml file is updated, I raise it in a TreeView. Then, when I click
on
the Node <YEAR_2006>, I would like to have a MsgBox where all the SubNodes
<OCTOBRE<NOVEMBRE<DÉCEMBREare listed.

If my explanations are clear enough, may be you know so practical solution
as the
previous you have already given to me !!!

Best regards,

Evelyne
Getting attributes is fairly easier, XmlNode has a property called
Attributes that is a collection of node's attributes. You can do
something like this to get the comment out of the JANVIER node in
<YEAR_2007>

<pseudocode>

Dim doc as new XmlDocument()
doc.Load("MyXml.xml")
for each node as XmlNode in doc.GetElementsByTagName("YEAR_2007")
if node.Name = "JANVIER" then
' Show the value of the comments attribute
MessageBox.Show(node.Attributes("comments").Value. ToString())
' Update it's value
node.Attributes("comments").Value = "Hello World!"
end if
next

</pseudocode>

That should take care of the attributes. On to the TreeView!

If I understood correctly, you want to use a TreeView to mimic the
layout of the Xml file right?

I dropped your Xml into a file on my desktop and wrote a quick app
that loads the nodes and attributes into a TreeView (called TreeView1)
on a form. Let me know how it works!

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim doc As New XmlDocument()
doc.Load("C:\Documents and Settings\srowe\Desktop\test.xml")
Dim node As XmlNode = doc.ChildNodes(0)
Dim tNode As New TreeNode(node.Name)
Me.TreeView1.Nodes.Add(tNode)
For Each child As XmlNode In node.ChildNodes
AddNodetoTreeview(child, tNode)
Next
End Sub

Private Sub AddNodetoTreeview(ByVal node As XmlNode, ByVal parent
As TreeNode)
Dim tNode As New TreeNode(node.Name)
parent.Nodes.Add(tNode)
For Each n As XmlNode In node.ChildNodes
AddNodetoTreeview(n, tNode)
Next
For Each a As XmlAttribute In node.Attributes
tNode.Nodes.Add(String.Format("{0} - {1}", a.Name,
a.Value))
Next
End Sub

Thanks,

Seth Rowe

Mar 1 '07 #4

P: n/a
E.F

"rowe_newsgroups" <ro********@yahoo.coma écrit dans le message de news:
11*********************@n33g2000cwc.googlegroups.c om...
On Mar 1, 1:43 am, <fenouillet...@laposte.netwrote:
"rowe_newsgroups" <rowe_em...@yahoo.coma écrit dans le message de news:
1172672252.407949.113...@8g2000cwh.googlegroups.co m...
On Feb 28, 3:32 am, <fenouillet...@laposte.netwrote:
Hi,
I'm steel trying to read and update my XML file with Visual Basic
Express but i am unable to find the right way to read my xml file and
update it if neccessary...
Here is my problem : evry day, i store the number of children in my
classroom in my XML file. For exemple, on monday, my app ask me
something like this : msgbox ("Are the 28 children here today
?",vbyesno)
If not, I write 25 in an inputbox and i store this information in the
xml.
On tuesday, I run my app and I would like to be asked :
"Are the 3 children (which where missing yesterday) back today ?"
If yes, I want to store 28 in the xml file. If not, I store the number
written
in my inputbox.
Etc...
At the end, i would like to see my xml file in a treeView and be able
to
retrive all the info stored in the differents nodes (Year, month, day).
Does anybody knoes how can I do ?
Think you for your attention (and sorry for my english)...
Evelyne
All the Xml related classes are in the System.Xml namespace, so you
might want to pull up object browser and look at those classes.
Here's a quick example of an update routine that sets each Child1 node
to "Hello World!":
' An Xml File
<BaseNode>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
</BaseNode>
<pseudocode>
' Imports System.Xml is needed
Dim doc as new XmlDocument
doc.Load("C:\MyPath\MyXmlFile.xml")
for each node as XmlNode in doc.GetElementsByTagName("Parent")
if node.Name = "Child1" then
node.InnerText = "Hello World!"
end if
next
</pseudocode>
If you need something more specific, and can't find the answer in the
archives, please post back and I'll try to help.
Thanks,
Seth Rowe

Hi,
thank you very much for your reply.

In my XML file, the informations are stored like that :

<PUPILL_CP_1>
<YEAR_2006>
<OCTOBRE EffectifDeLaClasse="28" Presents="25" Absents="3" Comment=""
/>
<NOVEMBRE EffectifDeLaClasse="28" Presents="28" Absents="0"
Comment="...." />
<DECEMBRE EffectifDeLaClasse="28" Presents="20" Absents="5"
Comment="blabla bla" />
</YEAR_2006>
<YEAR_2007>
<JANVIER EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="DANGER important desease"/>
<FEVRIER EffectifDeLaClasse="28" Presents="27" Absents="1"
Comment="something else" />
<MARS EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="something" />
</YEAR_2007>
</PUPILL_CP_1>

Thanks to your help, I am now able to read my xml file. Then, if it's
possible,
I would like to do the following .

1/ While reading my XML file, I would like to update the attributs of the
nodes.

For exemple, if I run my app in marsh and if my app read this
Comment="DANGER
important desease" (in the node <JANVIER EffectifDeLaClasse="28"
Presents="10"
Absents="18" Comment="DANGER important desease"/>)
I would like to have a message like :

If Msgbox("In Marsh 2007, do you know something about the desease in
<JANVIER>
<2007?", VbYesNo) = VbYes then inputbox("Write a new comment about the
<JANVIER>
<2007desease.") end if
and then update the XML file and continue to read the file.

2/ Once my xml file is updated, I raise it in a TreeView. Then, when I
click
on
the Node <YEAR_2006>, I would like to have a MsgBox where all the
SubNodes
<OCTOBRE<NOVEMBRE<DÉCEMBREare listed.

If my explanations are clear enough, may be you know so practical solution
as the
previous you have already given to me !!!

Best regards,

Evelyne
Getting attributes is fairly easier, XmlNode has a property called
Attributes that is a collection of node's attributes. You can do
something like this to get the comment out of the JANVIER node in
<YEAR_2007>

<pseudocode>

Dim doc as new XmlDocument()
doc.Load("MyXml.xml")
for each node as XmlNode in doc.GetElementsByTagName("YEAR_2007")
if node.Name = "JANVIER" then
' Show the value of the comments attribute
MessageBox.Show(node.Attributes("comments").Value. ToString())
' Update it's value
node.Attributes("comments").Value = "Hello World!"
end if
next

</pseudocode>

That should take care of the attributes. On to the TreeView!

If I understood correctly, you want to use a TreeView to mimic the
layout of the Xml file right?

I dropped your Xml into a file on my desktop and wrote a quick app
that loads the nodes and attributes into a TreeView (called TreeView1)
on a form. Let me know how it works!

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim doc As New XmlDocument()
doc.Load("C:\Documents and Settings\srowe\Desktop\test.xml")
Dim node As XmlNode = doc.ChildNodes(0)
Dim tNode As New TreeNode(node.Name)
Me.TreeView1.Nodes.Add(tNode)
For Each child As XmlNode In node.ChildNodes
AddNodetoTreeview(child, tNode)
Next
End Sub

Private Sub AddNodetoTreeview(ByVal node As XmlNode, ByVal parent
As TreeNode)
Dim tNode As New TreeNode(node.Name)
parent.Nodes.Add(tNode)
For Each n As XmlNode In node.ChildNodes
AddNodetoTreeview(n, tNode)
Next
For Each a As XmlAttribute In node.Attributes
tNode.Nodes.Add(String.Format("{0} - {1}", a.Name,
a.Value))
Next
End Sub

Thanks,

Seth Rowe
'""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""
Hi,

one more time, I am very grateful to you !

Thanks to your previous explanation, I can display all the attributs
of my elements in my treeview.

But now, I need to be able to modify or to update those attributs, not
directly on the treeview, but with an update function.

To do that, I have written a procedure which allows me, each time y drop
my treeview, to put the values of the attributs in a string whitch is added
to the tag of the node .

Then, when I click on one node, with the split function, each element of the
string (stored in the tag) are displayed in differents textboxes
corresponding
with each attributes of my treewiew.

But I am afraid of not using the more safe or appropriate function... In
this case
and if I have managed to be understood, may be know you some lines of code
which will allow me to reach my purpose ?

Thanks for your attention,

Evelyne

Mar 5 '07 #5

P: n/a
On Mar 5, 4:13 am, "E.F" <fenouillet...@laposte.etwrote:
"rowe_newsgroups" <rowe_em...@yahoo.coma écrit dans le message de news:
1172759199.588075.94...@n33g2000cwc.googlegroups.c om...
On Mar 1, 1:43 am, <fenouillet...@laposte.netwrote:
"rowe_newsgroups" <rowe_em...@yahoo.coma écrit dans le message de news:
1172672252.407949.113...@8g2000cwh.googlegroups.co m...
On Feb 28, 3:32 am, <fenouillet...@laposte.netwrote:
>Hi,
>I'm steel trying to read and update my XML file with Visual Basic
>Express but i am unable to find the right way to read my xml file and
>update it if neccessary...
>Here is my problem : evry day, i store the number of children in my
>classroom in my XML file. For exemple, on monday, my app ask me
>something like this : msgbox ("Are the 28 children here today
>?",vbyesno)
>If not, I write 25 in an inputbox and i store this information in the
>xml.
>On tuesday, I run my app and I would like to be asked :
>"Are the 3 children (which where missing yesterday) back today ?"
>If yes, I want to store 28 in the xml file. If not, I store the number
>written
>in my inputbox.
>Etc...
>At the end, i would like to see my xml file in a treeView and be able
>to
>retrive all the info stored in the differents nodes (Year, month, day).
>Does anybody knoes how can I do ?
>Think you for your attention (and sorry for my english)...
>Evelyne
All the Xml related classes are in the System.Xml namespace, so you
might want to pull up object browser and look at those classes.
Here's a quick example of an update routine that sets each Child1 node
to "Hello World!":
' An Xml File
<BaseNode>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
</BaseNode>
<pseudocode>
' Imports System.Xml is needed
Dim doc as new XmlDocument
doc.Load("C:\MyPath\MyXmlFile.xml")
for each node as XmlNode in doc.GetElementsByTagName("Parent")
if node.Name = "Child1" then
node.InnerText = "Hello World!"
end if
next
</pseudocode>
If you need something more specific, and can't find the answer in the
archives, please post back and I'll try to help.
Thanks,
Seth Rowe
Hi,
thank you very much for your reply.
In my XML file, the informations are stored like that :
<PUPILL_CP_1>
<YEAR_2006>
<OCTOBRE EffectifDeLaClasse="28" Presents="25" Absents="3" Comment=""
/>
<NOVEMBRE EffectifDeLaClasse="28" Presents="28" Absents="0"
Comment="...." />
<DECEMBRE EffectifDeLaClasse="28" Presents="20" Absents="5"
Comment="blabla bla" />
</YEAR_2006>
<YEAR_2007>
<JANVIER EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="DANGER important desease"/>
<FEVRIER EffectifDeLaClasse="28" Presents="27" Absents="1"
Comment="something else" />
<MARS EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="something" />
</YEAR_2007>
</PUPILL_CP_1>
Thanks to your help, I am now able to read my xml file. Then, if it's
possible,
I would like to do the following .
1/ While reading my XML file, I would like to update the attributs of the
nodes.
For exemple, if I run my app in marsh and if my app read this
Comment="DANGER
important desease" (in the node <JANVIER EffectifDeLaClasse="28"
Presents="10"
Absents="18" Comment="DANGER important desease"/>)
I would like to have a message like :
If Msgbox("In Marsh 2007, do you know something about the desease in
<JANVIER>
<2007?", VbYesNo) = VbYes then inputbox("Write a new comment about the
<JANVIER>
<2007desease.") end if
and then update the XML file and continue to read the file.
2/ Once my xml file is updated, I raise it in a TreeView. Then, when I
click
on
the Node <YEAR_2006>, I would like to have a MsgBox where all the
SubNodes
<OCTOBRE<NOVEMBRE<DÉCEMBREare listed.
If my explanations are clear enough, may be you know so practical solution
as the
previous you have already given to me !!!
Best regards,
Evelyne

Getting attributes is fairly easier, XmlNode has a property called
Attributes that is a collection of node's attributes. You can do
something like this to get the comment out of the JANVIER node in
<YEAR_2007>

<pseudocode>

Dim doc as new XmlDocument()
doc.Load("MyXml.xml")
for each node as XmlNode in doc.GetElementsByTagName("YEAR_2007")
if node.Name = "JANVIER" then
' Show the value of the comments attribute
MessageBox.Show(node.Attributes("comments").Value. ToString())
' Update it's value
node.Attributes("comments").Value = "Hello World!"
end if
next

</pseudocode>

That should take care of the attributes. On to the TreeView!

If I understood correctly, you want to use a TreeView to mimic the
layout of the Xml file right?

I dropped your Xml into a file on my desktop and wrote a quick app
that loads the nodes and attributes into a TreeView (called TreeView1)
on a form. Let me know how it works!

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim doc As New XmlDocument()
doc.Load("C:\Documents and Settings\srowe\Desktop\test.xml")
Dim node As XmlNode = doc.ChildNodes(0)
Dim tNode As New TreeNode(node.Name)
Me.TreeView1.Nodes.Add(tNode)
For Each child As XmlNode In node.ChildNodes
AddNodetoTreeview(child, tNode)
Next
End Sub

Private Sub AddNodetoTreeview(ByVal node As XmlNode, ByVal parent
As TreeNode)
Dim tNode As New TreeNode(node.Name)
parent.Nodes.Add(tNode)
For Each n As XmlNode In node.ChildNodes
AddNodetoTreeview(n, tNode)
Next
For Each a As XmlAttribute In node.Attributes
tNode.Nodes.Add(String.Format("{0} - {1}", a.Name,
a.Value))
Next
End Sub

Thanks,

Seth Rowe
'""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""
Hi,

one more time, I am very grateful to you !

Thanks to your previous explanation, I can display all the attributs
of my elements in my treeview.

But now, I need to be able to modify or to update those attributs, not
directly on the treeview, but with an update function.

To do that, I have written a procedure which allows me, each time y drop
my treeview, to put the values of the attributs in a string whitch is added
to the tag of the node .

Then, when I click on one node, with the split function, each element of the
string (stored in the tag) are displayed in differents textboxes
corresponding
with each attributes of my treewiew.

But I am afraid of not using the more safe or appropriate function... In
this case
and if I have managed to be understood, may be know you some lines of code
which will allow me to reach my purpose ?

Thanks for your attention,

Evelyne
I'm not sure I follow. Do you have a procedure that does what you need
and just aren't sure if it's the best way? If so please post the code
and I'll be happy to look at it.

Thanks,

Seth Rowe

Mar 5 '07 #6

P: n/a
"rowe_newsgroups" <ro********@yahoo.coma écrit dans le message de news:
11*********************@30g2000cwc.googlegroups.co m...
On Mar 5, 4:13 am, "E.F" <fenouillet...@laposte.etwrote:
"rowe_newsgroups" <rowe_em...@yahoo.coma écrit dans le message de news:
1172759199.588075.94...@n33g2000cwc.googlegroups.c om...
On Mar 1, 1:43 am, <fenouillet...@laposte.netwrote:
"rowe_newsgroups" <rowe_em...@yahoo.coma écrit dans le message de
news:
1172672252.407949.113...@8g2000cwh.googlegroups.co m...
On Feb 28, 3:32 am, <fenouillet...@laposte.netwrote:
>Hi,
>I'm steel trying to read and update my XML file with Visual Basic
>Express but i am unable to find the right way to read my xml file and
>update it if neccessary...
>Here is my problem : evry day, i store the number of children in my
>classroom in my XML file. For exemple, on monday, my app ask me
>something like this : msgbox ("Are the 28 children here today
>?",vbyesno)
>If not, I write 25 in an inputbox and i store this information in the
>xml.
>On tuesday, I run my app and I would like to be asked :
>"Are the 3 children (which where missing yesterday) back today ?"
>If yes, I want to store 28 in the xml file. If not, I store the
>number
>written
>in my inputbox.
>Etc...
>At the end, i would like to see my xml file in a treeView and be able
>to
>retrive all the info stored in the differents nodes (Year, month,
>day).
>Does anybody knoes how can I do ?
>Think you for your attention (and sorry for my english)...
>Evelyne
All the Xml related classes are in the System.Xml namespace, so you
might want to pull up object browser and look at those classes.
Here's a quick example of an update routine that sets each Child1 node
to "Hello World!":
' An Xml File
<BaseNode>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
<Parent>
<Child1>InnerText</Child1>
<Child2>InnerText</Child2>
</Parent>
</BaseNode>
<pseudocode>
' Imports System.Xml is needed
Dim doc as new XmlDocument
doc.Load("C:\MyPath\MyXmlFile.xml")
for each node as XmlNode in doc.GetElementsByTagName("Parent")
if node.Name = "Child1" then
node.InnerText = "Hello World!"
end if
next
</pseudocode>
If you need something more specific, and can't find the answer in the
archives, please post back and I'll try to help.
Thanks,
Seth Rowe
Hi,
thank you very much for your reply.
In my XML file, the informations are stored like that :
<PUPILL_CP_1>
<YEAR_2006>
<OCTOBRE EffectifDeLaClasse="28" Presents="25" Absents="3"
Comment=""
/>
<NOVEMBRE EffectifDeLaClasse="28" Presents="28" Absents="0"
Comment="...." />
<DECEMBRE EffectifDeLaClasse="28" Presents="20" Absents="5"
Comment="blabla bla" />
</YEAR_2006>
<YEAR_2007>
<JANVIER EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="DANGER important desease"/>
<FEVRIER EffectifDeLaClasse="28" Presents="27" Absents="1"
Comment="something else" />
<MARS EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="something" />
</YEAR_2007>
</PUPILL_CP_1>
Thanks to your help, I am now able to read my xml file. Then, if it's
possible,
I would like to do the following .
1/ While reading my XML file, I would like to update the attributs of
the
nodes.
For exemple, if I run my app in marsh and if my app read this
Comment="DANGER
important desease" (in the node <JANVIER EffectifDeLaClasse="28"
Presents="10"
Absents="18" Comment="DANGER important desease"/>)
I would like to have a message like :
If Msgbox("In Marsh 2007, do you know something about the desease in
<JANVIER>
<2007?", VbYesNo) = VbYes then inputbox("Write a new comment about the
<JANVIER>
<2007desease.") end if
and then update the XML file and continue to read the file.
2/ Once my xml file is updated, I raise it in a TreeView. Then, when I
click
on
the Node <YEAR_2006>, I would like to have a MsgBox where all the
SubNodes
<OCTOBRE<NOVEMBRE<DÉCEMBREare listed.
If my explanations are clear enough, may be you know so practical
solution
as the
previous you have already given to me !!!
Best regards,
Evelyne

Getting attributes is fairly easier, XmlNode has a property called
Attributes that is a collection of node's attributes. You can do
something like this to get the comment out of the JANVIER node in
<YEAR_2007>

<pseudocode>

Dim doc as new XmlDocument()
doc.Load("MyXml.xml")
for each node as XmlNode in doc.GetElementsByTagName("YEAR_2007")
if node.Name = "JANVIER" then
' Show the value of the comments attribute
MessageBox.Show(node.Attributes("comments").Value. ToString())
' Update it's value
node.Attributes("comments").Value = "Hello World!"
end if
next

</pseudocode>

That should take care of the attributes. On to the TreeView!

If I understood correctly, you want to use a TreeView to mimic the
layout of the Xml file right?

I dropped your Xml into a file on my desktop and wrote a quick app
that loads the nodes and attributes into a TreeView (called TreeView1)
on a form. Let me know how it works!

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim doc As New XmlDocument()
doc.Load("C:\Documents and Settings\srowe\Desktop\test.xml")
Dim node As XmlNode = doc.ChildNodes(0)
Dim tNode As New TreeNode(node.Name)
Me.TreeView1.Nodes.Add(tNode)
For Each child As XmlNode In node.ChildNodes
AddNodetoTreeview(child, tNode)
Next
End Sub

Private Sub AddNodetoTreeview(ByVal node As XmlNode, ByVal parent
As TreeNode)
Dim tNode As New TreeNode(node.Name)
parent.Nodes.Add(tNode)
For Each n As XmlNode In node.ChildNodes
AddNodetoTreeview(n, tNode)
Next
For Each a As XmlAttribute In node.Attributes
tNode.Nodes.Add(String.Format("{0} - {1}", a.Name,
a.Value))
Next
End Sub

Thanks,

Seth Rowe
'""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""
Hi,

one more time, I am very grateful to you !

Thanks to your previous explanation, I can display all the attributs
of my elements in my treeview.

But now, I need to be able to modify or to update those attributs, not
directly on the treeview, but with an update function.

To do that, I have written a procedure which allows me, each time y drop
my treeview, to put the values of the attributs in a string whitch is
added
to the tag of the node .

Then, when I click on one node, with the split function, each element of
the
string (stored in the tag) are displayed in differents textboxes
corresponding
with each attributes of my treewiew.

But I am afraid of not using the more safe or appropriate function... In
this case
and if I have managed to be understood, may be know you some lines of code
which will allow me to reach my purpose ?

Thanks for your attention,

Evelyne
I'm not sure I follow. Do you have a procedure that does what you need
and just aren't sure if it's the best way? If so please post the code
and I'll be happy to look at it.

Thanks,

Seth Rowe

"""""
Thank you very much.

I have replied to you with a private message because I'm afraid that
my code won't be a good exemple for everybody...

Evelyne

Mar 6 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.