成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

vb點虐 寫入xml的簡單介紹

vb點虐 操作xml數(shù)據(jù)庫(急)

使用System.XML

創(chuàng)新互聯(lián)是一家朝氣蓬勃的網(wǎng)站建設公司。公司專注于為企業(yè)提供信息化建設解決方案。從事網(wǎng)站開發(fā),網(wǎng)站制作,網(wǎng)站設計,網(wǎng)站模板,微信公眾號開發(fā),軟件開發(fā),成都小程序開發(fā),十年建站對發(fā)電機維修等多個領域,擁有豐富的網(wǎng)站維護經(jīng)驗。

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點虐 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點虐 中怎么創(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點虐 寫入xml的簡單介紹
網(wǎng)站路徑:http://jinyejixie.com/article14/ddichge.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站手機網(wǎng)站建設、動態(tài)網(wǎng)站虛擬主機、品牌網(wǎng)站制作營銷型網(wǎng)站建設

廣告

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

成都做網(wǎng)站
喀什市| 锦屏县| 阿坝县| 阿克苏市| 达尔| 准格尔旗| 延吉市| 石首市| 旬邑县| 临潭县| 都兰县| 甘孜| 泗阳县| 泰和县| 华安县| 土默特右旗| 丽江市| 惠来县| 黄山市| 汾西县| 福海县| 湖南省| 洮南市| 洛浦县| 西峡县| 鸡泽县| 安仁县| 定兴县| 进贤县| 宣汉县| 长治市| 婺源县| 恩平市| 石河子市| 铜陵市| 巢湖市| 都匀市| 宜君县| 长春市| 明光市| 颍上县|