Vb.net 2010 - LinkToXml - unable to add.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello,
im working on vb.net 2010, framework 4<br/>
i have a xml file c:xmlfile.xml :

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; database<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Titres<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Id<span style="color:Blue; >0<span style="color:Blue; </<span style="color:#A31515; Id<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Titre<span style="color:Blue; >T1<span style="color:Blue; </<span style="color:#A31515; Titre<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; An<span style="color:Blue; >A1<span style="color:Blue; </<span style="color:#A31515; An<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Duree<span style="color:Blue; >D1<span style="color:Blue; </<span style="color:#A31515; Duree<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Genre<span style="color:Blue; >G1<span style="color:Blue; </<span style="color:#A31515; Genre<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Acteurs<span style="color:Blue; >C1<span style="color:Blue; </<span style="color:#A31515; Acteurs<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Resume<span style="color:Blue; >R1<span style="color:Blue; </<span style="color:#A31515; Resume<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Img<span style="color:Blue; >I1<span style="color:Blue; </<span style="color:#A31515; Img<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Qual<span style="color:Blue; >Q1<span style="color:Blue; </<span style="color:#A31515; Qual<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Sup<span style="color:Blue; >S1<span style="color:Blue; </<span style="color:#A31515; Sup<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pret<span style="color:Blue; >P1<span style="color:Blue; </<span style="color:#A31515; Pret<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Tmb<span style="color:Blue; >T1<span style="color:Blue; </<span style="color:#A31515; Tmb<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Titres<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Titres<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Id<span style="color:Blue; >1<span style="color:Blue; </<span style="color:#A31515; Id<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Titre<span style="color:Blue; >T2<span style="color:Blue; </<span style="color:#A31515; Titre<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; An<span style="color:Blue; >A2<span style="color:Blue; </<span style="color:#A31515; An<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Duree<span style="color:Blue; >D2<span style="color:Blue; </<span style="color:#A31515; Duree<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Genre<span style="color:Blue; >G2<span style="color:Blue; </<span style="color:#A31515; Genre<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Acteurs<span style="color:Blue; >C2<span style="color:Blue; </<span style="color:#A31515; Acteurs<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Resume<span style="color:Blue; >R2<span style="color:Blue; </<span style="color:#A31515; Resume<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Img<span style="color:Blue; >I2<span style="color:Blue; </<span style="color:#A31515; Img<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Qual<span style="color:Blue; >Q2<span style="color:Blue; </<span style="color:#A31515; Qual<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Sup<span style="color:Blue; >S2<span style="color:Blue; </<span style="color:#A31515; Sup<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Pret<span style="color:Blue; >P2<span style="color:Blue; </<span style="color:#A31515; Pret<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Tmb<span style="color:Blue; >T2<span style="color:Blue; </<span style="color:#A31515; Tmb<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; Titres<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; database<span style="color:Blue; >
[/code]

i use a xmltoschema1.xsd gÃnÃrated with tihs file in my project in order to use intellisense.
<br/>
im using :

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Xml.Linq

<span style="color:Blue; Public FicBase <span style="color:Blue; As XDocument
<span style="color:Blue; Public RqBase <span style="color:Blue; As System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)
<span style="color:Blue; Public TmpXe <span style="color:Blue; As XElement = <Titres>
<Id></Id>
<Titre></Titre>
<An></An>
<Duree></Duree>
<Genre></Genre>
<Acteurs></Acteurs>
<<span style="color:Blue; Resume></<span style="color:Blue; Resume>
<Img></Img>
<Qual></Qual>
<Sup></Sup>
<Pret></Pret>
<Tmb></Tmb>
</Titres>

<span style="color:Blue; sub connecttoxml()
FicBase = XDocument.Load(c:xmlfile.xml)
RqBase = <span style="color:Blue; From xelm <span style="color:Blue; In FicBase...<Titres> <span style="color:Blue; Select xelm
<span style="color:Blue; If RqBase <span style="color:Blue; Is <span style="color:Blue; Nothing <span style="color:Blue; Then <span style="color:Blue; Exit <span style="color:Blue; Sub
<span style="color:Blue; For <span style="color:Blue; Each xe <span style="color:Blue; In RqBase
TmpItem = Listing.Items.Add(xe...<Titre>.Value) <span style="color:Green; Titre
TmpItem.SubItems.Add(xe...<An>.Value) <span style="color:Green; Date
TmpItem.SubItems.Add(xe...<Genre>.Value) <span style="color:Green; Genre
TmpItem.SubItems.Add(xe...<Qual>.Value) <span style="color:Green; Qualité
TmpItem.SubItems.Add(xe...<Sup>.Value) <span style="color:Green; Sup
TmpItem.SubItems.Add(xe...<Pret>.Value) <span style="color:Green; Pret
<span style="color:Blue; If xe...<Pret>.Value <> <span style="color:#A31515; "truc" <span style="color:Blue; Then TmpItem.ForeColor = Color.Red
TmpItem.Tag = xe
<span style="color:Blue; Next
<span style="color:Blue; end <span style="color:Blue; sub


[/code]
this sub works fine.

when an item of my listing was cliked i run this code :<br/>

<div style="color:Black;background-color:White; <pre>
tmpxe = listing.selecteditems(0).tag
[/code]
<br/>
and it works fine too.

so, i used a form to modify data of my tmpxe and i want to add a new element to my xml.<br/>

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; sub addxml()
TmpXe...<Sup>.Value = TS.Text
TmpXe...<Qual>.Value = TS.Text
TmpXe...<Pret>.Value = <span style="color:#A31515; "Dispo"
FicBase.Add(TmpXe)
<span style="color:Blue; end <span style="color:Blue; sub

[/code]
this not work.

the line ficbase.add send me an error which say this will corrupt my xmlfile.
tmpxe is fully completed so i dont know why it doesnt work.
could you explain to me why ?
(sorry for my poor english, i m french.)

<hr class="sig Olivier.

View the full article
 
Back
Top