Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Const xmlns As String = "http://www.atmarkit.co.jp/xmlns/sample/person" Dim document As New XmlDocument() Dim xmlDecl As XmlDeclaration = document.CreateXmlDeclaration("1.0", "UTF-8", Nothing) document.AppendChild(xmlDecl) Dim rootElement As XmlElement = document.CreateElement("person", "record", xmlns) document.AppendChild(rootElement) Dim idAttr As XmlAttribute = document.CreateAttribute("id") idAttr.Value = "0011" rootElement.Attributes.Append(idAttr) Dim nameElement As XmlElement = document.CreateElement("person", "name", xmlns) rootElement.AppendChild(nameElement) Dim nameText As XmlText = document.CreateTextNode("山田一郎") nameElement.AppendChild(nameText) Dim ageElement As XmlElement = document.CreateElement("person", "age", xmlns) rootElement.AppendChild(ageElement) ageElement.InnerText = "17" Dim addressElement As XmlElement = document.CreateElement("person", "address", xmlns) rootElement.AppendChild(addressElement) addressElement.InnerXml = "jp東京都杉並区1-2-3" Dim comment1 As XmlComment = document.CreateComment("サンプルプログラムの出力") rootElement.InsertBefore(comment1, nameElement) Dim comment2 As XmlComment = document.CreateComment("個人情報") rootElement.InsertAfter(comment2, nameElement) document.Save("c:\sample.xml") End Sub