欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

包含vb.net寫入xml的詞條

vb.net XML文件如何寫入

Imports System.IO

網(wǎng)站建設哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、微信小程序、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了湖里免費建站歡迎大家使用!

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim f As New FileInfo("d:\doc.xml")

If f.Exists = False Then

f.Create()

f.Refresh()

End If

Dim s As String = ""

Dim sw As StreamWriter = f.CreateText()

s = "?xml version=""1.0"" encoding=""GB2312""?"

sw.WriteLine(s)

sw.WriteLine("doc")

sw.WriteLine(" assembly")

sw.WriteLine("userId34/userId")

sw.WriteLine("userName張三/userName")

sw.WriteLine("qxbz1/qxbz")

sw.WriteLine(" /assembly")

sw.WriteLine("/doc")

sw.Flush()

sw.Close()

Process.Start("d:\doc.xml")

End Sub

End Class

vb.net操作xml數(shù)據(jù)庫(急)

使用System.XML

Imports Microsoft.VisualBasic

Imports System

Imports System.IO

Imports System.Xml

namespace HowTo.Samples.XML

public class WriteXmlFileSample

private const document as string = "newbooks.xml"

shared sub Main()

Dim myWriteXmlFileSample as WriteXmlFileSample

myWriteXmlFileSample = new WriteXmlFileSample()

myWriteXmlFileSample.Run(document)

end sub

public sub Run(args As String)

Dim myXmlTextReader as XmlTextReader = nothing

Dim myXmlTextWriter as XmlTextWriter = nothing

try

myXmlTextWriter = new XmlTextWriter (args, nothing)

myXmlTextWriter.Formatting = System.Xml.Formatting.Indented

myXmlTextWriter.WriteStartDocument(false)

myXmlTextWriter.WriteDocType("bookstore", nothing, "books.dtd", nothing)

myXmlTextWriter.WriteComment("此文件表示書店庫存數(shù)據(jù)庫的另一個片斷")

myXmlTextWriter.WriteStartElement("bookstore")

myXmlTextWriter.WriteStartElement("book", nothing)

myXmlTextWriter.WriteAttributeString("genre","autobiography")

myXmlTextWriter.WriteAttributeString("publicationdate","1979")

myXmlTextWriter.WriteAttributeString("ISBN","0-7356-0562-9")

myXmlTextWriter.WriteElementString("title", nothing, "The Autobiography of Mark Twain")

myXmlTextWriter.WriteStartElement("Author", nothing)

myXmlTextWriter.WriteElementString("first-name", "Mark")

myXmlTextWriter.WriteElementString("last-name", "Twain")

myXmlTextWriter.WriteEndElement()

myXmlTextWriter.WriteElementString("price", "7.99")

myXmlTextWriter.WriteEndElement()

myXmlTextWriter.WriteEndElement()

'向文件寫 XML 并關閉編寫器

myXmlTextWriter.Flush()

myXmlTextWriter.Close()

' 讀取返回的文件并進行分析以確保正確生成 XML

myXmlTextReader = new XmlTextReader (args)

FormatXml (myXmlTextReader, args)

catch e as Exception

Console.WriteLine ("異常:{0}", e.ToString())

finally

Console.WriteLine()

Console.WriteLine("對文件 {0} 的處理已完成。", args)

If Not myXmlTextReader Is Nothing

myXmlTextReader.Close()

end if

'關閉編寫器

If Not myXmlTextWriter Is Nothing

myXmlTextWriter.Close()

end if

End try

End Sub

private shared Sub FormatXml (reader as XmlTextReader, filename as String)

Dim piCount, docCount, commentCount, elementCount as Integer

Dim attributeCount, textCount, whitespaceCount as Integer

While reader.Read()

Select (reader.NodeType)

case XmlNodeType.ProcessingInstruction:

Format (reader, "ProcessingInstruction")

piCount += 1

case XmlNodeType.DocumentType:

Format (reader, "DocumentType")

docCount += 1

case XmlNodeType.Comment:

Format (reader, "Comment")

commentCount += 1

case XmlNodeType.Element:

Format (reader, "Element")

elementCount += 1

While reader.MoveToNextAttribute()

Format (reader, "Attribute")

end While

if (reader.HasAttributes)

attributeCount += reader.AttributeCount

end if

case XmlNodeType.Text:

Format (reader, "Text")

textCount += 1

case XmlNodeType.Whitespace:

whitespaceCount += 1

End Select

End While

' 顯示該文件的統(tǒng)計信息

Console.WriteLine ()

Console.WriteLine("{0} 文件的統(tǒng)計信息", filename)

Console.WriteLine ()

Console.WriteLine("處理指令:" piCount)

Console.WriteLine("文檔類型:" docCount)

Console.WriteLine("注釋:" commentCount)

Console.WriteLine("元素:" elementCount)

Console.WriteLine("屬性:" attributeCount)

Console.WriteLine("文本:" textCount)

Console.WriteLine("空白:" whitespaceCount)

End Sub

private shared Sub Format(byref reader as XmlTextReader , NodeType as String)

' 格式化輸出

Console.Write(reader.Depth " ")

Console.Write(reader.AttributeCount " ")

Dim i as Integer

for i = 0 to reader.Depth - 1

Console.Write(Strings.chr(9))

Next

Console.Write(reader.Prefix NodeType "" reader.Name "" reader.Value)

Console.WriteLine()

End Sub

End Class

End Namespace

參考:

vb.net中怎么創(chuàng)建xml文件并寫數(shù)據(jù)

DataSet 和 DataTable都有現(xiàn)成的方法:WriteXml

DataTable tb = this.dataGridView1.DataSource as DataTable;

if(tb != null)

{

tb.WriteXml(@"C:\table.xml",true);

return;

}

DataView dv = this.dataGridView1.DataSource as DataView;

if(dv != null)

{

dv.Table.WriteXml(@"C:\table.xml",true);

return;

}

IList list = this.dataGridView1.DataSource as IList;

if(list != null)

{

//to do,如果是IList,就要你自己想辦法導出了

//XmlDocument or XmlWriter都可以考慮

}

標題名稱:包含vb.net寫入xml的詞條
文章源于:http://chinadenli.net/article42/dogehec.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、建站公司移動網(wǎng)站建設、軟件開發(fā)靜態(tài)網(wǎng)站、網(wǎng)站營銷

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設