Private Sub btnCreateXml_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateXml.Click
Dim xml_document As XmlDocument
' Make the XML file.
xml_document = CreateXmlFile()
' Display the document's contents.
txtContents.Text = XmlDocToString(xml_document)
txtContents.Select(0, 0)
' Save the XML document.
xml_document.Save(FileStuff.DataSubdirectory() & "\Test.xml")
End Sub
' Make the XML document.
Private Function CreateXmlFile() As XmlDocument
Const INDENT As Integer = 4
Dim xml_document As XmlDocument
Dim root As XmlElement
Dim child As XmlElement
Dim grandchild As XmlElement
' Create a new XmlDocument object.
xml_document = New XmlDocument()
xml_document.PreserveWhitespace = True
' Define the file's version information.
AddXmlDeclaration(xml_document)
AddXmlNewLine(xml_document, xml_document, 0)
' Associate the XML file with an XSL file.
AddXmlXSLFile(xml_document, "Test.xsl")
' Make the DOCTYPE section.
AddXmlDocumentType(xml_document, "Root", _
"<!ENTITY us ""United States of America"">")
' Add a blank line before the real data.
AddXmlNewLine(xml_document, xml_document, 0)
' Add a comment.
AddXmlComment(xml_document, xml_document, _
"*** The data starts here ***")
' Create the root element.
AddXmlNewLine(xml_document, xml_document, 0)
root = AddXmlElement(xml_document, xml_document, "Root")
' Give the root element some attributes.
AddXmlAttribute(xml_document, root, "Attr-1", "Value 1")
AddXmlAttribute(xml_document, root, "Attr-2", "Value 2")
' Give the root element some text.
AddXmlText(xml_document, root, "Root inner text")
' Create a child element.
AddXmlNewLine(xml_document, root, INDENT)
child = AddXmlElement(xml_document, root, "Child-1")
AddXmlText(xml_document, child, "Child inner text")
AddXmlAttribute(xml_document, child, "Child-Attr-1", "Child Value 1")
' Create another child element.
AddXmlNewLine(xml_document, root, INDENT)
child = AddXmlElement(xml_document, root, "Child-2")
' Add some CDATA inside Child 2.
AddXmlNewLine(xml_document, child, 2 * INDENT)
AddXmlCdataSection(xml_document, child, vbCrLf & _
"<Example>" & vbCrLf & _
" CDATA text can contain whitespace" & vbCrLf & _
" & characters that look like markup!" & vbCrLf & _
"</Example>")
AddXmlNewLine(xml_document, child, INDENT)
' Create a comment inside the root.
AddXmlNewLine(xml_document, root, INDENT)
AddXmlComment(xml_document, root, _
"The following text and entity reference are in the Root node")
' Create a text node inside the root.
AddXmlNewLine(xml_document, root, INDENT)
AddXmlText(xml_document, root, "Country = ")
' Create an entity reference.
AddXmlEntityReference(xml_document, root, "us")
' Create another child node.
AddXmlNewLine(xml_document, root, INDENT)
child = AddXmlElement(xml_document, root, "Child-3")
' Create a grandchild.
AddXmlNewLine(xml_document, child, 2 * INDENT)
grandchild = AddXmlElement(xml_document, child, "Grandchild-1")
' Create a comment inside the grandchild.
AddXmlNewLine(xml_document, grandchild, 3 * INDENT)
AddXmlComment(xml_document, grandchild, "This comment is inside Grandchild-1")
AddXmlNewLine(xml_document, grandchild, 2 * INDENT)
AddXmlNewLine(xml_document, child, INDENT)
' Create a final root-level comment.
AddXmlNewLine(xml_document, root, 0)
AddXmlNewLine(xml_document, xml_document, 0)
AddXmlComment(xml_document, xml_document, "That's all folks!")
' Return the document.
Return xml_document
End Function
Please SUBSCRIBE to get new articles directly into your Email inbox!
Dim xml_document As XmlDocument
' Make the XML file.
xml_document = CreateXmlFile()
' Display the document's contents.
txtContents.Text = XmlDocToString(xml_document)
txtContents.Select(0, 0)
' Save the XML document.
xml_document.Save(FileStuff.DataSubdirectory() & "\Test.xml")
End Sub
' Make the XML document.
Private Function CreateXmlFile() As XmlDocument
Const INDENT As Integer = 4
Dim xml_document As XmlDocument
Dim root As XmlElement
Dim child As XmlElement
Dim grandchild As XmlElement
' Create a new XmlDocument object.
xml_document = New XmlDocument()
xml_document.PreserveWhitespace = True
' Define the file's version information.
AddXmlDeclaration(xml_document)
AddXmlNewLine(xml_document, xml_document, 0)
' Associate the XML file with an XSL file.
AddXmlXSLFile(xml_document, "Test.xsl")
' Make the DOCTYPE section.
AddXmlDocumentType(xml_document, "Root", _
"<!ENTITY us ""United States of America"">")
' Add a blank line before the real data.
AddXmlNewLine(xml_document, xml_document, 0)
' Add a comment.
AddXmlComment(xml_document, xml_document, _
"*** The data starts here ***")
' Create the root element.
AddXmlNewLine(xml_document, xml_document, 0)
root = AddXmlElement(xml_document, xml_document, "Root")
' Give the root element some attributes.
AddXmlAttribute(xml_document, root, "Attr-1", "Value 1")
AddXmlAttribute(xml_document, root, "Attr-2", "Value 2")
' Give the root element some text.
AddXmlText(xml_document, root, "Root inner text")
' Create a child element.
AddXmlNewLine(xml_document, root, INDENT)
child = AddXmlElement(xml_document, root, "Child-1")
AddXmlText(xml_document, child, "Child inner text")
AddXmlAttribute(xml_document, child, "Child-Attr-1", "Child Value 1")
' Create another child element.
AddXmlNewLine(xml_document, root, INDENT)
child = AddXmlElement(xml_document, root, "Child-2")
' Add some CDATA inside Child 2.
AddXmlNewLine(xml_document, child, 2 * INDENT)
AddXmlCdataSection(xml_document, child, vbCrLf & _
"<Example>" & vbCrLf & _
" CDATA text can contain whitespace" & vbCrLf & _
" & characters that look like markup!" & vbCrLf & _
"</Example>")
AddXmlNewLine(xml_document, child, INDENT)
' Create a comment inside the root.
AddXmlNewLine(xml_document, root, INDENT)
AddXmlComment(xml_document, root, _
"The following text and entity reference are in the Root node")
' Create a text node inside the root.
AddXmlNewLine(xml_document, root, INDENT)
AddXmlText(xml_document, root, "Country = ")
' Create an entity reference.
AddXmlEntityReference(xml_document, root, "us")
' Create another child node.
AddXmlNewLine(xml_document, root, INDENT)
child = AddXmlElement(xml_document, root, "Child-3")
' Create a grandchild.
AddXmlNewLine(xml_document, child, 2 * INDENT)
grandchild = AddXmlElement(xml_document, child, "Grandchild-1")
' Create a comment inside the grandchild.
AddXmlNewLine(xml_document, grandchild, 3 * INDENT)
AddXmlComment(xml_document, grandchild, "This comment is inside Grandchild-1")
AddXmlNewLine(xml_document, grandchild, 2 * INDENT)
AddXmlNewLine(xml_document, child, INDENT)
' Create a final root-level comment.
AddXmlNewLine(xml_document, root, 0)
AddXmlNewLine(xml_document, xml_document, 0)
AddXmlComment(xml_document, xml_document, "That's all folks!")
' Return the document.
Return xml_document
End Function
Please SUBSCRIBE to get new articles directly into your Email inbox!
تعليقات
إرسال تعليق