

LINK: https://gambas-playground.proko.eu/?gist=f17a0cd60f97c6242ce81f00fd0d97e2

(BEISPIEL1) Ändern des Wertes eines Attributes
(BEISPIEL2) Löschen des Wertes eines Atributes ~> spezielles Ändern
(BEISPIEL3) Löschen eines Attributes 
(BEISPIEL4) Erzeugen eines neuen Attributes
(BEISPIEL5) Hinweis: Ein Attribut kann man nicht umbenennen!
            5.1 Ein neues leeres Attribut erzeugen
            5.2 Den Wert der neuen Attributes auf den Wert der Original-Attributes setzen
            5.3 Das Original-Attribut löschen

Use "gb.xml"

Dim contents As String = "<xml>"
"<foo>"
"<p attr=\"1\">Hello</p>"
"<p attr=\"2\">Hi</p>"
"<p attr=\"3\">Greetings</p>"
"</foo>"
"</xml>"

Dim element As XmlElement
Dim doc As New XmlDocument

doc.FromString(contents)

(1) Element ermitteln
(2) Element bearbeiten

(BEISPIEL1)
element = doc.GetElementsByTagName("p")[1] 'Get the second p element
element.Attributes["attr"] = 42 'Set an attribute's value
'Also available: element.SetAttribute("attr", 42)

Print doc.ToString(True)

Print "-----------------------------------------------------------------------------------------------------------------"

(BEISPIEL2)
element.Attributes["attr"] = ""   'Set an attribute's value to an empty string (also works with Null)
element.Attributes["attr"] = NULL 'Set an attribute's value to an empty string (also works with Null)
Print doc.ToString(True)

Print "-----------------------------------------------------------------------------------------------------------------"

(BEISPIEL3)
element.RemoveAttribute("attr") 'Completely remove an attribute
Print doc.ToString(True)

Print "-----------------------------------------------------------------------------------------------------------------"

(BEISPIEL4)
element = doc.GetElementsByTagName("foo")[0] 'Get the first foo element
element.Attributes["otherAttr"] = "some value" 'Create a new attribute
Print doc.ToString(True)

Print "-----------------------------------------------------------------------------------------------------------------"

(BEISPIEL5)
'You can't "rename" an attribute, so you have to "transfer" the value. Create a new attribute from the previously created one
'Du kannst kein Attribut umbenennen, also musst du den Wert" übertragen. Erstellen Sie ein neues Attribut aus dem zuvor erstellten'

element.Attributes["newAttr"] = element.Attributes["otherAttr"] 
element.RemoveAttribute("otherAttr") 'Remove the old one
Print doc.ToString(True)




