472,978 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,978 software developers and data experts.

Visual basic express, read and update Xml file

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
6 7215
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
"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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Bruno Jouhier [MVP] | last post by:
I'm currently experiencing a strange phenomenon: At my Office, Visual Studio takes a very long time to compile our solution (more than 1 minute for the first project). At home, Visual Studio...
1
by: Thomas Holmgren | last post by:
Hi all I've tried to get my hands on the End User License Agreement for MS Visual C# .NET 2003 STANDARD edition, sofar without luck. Does anybody know where I can find the license agreement...
2
by: Belee | last post by:
1. I am using sql server express and visual studio 2003. I have been able to create the connection to the database in server explorer but cannot update table definitions. It gives an error that...
5
by: Patrick Olurotimi Ige | last post by:
Hi, I have VStudio.Net 2003 installed but can i install Visual Web Developer also on the same PC. My current .Net Frameork version is 1.1. Will the Visual Web Developer install ASP.NET 2.0? And...
4
by: Andrew Robinson | last post by:
My main dev machine has WinXp and VS2005 (pro). 1. I need to install VWD Express Edition so that I can do some instruction on this. Any issues with both on the same machine. Installation order?...
1
by: Martin Racette | last post by:
Hi, I recently installed that programing environment, and I'm wondering how to do some of the things I created a program that renames, moves, and copies file, most of the routine are located...
2
by: dancer | last post by:
In Visual Basic 2005 Express Edition When I choose Console Application for the project, the source code page automatically comes up with: Module Module1 When I choose Windows Application, the...
3
by: =?Utf-8?B?Rmxhc2hwcm8=?= | last post by:
i have googled this question but cannot find an answer. i'm running windows vista and i'm using Visual Basic Express 2008. i know the build event button SHOULD be in under the compile tag but i...
11
by: =?Utf-8?B?UGV0ZXIgSw==?= | last post by:
I am working with Visual Studio or alternately with Expression Web. I need to create about 50 aspx pages with about 1200 thumbnali images, typically arranged in three to four groups per page,...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.