473,230 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to insert a node in xml using visual basic express ?

E.F
Hi everybody,

I get lost trying to insert a node in my xml file with
readfile, xpath, xpathnavigator, etc...

1/ my xml file looks 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" />
</YEAR_2007>
</PUPILL_CP_1>

2/ I want to insert this node
"<MARS EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="something" />"
afert the last (which is <FEVRIER EffectifDeLaClasse="28" Presents="27"
Absents="1" Comment="something else" />)

Does anybody can explain me the best way to select one nodes
while reading this file and after, the best way to insert my node ?

Thank you very much for your attention.

Evelyne
Mar 13 '07 #1
7 1448
E.F wrote:
1/ my xml file looks like that :

<PUPILL_CP_1>
<YEAR_2006>
<OCTOBRE EffectifDeLaClasse="28" Presents="25" Absents="3" Comment=""
^^^^^
That tag is not closed so the sample is not well-formed XML.
<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" />
</YEAR_2007>
</PUPILL_CP_1>

2/ I want to insert this node
"<MARS EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="something" />"
afert the last (which is <FEVRIER EffectifDeLaClasse="28" Presents="27"
Absents="1" Comment="something else" />)
Use XmlDocument like this:

Dim XmlDoc As XmlDocument = New XmlDocument()
XmlDoc.Load("..\..\XMLFile1.xml")
Dim Mars As XmlElement = XmlDoc.CreateElement("Mars")
Mars.SetAttribute("EffectifDeLaClasse", "28")
Mars.SetAttribute("Presents", "10")
Mars.SetAttribute("Absents", "18")
Mars.SetAttribute("Comment", "something")

XmlDoc.SelectSingleNode("(PUPILL_CP_1/*)[last()]").AppendChild(Mars)
' Saving to console for testing
' save to file in real application
XmlDoc.Save(Console.Out)
If you don't want the create the element and its attribute by hand with
several calls but want to parse a string then use e.g.

Dim XmlDoc As XmlDocument = New XmlDocument()
XmlDoc.Load("..\..\XMLFile1.xml")
Dim Fragment As XmlDocumentFragment =
XmlDoc.CreateDocumentFragment()
Fragment.InnerXml = "<MARS EffectifDeLaClasse=""28""
Presents=""10"" Absents=""18"" Comment=""something"" />"

XmlDoc.SelectSingleNode("(PUPILL_CP_1/*)[last()]").AppendChild(Fragment)
XmlDoc.Save(Console.Out)
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 13 '07 #2
On Mar 13, 12:39 am, "E.F" <fenouillet...@laposte.netwrote:
Does anybody can explain me the best way to select one nodes
while reading this file and after, the best way to insert my node ?

Thank you very much for your attention.

Evelyne
If you're not completely sold on using node/xml manipulation, I'd
recommend trying out serialization. I'm a lazy man and I find it a
lot easier to let the CLR handle all my reading/writing from XML and I
just pass it a class or expect a class back from it.

Mar 13 '07 #3
E.F

"Martin Honnen" <ma*******@yahoo.dea écrit dans le message de news:
uf**************@TK2MSFTNGP03.phx.gbl...
E.F wrote:
>1/ my xml file looks like that :

<PUPILL_CP_1>
<YEAR_2006>
<OCTOBRE EffectifDeLaClasse="28" Presents="25" Absents="3"
Comment=""

^^^^^
That tag is not closed so the sample is not well-formed XML.
> <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" />
</YEAR_2007>
</PUPILL_CP_1>

2/ I want to insert this node
"<MARS EffectifDeLaClasse="28" Presents="10" Absents="18"
Comment="something" />"
afert the last (which is <FEVRIER EffectifDeLaClasse="28" Presents="27"
Absents="1" Comment="something else" />)

Use XmlDocument like this:

Dim XmlDoc As XmlDocument = New XmlDocument()
XmlDoc.Load("..\..\XMLFile1.xml")
Dim Mars As XmlElement = XmlDoc.CreateElement("Mars")
Mars.SetAttribute("EffectifDeLaClasse", "28")
Mars.SetAttribute("Presents", "10")
Mars.SetAttribute("Absents", "18")
Mars.SetAttribute("Comment", "something")

XmlDoc.SelectSingleNode("(PUPILL_CP_1/*)[last()]").AppendChild(Mars)
' Saving to console for testing
' save to file in real application
XmlDoc.Save(Console.Out)
If you don't want the create the element and its attribute by hand with
several calls but want to parse a string then use e.g.

Dim XmlDoc As XmlDocument = New XmlDocument()
XmlDoc.Load("..\..\XMLFile1.xml")
Dim Fragment As XmlDocumentFragment =
XmlDoc.CreateDocumentFragment()
Fragment.InnerXml = "<MARS EffectifDeLaClasse=""28""
Presents=""10"" Absents=""18"" Comment=""something"" />"

XmlDoc.SelectSingleNode("(PUPILL_CP_1/*)[last()]").AppendChild(Fragment)
XmlDoc.Save(Console.Out)
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thank you very much for your help.

Evelyne
Mar 14 '07 #4
E.F

"jayeldee" <ja******@gmail.coma écrit dans le message de news:
11**********************@64g2000cwx.googlegroups.c om...
On Mar 13, 12:39 am, "E.F" <fenouillet...@laposte.netwrote:
>Does anybody can explain me the best way to select one nodes
while reading this file and after, the best way to insert my node ?

Thank you very much for your attention.

Evelyne

If you're not completely sold on using node/xml manipulation, I'd
recommend trying out serialization. I'm a lazy man and I find it a
lot easier to let the CLR handle all my reading/writing from XML and I
just pass it a class or expect a class back from it.
Thank you for this proposition. In fact, I need to present my file
in a treeview. This is the reason why I work with xml.

Is it possible to do such thing with serialisation ?

Mar 14 '07 #5
On Mar 14, 6:39 am, "E.F" <fenouillet...@laposte.etwrote:
Thank you for this proposition. In fact, I need to present my file
in a treeview. This is the reason why I work with xml.

Is it possible to do such thing with serialisation ?
Sure is! Sent you an email with an example that was a bit big and I
didn't want to litter up the thread.

Mar 14 '07 #6
E.F
"jayeldee" <ja******@gmail.coma écrit dans le message de news:
11**********************@n59g2000hsh.googlegroups. com...
On Mar 14, 6:39 am, "E.F" <fenouillet...@laposte.etwrote:
>Thank you for this proposition. In fact, I need to present my file
in a treeview. This is the reason why I work with xml.

Is it possible to do such thing with serialisation ?

Sure is! Sent you an email with an example that was a bit big and I
didn't want to litter up the thread.

Hi !

I'm very interested with your example, but I didn't received it...

May I ask you where I can find it or may be could you try to send
it right to my mail one more time.

Best regards,

Evelyne
Mar 15 '07 #7
On Mar 14, 9:28 pm, "E.F" <fenouillet...@laposte.etwrote:
Hi !

I'm very interested with your example, but I didn't received it...

May I ask you where I can find it or may be could you try to send
it right to my mail one more time.

Best regards,

Evelyne
I sent it to the email in your profile but maybe it didn't go
through. I'm jayeldee-at-gmail-dot-com if you want to try sending me
something that I can reply to.

Mar 15 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bootstrap Bill | last post by:
A new Google group has been formed for the purpose of discussing the new Visual Studio Express products. http://groups-beta.google.com/group/Visual-Studio-Express The products are currently in...
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: K Hayes | last post by:
Hi All, Newish VB.NET programmer seeking help! I have a TreeView with a node that I wish to drag and drop to a Textbox. In the Treeview_ItemDrag i have
6
by: Brian Henry | last post by:
Visual Basic 2005 Express: http://download.microsoft.com/download/f/c/7/fc7debaf-4513-4300-9e6a-8fe27be88cd1/vbsetup.exe Visual C# 2005 Express:...
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?...
2
by: Progman | last post by:
I have Visual Studio 2005 Standard edition. Is ti the same thing as the Express edition or Standard is more?
8
by: Zardax | last post by:
Hi !!! I need to know if there is compatibility between VB 6.0 and Visual Basic 2005 Express Everything I need is to compile the VB 6.0 code in Visual Basic 2005 Express without re-write the...
1
by: manivesa | last post by:
Hello does anybody knows how to set manufacturer property when publishing a project with visual basic express? Thanks
6
by: Salman | last post by:
I would like to know how I can distribute the application that I create with Visual C++ express edition. I checked the menu options to find a deploy option similar to the one found on the Visual...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.