Menu Search

Visual Basic / .NET

Einfaches Erstellen einer XML Datei in .Net
Dim XmlDoc As New XmlDocument

´Write down the XML declaration
Dim XmlDeclaration As XmlDeclaration = XmlDoc.CreateXmlDeclaration("1.0", "UTF-8", Nothing)

´Create the root element
Dim RootNode As XmlElement = XmlDoc.CreateElement("RootNode")
XmlDoc.InsertBefore(XmlDeclaration, XmlDoc.DocumentElement)
XmlDoc.AppendChild(RootNode)

´Create a new element and add it to the root node
Dim ParentNode As XmlElement = XmlDoc.CreateElement("Parent")

´Set attribute name and value!
ParentNode.SetAttribute("AttributName", "AttributWert")

XmlDoc.DocumentElement.PrependChild(ParentNode)

´Create the required nodes
Dim FirstElement As XmlElement = XmlDoc.CreateElement("FirstElement")
Dim SecondElement As XmlElement = XmlDoc.CreateElement("SecondElement")
Dim ThirdElement As XmlElement = XmlDoc.CreateElement("ThirdElement")


´retrieve the text
Dim FirstTextElement As XmlText = XmlDoc.CreateTextNode("This is the text from the first element")
Dim SecondTextElement As XmlText = XmlDoc.CreateTextNode("This is the text from the second element")
Dim ThirdTextElement As XmlText = XmlDoc.CreateTextNode("This is the text from the third element")

´append the nodes to the parentNode without the value
ParentNode.AppendChild(FirstElement)
ParentNode.AppendChild(SecondElement)
ParentNode.AppendChild(ThirdElement)

´save the value of the fields into the nodes
FirstElement.AppendChild(FirstTextElement)
SecondElement.AppendChild(SecondTextElement)
ThirdElement.AppendChild(ThirdTextElement)

´Save to the XML file
XmlDoc.Save("demo.xml")

Liste

Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste
Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste

Index

Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste
Index | List
  • Vorherige
  • Seite #n
  • #n
  • #c
  • Seite #n
  • Nächste

LetzteChance.Org - Links -

PDF/ZIP/Word