|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Mar 2001
Città: Grosseto
Messaggi: 2451
|
[Vb.net e Xml]Uso di appendchild e creazione albero xml
Ciao a tutti, ho un xml con la seguente struttura:
<changes> <change changedate="2009-04-28T10:30:24" user="Sistema role="Sistema"> <oldvalue> <stato>9800gt pè gioca a crysys</stato> </oldvalue> <newvalue> <stato>02 - Verifica contabile</stato> </newvalue> </change> </changes> Volevo replicare questa riga in vb.net. Ho fatto la seguente porzione di codice: Dim root = xml_mod.selectSingleNode("//changes") Dim nodofiglio = xml_mod.createElement("change") root.appendchild(nodofiglio) Aggiunge il tag change ma non so come creare gli attributi.
__________________
Hp Omen 15 - Ryzen 5800H - RTX 3060 6Gb |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Mar 2001
Città: Grosseto
Messaggi: 2451
|
Con questo codice sono riuscito a replicare la tab:
'Creazione riga tabella xml Dim root = xml_mod.selectSingleNode("//changes") Dim nodofiglio = xml_mod.createElement("change") root.appendchild(nodofiglio) Dim nodofiglio1 = xml_mod.createElement("oldvalue") nodofiglio.appendchild(nodofiglio1) Dim nodofiglio2 = xml_mod.createElement("stato") nodofiglio1.appendchild(nodofiglio2) Dim nodofiglio3 = xml_mod.createElement("newvalue") nodofiglio.appendchild(nodofiglio3) Dim nodofiglio4 = xml_mod.createElement("stato") nodofiglio3.appendchild(nodofiglio4) Adesso quello che voglio fare è la selectsinglenode di uno di questi nodi.Come faccio a beccare il nodo giusto?Ci sono almeno 100 tabelle di questo tipo ed ognuna corrisponde ad un record.
__________________
Hp Omen 15 - Ryzen 5800H - RTX 3060 6Gb |
|
|
|
|
|
#3 | |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
Codice:
Dim at1 As Xml.XmlAttribute = xml_mod.CreateAttribute("nomeAttributo1")
at1.Value = "valoreAttributo1"
nodofiglio.Attributes.Append(at1)
Dim at2 As Xml.XmlAttribute = xml_mod.CreateAttribute("nomeAttributo2")
at2.Value = "valoreAttributo2"
nodofiglio.Attributes.Append(at2)
'...
'...
|
|
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Mar 2001
Città: Grosseto
Messaggi: 2451
|
Quote:
type xml.xmlattribute non definito
__________________
Hp Omen 15 - Ryzen 5800H - RTX 3060 6Gb |
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
|
|
|
|
|
|
#6 | |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 3210
|
Quote:
Codice:
For Each N As Xml.XmlNode In root.ChildNodes
lst_xml.Items.Add(N.Name)
If N.Attributes.Count > 0 Then
For Each A As Xml.XmlAttribute In N.Attributes
lst_xml.Items.Add(" " & A.Name & " = " & A.Value)
Next
End If
For Each N1 As Xml.XmlNode In N.ChildNodes
Select Case N1.NodeType
Case Xml.XmlNodeType.Element
lst_xml.Items.Add(" " & N1.Name & " = " & N1.InnerText)
'Case ...
'Case ...
Case Else
'...
'...
End Select
Next
Next
|
|
|
|
|
|
|
#7 | |
|
Senior Member
Iscritto dal: Mar 2001
Città: Grosseto
Messaggi: 2451
|
Quote:
__________________
Hp Omen 15 - Ryzen 5800H - RTX 3060 6Gb |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 23:06.




















