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

vb.net處理xml的簡單介紹

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

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

我們注重客戶提出的每個(gè)要求,我們充分考慮每一個(gè)細(xì)節(jié),我們積極的做好網(wǎng)站建設(shè)、成都網(wǎng)站制作服務(wù),我們努力開拓更好的視野,通過不懈的努力,成都創(chuàng)新互聯(lián)贏得了業(yè)內(nèi)的良好聲譽(yù),這一切,也不斷的激勵(lì)著我們更好的服務(wù)客戶。 主要業(yè)務(wù):網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)站設(shè)計(jì),微信小程序開發(fā),網(wǎng)站開發(fā),技術(shù)開發(fā)實(shí)力,DIV+CSS,PHP及ASP,ASP.Net,SQL數(shù)據(jù)庫的技術(shù)開發(fā)工程師。

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,就要你自己想辦法導(dǎo)出了

//XmlDocument or XmlWriter都可以考慮

}

VB.NET讀取XML節(jié)點(diǎn)問題。

有兩種辦法。

方法一、創(chuàng)建一個(gè) MSXML2.DOMDocument 對象,把這個(gè)文件Load進(jìn)來,按照教科書上的步驟處理。這個(gè)對象名并非唯一,依據(jù)你電腦上的MSXML版本而定。你在引用中查一下。

方法二、將這個(gè)文件當(dāng)做一個(gè)普通的文本文件來處理。將它完整的讀入到一個(gè)字符串中,依據(jù)節(jié)點(diǎn)名用Split()函數(shù)將它分段,提取所需的內(nèi)容。

兩種方法都不復(fù)雜,嘗試一下吧。

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ù)庫的另一個(gè)片斷")

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 并關(guān)閉編寫器

myXmlTextWriter.Flush()

myXmlTextWriter.Close()

' 讀取返回的文件并進(jìn)行分析以確保正確生成 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

'關(guān)閉編寫器

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)計(jì)信息

Console.WriteLine ()

Console.WriteLine("{0} 文件的統(tǒng)計(jì)信息", 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問題!

Dim?xmlDoc?As?New?System.Xml.XmlDocument

xmlDoc.Load("c:\xml.xml")?'載入xml文件

Dim?Items?As?Xml.XmlNodeList?=?xmlDoc.DocumentElement.SelectNodes("http://record/item")?'參數(shù)為xpath查詢串,前面斜杠,//:表示任何結(jié)點(diǎn),/:表示根結(jié)點(diǎn)

For?Each?s?As?Xml.XmlNode?In?Items

Console.WriteLine(s.Attributes.GetNamedItem("id").Value??vbTab??s.InnerText)

Next

分享題目:vb.net處理xml的簡單介紹
標(biāo)題URL:http://chinadenli.net/article22/doedejc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版外貿(mào)網(wǎng)站建設(shè)網(wǎng)頁設(shè)計(jì)公司App設(shè)計(jì)網(wǎng)站排名軟件開發(fā)

廣告

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

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)