包含vb.net寫入xml的詞條

vb.net XML文件如何寫入

Imports System.IO

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

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數據庫(急)

使用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("此文件表示書店庫存數據庫的另一個片斷")

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

' 顯示該文件的統計信息

Console.WriteLine ()

Console.WriteLine("{0} 文件的統計信息", 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中怎么創建xml文件并寫數據

DataSet 和 DataTable都有現成的方法: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://m.kartarina.com/article42/dogehec.html

成都網站建設公司_創新互聯,為您提供商城網站建站公司移動網站建設軟件開發靜態網站網站營銷

廣告

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

成都定制網站建設
主站蜘蛛池模板: 亚洲AV无码国产精品麻豆天美| 东京热加勒比无码视频| 中文字幕人成无码免费视频| 亚洲AV成人噜噜无码网站| 久久久久久亚洲精品无码| 东京热无码av一区二区| 亚洲久热无码av中文字幕| 国产精品无码素人福利| 中文字幕人成无码免费视频| 高潮潮喷奶水飞溅视频无码| 亚洲性无码一区二区三区| 国产成人无码精品久久久性色 | 国产av永久精品无码| 亚洲AV中文无码乱人伦下载 | 最新无码A∨在线观看| 免费无码A片一区二三区| 亚洲AV无码一区二区二三区入口| 无码人妻精品一区二区三区久久久| 国产精品三级在线观看无码| 精品久久久久久无码人妻热| 成人麻豆日韩在无码视频| 无套内射在线无码播放| 亚洲精品无码永久在线观看你懂的 | 好硬~好爽~别进去~动态图, 69式真人无码视频免 | 亚洲看片无码在线视频| 亚洲av无码不卡| 高清无码视频直接看| 变态SM天堂无码专区| 久久无码精品一区二区三区| 少妇中文无码高清| 日韩人妻无码免费视频一区二区三区| 无码粉嫩小泬无套在线观看 | 亚洲国产精品无码第一区二区三区| 亚洲精品无码AV人在线播放 | AV无码免费永久在线观看| 免费无码中文字幕A级毛片| 久久国产加勒比精品无码| 久久久久亚洲精品无码蜜桃| 久久亚洲AV成人无码电影| 久久av无码专区亚洲av桃花岛| 无码国产精品一区二区免费vr|