职位关键字 工作地点
工作名称 公司名称 校园招聘
中国最好的工作搜索引擎!
  回复留言  
  VB.NET没有操作XML的基类吗?高手救命啊
作者: Im_DS  01-01 08:00   回复  
 RT...

急啊,救救

  回复:VB.NET没有操作XML的基类吗?高手救命啊
作者: ghostidea  01-01 08:00   回复  
 使用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



参考:http://chs.gotdotnet.com/quickstart/util/srcview.aspx?path=%2fquickstart%2fhowto%2fsamples%2fXml%2fWriteXmlFile%2fWriteXmlFile.src

  回复:VB.NET没有操作XML的基类吗?高手救命啊
作者: 13026958826  07-16 13:29   回复  
  好像没有吧...

  回复:VB.NET没有操作XML的基类吗?高手救命啊
作者: djzhou6688  07-16 13:29   回复  
  不明白你的意思。

.net里任何语言都没有自己的功能类库,都是.netSDK提供的,操作xml,.netSDK提供了很多类,自己看看帮助吧

  回复:VB.NET没有操作XML的基类吗?高手救命啊
作者: 3tion  07-16 13:29   回复  
  System.Xml命名空间下面一堆。。。

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.chs/WD_XML/html/473215f3-3473-4a17-9938-ebd1a3d48294.htm

MSDN的帮助里面的地址。

标 题:
内 容:
用户名:
 游客
 
 
Copyright©2005-2007, 版权所有 WWW.JOBMET.COM
ICP证:京ICP备06019556号