当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET XmlDocument.CreateXmlDeclaration方法代码示例

本文整理汇总了VB.NET中System.Xml.XmlDocument.CreateXmlDeclaration方法的典型用法代码示例。如果您正苦于以下问题:VB.NET XmlDocument.CreateXmlDeclaration方法的具体用法?VB.NET XmlDocument.CreateXmlDeclaration怎么用?VB.NET XmlDocument.CreateXmlDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.CreateXmlDeclaration方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Sample

Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim doc As New XmlDocument()
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>" & _
                    "</book>")
        
        'Create an XML declaration. 
        Dim xmldecl As XmlDeclaration
        xmldecl = doc.CreateXmlDeclaration("1.0", Nothing, Nothing)
        
        'Add the new node to the document.
        Dim root As XmlElement = doc.DocumentElement
        doc.InsertBefore(xmldecl, root)
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Xml,代码行数:26,代码来源:XmlDocument.CreateXmlDeclaration

示例2: DOMSave

public class DOMSave
   public Shared Sub Main
        Dim myDoc As New Xml.XmlDocument

        myDoc.AppendChild(myDoc.CreateXmlDeclaration("1.0", "UTF-8", String.Empty))
        myDoc.AppendChild(myDoc.CreateComment("information about this book"))

        Dim rootBook As Xml.XmlNode =myDoc.AppendChild(myDoc.CreateElement("book"))
        rootBook.Attributes.Append(myDoc.CreateAttribute("isbn"))
        rootBook.Attributes("isbn").Value = "0-672-32549-7"

        Dim title As Xml.XmlNode
        title = rootBook.AppendChild(myDoc.CreateElement("title"))
        title.InnerText = "Start"
        Dim authors As Xml.XmlNode = rootBook.AppendChild(myDoc.CreateElement("authors"))
        Dim Duncan, Andy, Erik, Joel As Xml.XmlNode

        Duncan = authors.AppendChild(myDoc.CreateElement("author"))
        Andy = authors.AppendChild(myDoc.CreateElement("author"))
        Erik = authors.AppendChild(myDoc.CreateElement("author"))
        Joel = authors.AppendChild(myDoc.CreateElement("author"))

        Duncan.InnerText = "D"
        Andy.InnerText = "A"
        Erik.InnerText = "E"
        Joel.InnerText = "J"

        Dim chapters As Xml.XmlNode = myDoc.CreateElement("chapters")

        rootBook.AppendChild(chapters)

        Dim chapterElements(10) As Xml.XmlElement

        For i As Integer = 0 To 10
            chapterElements(i) = myDoc.CreateElement("chapter")
            With chapterElements(i)
                .Attributes.Append(myDoc.CreateAttribute("id"))
                .Attributes("id").Value =CStr(i + 1)
                .Attributes.Append(myDoc.CreateAttribute("topic"))
            End With
            chapters.AppendChild(chapterElements(i))
        Next


        chapterElements(0).Attributes("topic").Value = "A"
        chapterElements(1).Attributes("topic").Value = "B"
        chapterElements(2).Attributes("topic").Value = "C"
        chapterElements(3).Attributes("topic").Value = "D"
        chapterElements(4).Attributes("topic").Value = "E"
        chapterElements(5).Attributes("topic").Value = "F"
        chapterElements(6).Attributes("topic").Value = "G"
        chapterElements(7).Attributes("topic").Value = "H"
        chapterElements(8).Attributes("topic").Value = "I"
        chapterElements(9).Attributes("topic").Value = "J"
        chapterElements(10).Attributes("id").Value = "K"
        chapterElements(10).Attributes("topic").Value = "L"

        Dim myWriter As New Xml.XmlTextWriter("test.xml", System.Text.Encoding.UTF8)

        myWriter.Formatting = Xml.Formatting.Indented
        myDoc.Save(myWriter)
        myWriter.Close()
   End Sub
End class
开发者ID:VB程序员,项目名称:System.Xml,代码行数:64,代码来源:XmlDocument.CreateXmlDeclaration


注:本文中的System.Xml.XmlDocument.CreateXmlDeclaration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。